
/* ############################# CONFIG ########################### */
	dTS 	= '30px'; 				//Default Teaser Size
	dTIS	= '50px'; 				//Default Teaser Image Size
	dTLC 	= 'rgb(30,30,30)'; 		//Default Teaser Link Color
	dTO 	= 0.33;			 		//Default Teaser Opacity
	
	fTS 	= '100px'; 				//Focused Teaser Size
	fTIS 	= '100px'; 				//Focused Teaser Image Size
	fTLC 	= 'rgb(230,230,230)'; 	//Focused Teaser Link Color
	fTO 	= 1;			 		//Focused Teaser Opacity
	
	aniDur 	= 200;			//Duration of an Animation in ms
	
$(document).ready(function(){
	/*$(".freeTrial").click(function(event){
		event.preventDefault();
		$.get('/bin/assets/trialLessonBox.php', function(data){
			$("#superHeader").before(data);
		});
	});*/

	$("#educ").hide();
	$("#about").hide();
	$("#mag").hide();
	$("#career").hide();
	
	$(".navi").mouseenter(function(){
		$(this).stop();
		$(this).fadeTo(aniDur,0);
	});
	$(".navi").mouseleave(function(){
		$(this).stop();
		$(this).fadeTo(aniDur,1);
	});
	
});

var musicPlayer = null; 
function playerReady(theMusicPlayer) {
	musicPlayer = document.getElementById('mpl');
	addListeners();
}
function stateListener(obj){
		$.get('/bin/assets/musicPlayed.php', {}, function(data){
			//alert(data);
		});
}
function addListeners() {
	if (musicPlayer){ 
		// http://developer.longtailvideo.com/trac/wiki/Player4Events#Viewevents
		// http://developer.longtailvideo.com/trac/wiki/Player4Api#Readingvariables
		musicPlayer.addViewListener("ITEM", "stateListener");
		musicPlayer.addViewListener("PLAY", "stateListener");
		musicPlayer.addViewListener("NEXT", "stateListener");
		musicPlayer.addViewListener("PREV", "stateListener");
	} else {
		setTimeout("addListeners()",100);
	}
}



function fbShare(id, tbl){
	$.get('/bin/assets/fbShareClicked.php', {id:id, tbl:tbl}, function(data){
		//Could be a Callback
	});
}

function expandPlayer(targId, height){
	$("#"+targId).animate({ 
		height: height
	}, 250 );
}

function initSlideShow(containerId, images){
	container = document.getElementById(containerId);
	
	container.innerHTML = "\n<div id=\"image\">\n\t<img width=\"200\" src=\"/upload/galerie/"+images[0]+"\" id=\"slideshowImage\" />\n</div>\n";
	container.innerHTML += "<div id=\"imageOverlay\">\n\t<img width=\"200\" src=\"\" id=\"slideshowImageOverlay\" />\n</div>\n";
	
	//container.style.backgroundImage = 'url(/upload/slideshow/'+imgs[imgs.length-1]+')';
		
	
	$("#slideshowImageOverlay").fadeTo(0, '0');
	
	fadeTime = 1500;
	waitTime = 1500;
	currImg = 0;
	slideshowImgVis = true;
	
	slideshow(currImg);
	
	/*slideshow = window.setInterval(function(){
	
	
	
	}, fadeTime+fadeTime+waitTime);*/
}

function slideshow(currImg){
		var slideshowImage = document.getElementById('slideshowImage');
		var slideshowImageOverlay = document.getElementById('slideshowImageOverlay');
		
		worked = false;
		
		if(currImg > imgs.length -1){
			currImg = 0;
		}
		
		if(currImg+1 >= imgs.length -1){
			nextImg = 0;
		}else{
			nextImg = currImg +1;
		}

		
		slideshowImageOverlay.src = '/upload/galerie/'+imgs[currImg];
		
		$("#slideshowImageOverlay").fadeTo(fadeTime, '1', function(){ //callback
		
			slideshowImage.src = '/upload/galerie/'+imgs[nextImg];
			window.setTimeout(function(){
				$("#slideshowImageOverlay").fadeTo(fadeTime, '0', function(){
					slideshow(nextImg);
				});
			}, waitTime);
			
		});
				
		currImg++;

}


