
/* ############################# CONFIG ########################### */
	dTS 	= '40px'; 				//Default Teaser Size
	dTIS	= '40px'; 				//Default Teaser Image Size
	dTLC 	= 'rgb(30,30,30)'; 		//Default Teaser Link Color
	dTO 	= 0.33;			 		//Default Teaser Opacity
	
	fTS 	= '60px'; 				//Focused Teaser Size
	fTIS 	= '60px'; 				//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 resettext(feld)
	{
   	 if(feld.value=="... oder Plz eingeben")
    {
        feld.value="";
    }
}



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 = '<img src="" id="slideshowImage" />';
	
	if (containerId == "slideshow")  container.innerHTML = '<img src="" id="slideshowImage" style="width:200px; height:140px" />';
	
	c= imgs.length-1;
	
	//if (containerId == "slideshow") container.style.backgroundImage = 'url(/upload/galerie/'+imgs[c]+')';
	//else container.style.backgroundImage = 'url(/upload/galerie/'+imgs[c]+')';
	
	//dump('\t url(/upload/slideshow/'+imgs[0]+') \n\n');
	
	slideshowImage = document.getElementById('slideshowImage');
	$("#slideshowImage").fadeTo(0, '0');
	
	fadeTime = 3200;
	waitTime = 500;
	currImg = 0;
	slideshowImgVis = true;
	
	var slideshow = window.setInterval("xxxslideShow()", fadeTime+fadeTime+waitTime);
}

function xslideShow(cid){



		worked = false;
		//alert("xsl");
		
		if(currImg > imgs.length -1){
			currImg = 0;
		}
		
		if(currImg+1 >= imgs.length -1){
			nextImg = 0;
		}else{
			nextImg = currImg +1;
		}

		slideshowImage = document.getElementById('slideshowImage');
		slideshowImage.src = '/upload/galerie/'+imgs[currImg]+' style="width:200px; height: 140px"';
		
		
		
		$("#slideshowImage").fadeTo(fadeTime, '1', function(){
			
			
	
			
			container.style.backgroundImage = 'url(/upload/galerie/'+imgs[nextImg]+') height=140px width=200px';
			window.setTimeout(function(){
				$("#slideshowImage").fadeTo(fadeTime, '0');
			}, waitTime);
		});
				
		currImg++;
}



function xxxslideShow(cid){



		worked = false;
		//alert("xsl");
		
		if(currImg > imgs.length -1){
			currImg = 0;
		}
		
		if(currImg+1 >= imgs.length -1){
			nextImg = 0;
		}else{
			nextImg = currImg +1;
		}

		slideshowImage = document.getElementById('slideshowImage');
		slideshowImage.src = '/upload/galerie/'+imgs[currImg];
		
		
		
		$("#slideshowImage").fadeTo(fadeTime, '1', function(){
			
			
			//alert(nextImg);

			
			
			container.style.backgroundImage = 'url(/upload/galerie/'+imgs[nextImg]+') height=140px width=200px';
			window.setTimeout(function(){
				$("#slideshowImage").fadeTo(fadeTime, '0');
			}, 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();
		});
	}
	

	
}
	
		var vbImgPath="mmsbutton-files/";
		var btIdPref="vb";
		function xxppr(im)
		{
			var i=new Image;
			i.src=vbImgPath+"bt"+im;return i;
		}
		
		function xxpe(id)
			{
				
				
				x=id.substring(0,id.length-1);
				if(document[btIdPref+x])	
					{
						document[btIdPref+x].src=eval(btIdPref+id+".src");
					}
			}


function moveImage(source){
		$("#newsFocusImage").fadeOut(aniDur);
		$("#"+source).hide(aniDur);
		
		window.setTimeout(function(){
			document.getElementById('newsFocusImage').src = document.getElementById(source).src
			$("#newsFocusImage").fadeIn(aniDur);
		}, aniDur);
	}

	
function newsLoop22(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 ){
			
			moveImage("NewsImg"+offset)

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

		}
		
		collapseBlurs(offset);
		var next = parseInt(offset)+1;
		
		
		
		if(next <= 4){
			//while(typeof document.getElementById('News'+next) == "undefined" || document.getElementById('News'+next) == null ){
			//	if(next <= 4){next++;document.write(next+'<br>');}else{next = 0;}
			//}
			newsLoopTO = window.setTimeout("newsLoop22("+next+")", 5000);
		}else{
			newsLoopTO = window.setTimeout("newsLoop22(0)", 5000);
		}
	}
	
	
	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 ){
			
			h = document.getElementById('NewsImg'+offset).style.height;
			w = document.getElementById('NewsImg'+offset).style.width;
			
			moveImage("NewsImg"+offset)
			
			sf = fTIS * 100/w;
			h2 = h * sf/100;

			$("#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 );
				moveImage("NewsImg"+offset);
			}
	}
	
	function moveImage(source){
		$("#newsFocusImage").fadeOut(aniDur);
		$("#"+source).hide(aniDur);
		
		window.setTimeout(function(){
			document.getElementById('newsFocusImage').src = document.getElementById(source).src
			$("#newsFocusImage").fadeIn(aniDur);
		}, 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+'€';
}
