$(function() {
	var idBuehne = getIDasString('id');
	var lang = getIDasString('lang');
	
	var $buehne = $(idBuehne + ' #buehne');
	var $head = $(idBuehne + ' h1');
	var $usp = $(idBuehne + ' .usp');
	var $slideIn = $(idBuehne + ' .bgSlideIn a');	
	var slideInLeft = parseInt($slideIn.css('left'));	
	
	allLinks4Sitestat('onclick.buehne.' + getIDasString('year'),getIDasString('id'));
	
	if(getCookie('mainStage') == 'opened'){
		return;
	}
	
	setCookie('mainStage','opened',0.125);
	
	initAnimation();
	
	function initAnimation(){
	
		$(idBuehne).preloadAnimation({'size':'big','show':true});
		
		var serverPath = '/static/bilder/mainStage/2012/01/';
//		var serverPath = 'lokal';
		
		var bgImg = 'images/mainStage_bg.jpg';
		if(lang == 'fr' || lang == 'nl'){
			bgImg = 'images/mainStage_bg_' + lang + '.jpg';
		}
		
		var images = new Array();
		images.push(bgImg);
		images.push('images/mainStage_txt_' + lang + '.png');	
		
		$.preloadImages(images, animateBuehne, serverPath);	
		$buehne.css('top','-400px');
		$usp.hide();
		$slideIn.hide();
		$head.hide();
		$(idBuehne + ' a').bind('click.wait4Animation',function(e) {
			return (false);
		});
		
	}
	
	function animateBuehne(){
		$('body').preloadAnimation('hide');
		$buehne
			.animate(
				{'top':'0'},
				1000,
				'swing',
				function(){
					animateHead();
				}
			);
	}
	function animateHead() {
		$head
			.css('top','-' + $head.height() + 'px')
			.show()
			.animate(
				{'top' : '0'},
				500,
				'swing',
				function(){
					animateUSP();
				}
			);
	}
	function animateUSP() {
		$usp.show(
			250,
			'linear',
			function(){
				animateSlideIn();
			});
	}
	function animateSlideIn(){
		$slideIn
			.css('left',slideInLeft - 60)
			.show()
			.animate(
				{'left':slideInLeft},
				300,
				'swing',
				function(){	
					$(this).css('left','');
				}
			);
		$(idBuehne + ' a').unbind('click.wait4Animation');	
	}
});	
//	function fertig(parameter, parameter2){
//		return function() {
//			debug(parameter);
//		};
//	}