function checkSubject(ref, target){
	if(ref.value == 'Bewerbung'){
		document.getElementById(target).disabled = true;
		document.getElementById(target).style.borderColor = '#330000';
		document.getElementById(target).style.color = '#666666';
		
	}else{
		document.getElementById(target).disabled = false;
		document.getElementById(target).style.borderColor = '#cc0000';
		document.getElementById(target).style.color = '#ffffff';

	}
}

function expand(id){
	$("#"+id).toggle(200);
}

$(document).ready(function(){
	$(".navi").mouseleave(function(){
		if(typeof subNaviHideTimer != "undefined"){window.clearTimeout(subNaviHideTimer);}
		subNaviHideTimer = window.setTimeout(function(){hideSubNav("none");}, 2000);
	});
	$(".subNav").mouseleave(function(){
		if(typeof subNaviHideTimer != "undefined"){window.clearTimeout(subNaviHideTimer);}
		subNaviHideTimer = window.setTimeout(function(){hideSubNav("none");}, 2000);
	});
	$(".subNav").mouseenter(function(){
		if(typeof subNaviHideTimer != "undefined"){window.clearTimeout(subNaviHideTimer);}
	});
});

function showSubNav(targetId){
	hideSubNav(targetId);
	$("#"+targetId).stop();
	$("#"+targetId).fadeIn(aniDur);
}

function hideSubNav(besides){
	if(typeof subNaviHideTimer != "undefined"){window.clearTimeout(subNaviHideTimer);}
	
	if(besides != 'educ'){
		$("#educ").fadeOut(aniDur, function(){
			$("#educ").hide();
		});
	}
	if(besides != 'about'){
		$("#about").fadeOut(aniDur, function(){
			$("#about").hide();
		});
	}
	if(besides != 'mag'){
		$("#mag").fadeOut(aniDur, function(){
			$("#mag").hide();
		});
	}
	if(besides != 'career'){
		$("#career").fadeOut(aniDur, function(){
			$("#career").hide();
		});
	}
}
	
	function newsLoop(offset){
		if(typeof newsLoopTO != "undefined"){window.clearTimeout(newsLoopTO)};
		
			$("#News"+offset).stop();
			$("#News"+offset).animate({height: fTS, opacity:fTO}, aniDur );
		
		if(typeof document.getElementById('NewsImg'+offset) != "undefined" && document.getElementById('NewsImg'+offset) != null ){

			$("#NewsImg"+offset).stop();
			$("#NewsImg"+offset).animate({ 
				width: fTIS,
				height: fTIS
			}, aniDur );

		}
		
		collapseBlurs(offset);
		var next = parseInt(offset)+1;
		if(next <= 4){
			newsLoopTO = window.setTimeout("newsLoop("+next+")", 5000);
		}else{
			newsLoopTO = window.setTimeout("newsLoop(0)", 5000);
		}
	}
	
 $(document).ready(function(){


	 
 
	$("#NewsTeaserBox").mouseleave(function(){
		newsLoopTO = window.setTimeout('newsLoop(0)', 1);
	});
	
	// #### EVENT HANDLER: #News0 ####
	$("#News0").mouseenter(function(){
		focusTeaser(0);
	});
	$("#News1").mouseleave(function(){
		blurTeaser(0);
	});

	// #### EVENT HANDLER: #News1 ####
	$("#News1").mouseenter(function(){
		focusTeaser(1);
	});
	$("#News1").mouseleave(function(){
		blurTeaser(1);
	});
		
	// #### EVENT HANDLER: #News2 ####
	$("#News2").mouseenter(function(){
		focusTeaser(2);
	});
	$("#News2").mouseleave(function(){
		blurTeaser(2);
	});
	
	// #### EVENT HANDLER: #News3 ####
	$("#News3").mouseenter(function(){
		focusTeaser(3);
	});
	$("#News3").mouseleave(function(){
		blurTeaser(3);
	});
		
	// #### EVENT HANDLER: #News4 ####
	$("#News4").mouseenter(function(){
		focusTeaser(4);
	});
	$("#News4").mouseleave(function(){
		blurTeaser(4);
	});

});
	
	function focusTeaser(offset){
			collapseBlurs(offset);
			window.clearTimeout(newsLoopTO);
			$("#News"+offset).stop();
			$("#News"+offset).animate({height: fTS, opacity:fTO}, aniDur );

			if(typeof document.getElementById('NewsImg'+offset) != "undefined" && document.getElementById('NewsImg'+offset) != null ){
				$("#NewsImg"+offset).stop();
				$("#NewsImg"+offset).animate({width: fTIS,height: fTIS}, aniDur );
			}
	}

	function blurTeaser(offset){
			$("#News"+offset).stop();		
			$("#News"+offset).animate({height: dTS, opacity:dTO}, aniDur );
			
			if(typeof document.getElementById('NewsImg'+offset) != "undefined" && document.getElementById('NewsImg'+offset) != null ){
				$("#NewsImg"+offset).stop();
				$("#NewsImg"+offset).animate({width: dTIS, height: dTIS}, aniDur );
			}
	}

	function collapseBlurs(active){
		for(i=0;i<5;i++){
			if(active != i){
				$("#News"+i).stop();
				$("#News"+i).animate({height: dTS, opacity:dTO}, aniDur );
				
				if(typeof document.getElementById('NewsImg'+i) != "undefined" && document.getElementById('NewsImg'+i) != null ){
					$("#NewsImg"+i).stop();
					$("#NewsImg"+i).animate({ 
						width: dTIS,
						height: dTIS
					}, aniDur );
				} // if img
				
			} // if active
		} //for
	}// collapseBlurs();


