Cufon.replace('h1');
Cufon.replace('h2');
Cufon.replace('h3', {hover: true});
Cufon.replace('#menu-top', {hover: true});

$(document).ready(function()
{
	var menu_selected=$('#menu-top div.selected');
	var MenuEnterLeave = 0;

	$('.clear-js').show();
	$('.grid_6').css('float', 'left');

	$('#menu-top div').css('background', 'none');
	$('#menu-top').prepend('<div id="menu-indicator" style="position:absolute;top:0px;opacity:0" class="selected"></div>');

	$('#menu-top div a').mouseenter(function()
	{
		MenuEnterLeave = MenuEnterLeave +1;
		if ($(this).position().left != $('a', menu_selected).position().left)
		{
			menu_selected.removeClass('selected');
			Cufon.refresh('#menu-top');
		}
		$('#menu-indicator').stop(true);
		$('#menu-indicator').animate({width: $(this).parent().width(), left: $(this).parent().position().left}, 250);
	});
	$('#menu-top div a').mouseleave(function()
	{
		MenuEnterLeave = MenuEnterLeave -1;
		if ($(this).position().left != $('a', menu_selected).position().left)
		{
			$(this).animate({opacity: 0.1}, 300);
			$(this).animate({opacity: 1}, 350);
		}
		if ($('#menu-indicator').css('opacity') == 1)
		{
			$('#menu-indicator').stop(true);
		}
		else
		{
			$('#menu-indicator').animate({opacity: 1}, 300);
		}
		setTimeout(function ()
		{
		if (MenuEnterLeave == 0)
		{
			menu_selected.addClass('selected');
			Cufon.refresh('#menu-top');
			$('#menu-indicator').animate({width: menu_selected.width(), left: menu_selected.position().left}, 250)
		}
		}, 100);
	});
	
	setTimeout(function(){
	$('#menu-indicator').animate({width: menu_selected.width(), left: menu_selected.position().left, opacity: 1}, 250);},300);



function prepare(site)
{
	if (site == 'start')
	//** 
	//** Prepare for site "start"
	//**
	{
		//Manipulating DOM
		$('#content-neuigkeiten .content-box-inner').prepend('<div id="ngc"></div>');
		$('#content-neuigkeiten .newsitem').each(function(i)
		{
			$('#ngc').append(
				'<div id="ngc-content-'+i+'" class="ngc-content" style="left:'+i*580+'px;top:-'+i*123+'px">'
				+ '<div class="content">'
				+  '<h2>'+$('h3', this).text()+'</h2>'
				+ $('.content', this).html()
				+ '</div>'
			);
			$(this).click(function()
			{
				$('.ngc-content').each(function(j)
				{
					$(this).animate({'left':j*580-i*580}, 450), 'swing';
				});
			});
		});

		//Applying styles
		$('#librebox-trigger, #clipgrab-trigger, #deings-trigger').css('margin-bottom', '-10px');
		$('#projekte-selector').show();
		$('#clipgrab-info').hide();
		$('#deings-info').hide();
		$('.newsitem .content').hide();
	}
	else if (site == 'web')
	//**
	//** Prepare for site "web"
	//**
	{
		//Removing unwanted borders
		$('#stage .content-box-top').remove();
		$('#stage .content-box-top-left').remove();
		$('#stage .content-box-top-right').remove();
		$('#stage .content-box-bottom').remove();
		$('#stage .content-box-bottom-left').remove();
		$('#stage .content-box-bottom-right').remove();
		$('#stage .content-box-left').remove();
		$('#stage .content-box-right').remove();

		//Manipulating DOM
		$('#content').append(
			'<div class="grid_3 stage-trigger" id="trigger-web"><img src="img/web.png" alt="Web"/></div>'+
			'<div class="grid_3 stage-trigger" id="trigger-community"><img src="img/community.png" alt="Community"/></div>'+
			'<div class="grid_3 stage-trigger" id="trigger-drupal"><img src="img/drupal.png" alt="Drupal"/></div>'+
			'<div class="grid_3 stage-trigger" id="trigger-jquery"><img src="img/jquery.png" alt="jQuery"/></div>'+
			'<div class="grid_4 stage-trigger" id="trigger-referenzen"><img src="img/referenzen.png" alt=""/></div>'+
			'<div class="clear"></div><br />'
		);
		$('.stage-trigger').append(
			'<div class="stage-trigger-right"></div><div class="stage-trigger-left"></div><div class="stage-trigger-bottom"><div class="stage-trigger-bottom-left"></div><div class="stage-trigger-bottom-right"></div>'
		);
		$('#content').append('<div id="stage-shadow"></div>');
		$('.stage-sub').each(function()
		{
			$(this).prepend('<img class="stage-sub-image" src="templates/css/img/stage-sub-'+$('h3', $(this)).text().toLowerCase().replace(' ', '_')+'.png" alt="" />');
		});
		
		//Applying styles
		$('#stage').css({'height' : '221px', 'overflow' : 'hidden', 'background-image' : 'url(templates/css/img/stage-bg-js.png)'});
		$('#stage .content-box-inner').css({'padding-left' : '10px', 'padding-right' : '10px'});
		$('#trigger-web').css({'paddingTop' : '20px', 'lineHeight' : '130px'});
		$('#content').css('min-height', $('#content').height());
		$('.stage-sub-selector').css({'width' : '100%', 'background' : '#ffffff', 'position' : 'absolute', 'bottom' : '40px', 'left' : '0px'});
		$('.stage-sub h3').css({'float' : 'left', 'marginTop' : '8px', 'marginLeft' : '3px', 'cursor' : 'pointer'});
		$('.stage-sub-content').hide();
		$('.stage-sub-selector img').css('marginLeft', (580-($('.stage-sub-selector h3:last').position().left + $('.stage-sub-selector h3:last').width()))/($('.stage-sub-selector h3').length+1) );
		$('#stage-drupal').hide();
		$('#stage-jquery').hide();
		$('#stage-community').hide();
	}
	else if (site == 'software')
	{
		//Manipulating DOM
		$('body').append('<div id="overlay-bg" style="width: 100%; height: 100%;background: #ffffff;opacity:0.6;position: fixed; left:0px; top: 0px;"></div><div id="overlay" style="width:100%; height: 100%; position: fixed; left:0px; top: 0px;text-align:center"></div>');

		//Applying styles
		$('#info-selector').show();
		$('#info-selector').css('left', '67px');
		$('#qt-info').hide();
		$('#trigger-qt:hover').css('cursor', 'pointer')
		$('#trigger-qt:hover').css('cursor', 'pointer')
		$('#overlay').hide();
		$('#overlay-bg').hide();
	}
}




function web_display_stage_sub(object)
{
	object.parent().parent().fadeOut(500);
	object.parent().parent().parent().append('<div id="stage-sub-shown" class="content-box-inner" style="padding-left: 10px; padding-right: 10px;display:none">'
	+'<h3 style="text-transform: lowercase;">'+$('h3', object).text()+'</h3>'
	+$('.stage-sub-content', object).html()
	+'<br /><a href="#" id="stage-sub-shown-close">Zurück</a>'
	+'</div>');

	$('#stage-sub-shown-close').click(function()
	{
		stage = $('.content-box-inner', object.parent().parent().parent());
		$('#stage-sub-shown').fadeOut(500);
		setTimeout(function ()
		{
			stage.fadeIn();
			$('#stage-sub-shown').remove();
		}, 500);
	});

	Cufon.replace('#stage-sub-shown h3')
	setTimeout(function ()
	{
		$('#stage-sub-shown').fadeIn();
	}, 500);
}

function web_display_stage(name)
{

	if (name == 'web')
	{
		$('#stage-community').fadeOut(500);
		$('#trigger-community').animate({'paddingTop' : '0px', 'lineHeight' : '140px'});
		$('#stage-drupal').fadeOut(500);
		$('#trigger-drupal').animate({'paddingTop' : '0px', 'lineHeight' : '140px'});
		$('#stage-jquery').fadeOut(500);
		$('#trigger-jquery').animate({'paddingTop' : '0px', 'lineHeight' : '140px'});
		$('#stage-referenzen').fadeOut(500);
		$('#trigger-referenzen').animate({'paddingTop' : '0px', 'lineHeight' : '140px'});
	}
	else if (name == 'drupal')
	{
		$('#stage-web').fadeOut(500);
		$('#trigger-web').animate({'paddingTop' : '0px', 'lineHeight' : '140px'});
		$('#stage-community').fadeOut(500);
		$('#trigger-community').animate({'paddingTop' : '0px', 'lineHeight' : '140px'});
		$('#stage-jquery').fadeOut(500);
		$('#trigger-jquery').animate({'paddingTop' : '0px', 'lineHeight' : '140px'});
		$('#stage-referenzen').fadeOut(500);
		$('#trigger-referenzen').animate({'paddingTop' : '0px', 'lineHeight' : '140px'});
	}
	else if (name == 'jquery')
	{
		$('#stage-web').fadeOut(500);
		$('#trigger-web').animate({'paddingTop' : '0px', 'lineHeight' : '140px'});
		$('#stage-community').fadeOut(500);
		$('#trigger-community').animate({'paddingTop' : '0px', 'lineHeight' : '140px'});
		$('#stage-drupal').fadeOut(500);
		$('#trigger-drupal').animate({'paddingTop' : '0px', 'lineHeight' : '140px'});
		$('#stage-referenzen').fadeOut(500);
		$('#trigger-referenzen').animate({'paddingTop' : '0px', 'lineHeight' : '140px'});
	}
	else if (name == 'community')
	{
		$('#stage-web').fadeOut(500);
		$('#trigger-web').animate({'paddingTop' : '0px', 'lineHeight' : '140px'});
		$('#stage-drupal').fadeOut(500);
		$('#trigger-drupal').animate({'paddingTop' : '0px', 'lineHeight' : '140px'});
		$('#stage-jquery').fadeOut(500);
		$('#trigger-jquery').animate({'paddingTop' : '0px', 'lineHeight' : '140px'});
		$('#stage-referenzen').fadeOut(500);
		$('#trigger-referenzen').animate({'paddingTop' : '0px', 'lineHeight' : '140px'});
	}
	else if (name == 'referenzen')
	{
		$('#stage-web').fadeOut(500);
		$('#trigger-web').animate({'paddingTop' : '0px', 'lineHeight' : '140px'});
		$('#stage-community').fadeOut(500);
		$('#trigger-community').animate({'paddingTop' : '0px', 'lineHeight' : '140px'});
		$('#stage-drupal').fadeOut(500);
		$('#trigger-drupal').animate({'paddingTop' : '0px', 'lineHeight' : '140px'});
		$('#stage-jquery').fadeOut(500);
		$('#trigger-jquery').animate({'paddingTop' : '0px', 'lineHeight' : '140px'});
	}
	setTimeout(function ()
	{
		$('#stage-'+name).fadeIn(500);
	}, 500);
	$('#trigger-'+name).animate({'paddingTop' : '20px', 'lineHeight' : '130px'});
}

function start_display_projekt(name)
{
	$('#projekte-selector').animate({opacity : 0.2});
	if (name == 'librebox')
	{
		$('#clipgrab-info').slideUp();
		$('#deings-info').slideUp();
		$('#projekte-selector').animate({left : 35});
		
	}
	else if (name == 'clipgrab')
	{
		$('#librebox-info').slideUp();
		$('#deings-info').slideUp();
		$('#projekte-selector').animate({left: 146});
	}
	else if (name == 'deings')
	{
		$('#librebox-info').slideUp();
		$('#clipgrab-info').slideUp();
		$('#projekte-selector').animate({left : 263});
	}
	$('#projekte-selector').animate({opacity : 1});
	$('#'+name+'-info').slideDown();
}


function software_display_info(name)
{
	$('#info-selector').animate({opacity : 0.2});
	if (name == 'gpl')
	{
		$('#qt-info').slideUp();
		$('#info-selector').animate({left : 67});
		
	}
	else if (name == 'qt')
	{
		$('#gpl-info').slideUp();
		$('#info-selector').animate({left: 220});
	}
	$('#info-selector').animate({opacity : 1});
	$('#'+name+'-info').slideDown();
}

function software_show_screenshot(object)
{
	$('#overlay-bg').fadeIn();
	$('#overlay img').remove();
	$('#overlay p').remove();
	$('#overlay').append('<img src="' + object.attr('href') + '" style="margin-top:50px;" />');
	$('#overlay').fadeIn();
	$('#overlay img').css('top', $(window).height()/2-$('#overlay img').height()/2); 
	$('#overlay img').css('left', $(window).width()/2-$('#overlay img').width()/2); 
	$('#overlay').append('<p>'+$('img', object).attr('alt')+'</p>');
	
}

function initialise(site)
{
	if (site == 'start')
	{
		prepare(site);
		//Creating event handlers
		$('#librebox-trigger').click(function(){start_display_projekt('librebox');});
		$('#librebox-trigger').hover(function(){$(this).css('cursor', 'pointer')});
		$('#clipgrab-trigger').click(function(){start_display_projekt('clipgrab');});
		$('#clipgrab-trigger').hover(function(){$(this).css('cursor', 'pointer')});
		$('#deings-trigger').click(function(){start_display_projekt('deings');});
		$('#deings-trigger').hover(function(){$(this).css('cursor', 'pointer')});
		$('h3').hover(function(){$(this).css('cursor', 'pointer')});
	}

	else if (site == 'web')
	{
		prepare(site);
		//Creating event handlers
		$('.stage-sub').click(function(){web_display_stage_sub($(this));});
		$('#trigger-web').click(function(){web_display_stage('web');});
		$('#trigger-drupal').click(function(){web_display_stage('drupal');});
		$('#trigger-jquery').click(function(){web_display_stage('jquery');});
		$('#trigger-community').click(function(){web_display_stage('community');});
		$('#trigger-referenzen').click(function(){web_display_stage('referenzen');});
	}
	else if (site == 'software')
	{
		prepare(site);
		//Creating event handlers
		$('#trigger-gpl').click(function(){software_display_info('gpl');});
		$('#trigger-gpl').hover(function(){$(this).css('cursor', 'pointer')});
		$('#trigger-qt').click(function(){software_display_info('qt');});
		$('#trigger-qt').hover(function(){$(this).css('cursor', 'pointer')});
		$('.thumbnail').click(function(e){e.preventDefault();software_show_screenshot($(this));});
		
		$('#overlay').click(function(){$(this).fadeOut();$('#overlay-bg').fadeOut();});
		
	}
}
if ($('#site').hasClass('start'))
	{
		initialise('start');
	}
else if ($('#site').hasClass('web'))
	{
		initialise('web');
	}
else if ($('#site').hasClass('software'))
	{
		initialise('software');
	}
else if ($('#site').hasClass('kontakt'))
	{
		initialise('kontakt');
	}
});


function UnCryptMailto(s, shift) {
	var n=0;
	var r="";
	for(var i=0;i<s.length;i++) { 
		n=s.charCodeAt(i); 
		if (n>=8364) {n = 128;}
		r += String.fromCharCode(n-(shift)); 
	}
	return r;
}
function linkTo_UnCryptMailto(s, shift)	{
	location.href=UnCryptMailto(s, shift);
}
