/* ############################# 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(){

	hideSubNav('none');
	$(".navi").mouseenter(function(){
		$(this).stop();
		$(this).fadeTo(aniDur,0);
	});
	$(".navi").mouseleave(function(){
		$(this).stop();
		$(this).fadeTo(aniDur,1);
	});
});

function expand(id){
	$("#"+id).toggle(200);
}
	
function showSubNav(targetId){
	hideSubNav('all');
	$("#"+targetId).fadeIn(aniDur);
}

function hideSubNav(besides){
	if(besides != 'educ'){
		$("#educ").fadeOut(aniDur);
		$("#educ").hide();
	}
	if(besides != 'about'){
		$("#about").fadeOut(aniDur);
		$("#about").hide();
	}
	if(besides != 'mag'){
		$("#mag").fadeOut(aniDur);
		$("#mag").hide();
	}
	if(besides != 'career'){
		$("#career").fadeOut(aniDur);
		$("#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 ){
			
			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("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 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=yes");
}

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";
	
	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+'€';
}


function initSlideShow(containerId, imgs){
	container = document.getElementById(containerId);
	container.innerHTML = '<img src="'+imgs[0]+'" id="slideshowImage" />';
	container.style.backgroundImage = 'url(/upload/slideshow/'+imgs[imgs.length-1]+')';
	//alert(containerId);
	//dump('\t url(/upload/slideshow/'+imgs[imgs.length-1]+') \n\n');
	
	slideshowImage = document.getElementById('slideshowImage');
	$("#slideshowImage").fadeTo(0, '0');
	
	fadeTime = 3000;
	waitTime = 3000;
	currImg = 0;
	slideshowImgVis = true;
	
	var slideshow = window.setInterval("xslideShow()", fadeTime+fadeTime+waitTime);
}

function xslideShow(){

		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/slideshow/'+imgs[currImg];
		
		$("#slideshowImage").fadeTo(fadeTime, '1', function(){
			
			
			//alert(nextImg);
			
			container.style.backgroundImage = 'url(/upload/slideshow/'+imgs[nextImg]+')';
			window.setTimeout(function(){
				$("#slideshowImage").fadeTo(fadeTime, '0');
			}, waitTime);
		});
				
		currImg++;
}