function insertSwitch(toShow){

	document.getElementById('news').style.display = 'none';
	document.getElementById('termin').style.display = 'none';
	document.getElementById('video').style.display = 'none';
	document.getElementById('standort').style.display = 'none';
	document.getElementById('galerie').style.display = 'none';
	
	document.getElementById(toShow).style.display = 'block';

}

function changeCalendar(timestamp, owner){
		$("#calendarContainer").fadeTo(250, 0.6)
		$("#calendarLoading").html('<img src="/bin/pic/smallLoading.gif" alt="Daten werden Geladen" />');
		$.get('/bin/assets/calendar.php', {m:timestamp, owner:owner}, function(data) {
			$("#calendarContainer").fadeTo(100, 0, function(){
			$('#calendarContainer').html(data);
			$("#calendarContainer").fadeTo(100, 1, function(){$("#calendarLoading").html('');});
							
		});
		
	});
}


function getTooltip(ref){
	$('#'+ref).fadeIn("fast");
}

function hideTooltip(ref){
	$('#'+ref).fadeOut("fast");
}

function openShop(){
	window.open('shop.php', "Zweitfenster", "width=800,height=600,left=100,top=100,scrollbars=no");
}

function openPlayer(file, name, width, height){
	//window.open(file, name, "width="+width+",height="+height+",left=100,top=100,scrollbars=yes,location=no,status=no");
	newWindow = window.open(file, name, "width=1,height=1,left=100,top=100,scrollbars=yes,location=no,status=no");
}

function navigate(to){
	if(to != 'nochange'){
		window.location.href = to.toLowerCase() + '/';
	}
}

function clearField(ref, vorbeleg){
	if(ref.value == vorbeleg){
		ref.value = '';
	}
}

function openImageDetails(id, width, height){
	srcstring 	= '/galerie_details.php?id='+id+'&offset=0';
	winWidth 	= parseInt(width)+100;
	winHeight 	= parseInt(height)+200;
	if(winHeight > screen.height){
		winHeight = screen.height;
	}
	optsstring	= "width="+winWidth+",height="+winHeight+",left=100,top=0,scrollbars=yes,resizable=yes";
	
	window.open(srcstring, "Zweitfenster", optsstring);
}

function increaseCart(item, price){

	var priceNew = price.split(',');
	priceNew = priceNew.join('.');

	if(	document.shop.order.value == ''){
		summ = 0.0;
	}
		
	summ += parseFloat(priceNew);

	var output = summ;
	
	output = output.toString(10);
	output = output.split('.');

	if(output[1] != undefined){
		if( output[1].substr(2,2) == '' || output[1].substr(2,2) == '00'){
				output[1]+='0';
		}
	}
	
	output = output.join(',');
	
	if(summ<100){
		output = output.substr(0,5);
	}else{
		output = output.substr(0,6)
	}

	document.getElementById('summDisplay').innerHTML = '';
	document.getElementById('summDisplay').innerHTML = output+'€';
	
	document.shop.order.value += '1x '+item+' \\\\ '+price+'€\n';
	document.shop.summe.value = output+'€';
}