// JavaScript Document


$(document).ready(function(){
	// actual page
	here = $('body');
	
	ie6catch = $.browser.msie + $.browser.version;
 	if (ie6catch.indexOf("true6") == -1 && ie6catch.indexOf("true7") == -1) {
		$('#window').slideDown(800);
	}
 	else
 	{
		
	 	$('#window').show(); 
	}
	
	spektrum();
	startCufon();
	
});


function startCufon(){
 	
	if(document.location.href.indexOf("/cn/") == -1)
	{
	Cufon.replace('#menu a', {fontFamily:'univers-regular', hover:'true'});
	Cufon.replace('#header h1', {fontFamily:'univers-regular'});
	Cufon.replace('h2', {fontFamily:'univers-regular'});
	}
	
}


function spektrum(){
	var target;
	$('#leistungsspektrum #content ul a:not(.headmenu)').click(function(){
	// stopall();
		$('.legend_left_holder *').stop(true, true);
		$('.legend_right_holder *').stop(true, true);
		$('.anz_anim *').stop(true, true);
		target = $(this).attr('href');
		
		$('#picWrap').load('spektrum/'+target, '', function(){
																												
			spekGal();
			//lsChange();
			//Cufon.replace('h2');
			//startCufon();
		});
		
		$('#content ul li').removeClass('active');
		$(this).parent('li').addClass('active');
		
		return false;
	});	
}



function spekGal(){
	var autoWidth;
	isLoaded = 1;
	
	
	$('.award_img').hover(function(){
			$(this).attr('src', '../images/template/award_anim_akt.gif');							 
	}, function(){
		//if($(this).attr('class').indexOf("award_on") == -1)
		if(!$(this).hasClass('award_on'))
		{
			$(this).attr('src', '../images/template/award_anim.gif');	
		}
	});
	
	$('.award_img').click(function(){
		$('.award_div').stop(true,true).css('width', '0');
		autoWidth = $(this).next().children().width();
		$(this).next().animate({'width':autoWidth}, 500);
		$('.awards img').attr('src', '../images/template/award_anim.gif').removeClass('award_on');		
		$(this).attr('src', '../images/template/award_anim_akt.gif').addClass('award_on');
	});
	
	
	
	$('.submenu .description .next').click(function(){
		$('.description span').css('opacity', '0');
			stopall();
			// Filmstop
			stopit = $(this).parent('.description').attr('rel');
		
			if(stopit){
				window.document[stopit].sendEvent('STOP');
			}
		
			$(arrContent[currContent]).animate({'left':'-900px'}, 500).next().animate({'left':'0'}, 500, function(){
				currContent++;
				animall(arrContent[currContent]);
			});
	});
	
	$('.submenu .description .back').click(function(){
		$('.description span').css('opacity', '0');																						
		stopall();
		// Filmstop
		stopit = $(this).parent('.description').attr('rel');
		
		if(stopit)
		{
			window.document[stopit].sendEvent('STOP');
		}
	
		$(arrContent[currContent]).animate({'left':'900px'}, 500).prev().animate({'left':'0'}, 500,function(){
			currContent--;
			animall(arrContent[currContent]);
		});
		
	});
}

function stopall() {
		$('.legend_point').hide();
		$('.legend_right .linie span').hide();
		$('.legend_left .linie span').hide();
		
		$('.img1').removeAttr('style');
		$('.img2').removeAttr('style');
		$('.shadow1').removeAttr('style');
		$('.shadow2').removeAttr('style');
		
		$('.legend_right').stop(true, true);
		$('.legend_left').stop(true, true);
		
		$('.legend_right .linie span').stop(true, true);
		$('.legend_left .linie span').stop(true, true);
		
		$('.weblink').stop(true, true);
		
		$('.legend_right').css('opacity', '0');
		$('.legend_left').css('opacity', '0');
		
		$('.weblink').css('opacity', '0');
	}

// Animation legend
function animlegend(_currContent) {
	
	$('.description span').animate({opacity: 1}, 1000);
	$('.legend_point').show();
	
	$(_currContent).find('.legend_right').animate({opacity: 1}, 1000, function(){
		$(_currContent).find('.legend_right .linie span').effect('slide', {direction: 'right'}, 1500, function(){ 
			$(_currContent).find('.legend_right .weblink').animate({opacity: 1}, 500);
		});
	});
	
	
	$(_currContent).find('.legend_left').animate({opacity: 1}, 1000, function(){
		$(_currContent).find('.legend_left .linie span').effect('slide', {direction: 'left'}, 1500, function(){ 
			$(_currContent).find('.legend_left .weblink').animate({opacity: 1}, 500);
		});
	});
	
}



function animall(_currContent) {
	
	
	
	if($(_currContent).attr('rel') == 'ecojump'){
		
		$('.description span').animate({opacity: 1}, 1000);
		// animation blätter
		$(_currContent).find('.img2').effect('slide', {direction: 'up', distance: 800}, 500,function(){
			$(_currContent).find('.img2').effect('bounce', {direction: 'up', times:2, distance:25}, 400,function(){
				$(_currContent).find('.img1').effect('slide', {direction: 'up', distance: 800}, 500,function(){
					$(_currContent).find('.img1').effect('bounce', {direction: 'up', times:2, distance:25}, 400)
				});
			});
		});
	
		// animation blätter schatten
		$(_currContent).find('.shadow2').effect('slide', {direction: 'left', distance: 800}, 500,function(){
			$(_currContent).find('.shadow2').effect('bounce', {direction: 'left', times:2, distance:25}, 400,function(){
				$(_currContent).find('.shadow1').effect('slide', {direction: 'left', distance: 800}, 500,function(){
					$(_currContent).find('.shadow1').effect('bounce', {direction: 'left', times:2, distance:25}, 400, function(){
						$(_currContent).find('.legend_point').animate({opacity: 1}, 1000, function(){
							animlegend(_currContent);																																	
						});
					})
				});		
			});
		});
	}
	else
	{
		$('.legend_point').css('opacity', '1');
		animlegend(_currContent);
	}
}

function lsChange() {
	$(document).pngFix();
	currContent=0;
	arrContent = null;
	arrContent = $("#picWrap").find('.extcontent');
	if(isLoaded == 0)
	spekGal();
	startCufon();
	//$('.ani').hide();	
	
	$('.legend_right .linie span').hide();
	$('.legend_left .linie span').hide();
	
	animall(arrContent[currContent]);
}


