// JavaScript Document

$(document).ready(function(){
						   
	removeFocus();
	
	menuinit();

	menufunction();
	
	if(!$('#navi ul.layer1 li').hasClass('active')) $('#menu_27').parent('div').parent('li').addClass('active');
	
	if ( ($('#scrollpanearea').html() != null) && ($('#scrollpanearea').html() != '') ) $('#scrollpanearea').jScrollPane({showArrows:true, arrowSize: 0, dragMinHeight:38, dragMaxHeight:38});
	
	if ( ($('#wahlinterview').html() != null) && ($('#wahlinterview').html() != '') ) wahlinterview();
	
	$('#menu_49').fancybox({ 
		'zoomSpeedIn': 300,
		'zoomSpeedOut': 300,
		'overlayShow': true,
		'frameWidth':790,
		'frameHeight':480,
		'hideOnContentClick':false
		});		
});

function playVideo(video, title, size){
	if (size == "small"){ v_height = "240" } else { v_height = "311"}
	$("#youtubeVideo").html('<object width="384" height="'+v_height+'"><param name="movie" value="'+ video +'&rel=0" /><param name="allowFullScreen" value="true"><param name="allowscriptaccess" value="always"><embed src="'+ video +'&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="384" height="'+v_height+'"></object>');
	$("#youtubeVideoTitle").html(title);
	return false;
}

function menuinit(){

	$('#navi .layer2 li #menu_34').parent('li').css({'background-image':'url(fileadmin/templates/_img/design/navi/pfeil_green.gif)'});
	$('#navi .layer2 li #menu_33').parent('li').css({'background-image':'url(fileadmin/templates/_img/design/navi/pfeil_red.gif)'}); 
	$('#navi .layer2 li #menu_32').parent('li').css({'background-image':'url(fileadmin/templates/_img/design/navi/pfeil_yellow.gif)'}); 
	$('#navi .layer2 li #menu_41').parent('li').css({'background':'none','font-weight':'bold','border':'none','color':'#233b7e'});
	
	/*$('#navi .layer2 li #menu_42').parent('li').html('<object width="199" height="120"><param name="movie" value="http://www.youtube.com/v/1nEHtm8ZpBs&hl=de&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/1nEHtm8ZpBs&hl=de&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="199" height="120"></embed></object>').attr("id","naviYoutube");*/
	
	$('#navi .layer2 li #menu_42').parent('li').html('<a href="http://www.volvic.de/bundesgeschmackswahl/piet-klocke-tv-ansehen/alle-interviews-ansehen.html" title="Alle Interviews"><img src="fileadmin/templates/_img/klocke.jpg" alt="Piet Klocke" title="Piet Klocke" /></a>').attr("id","naviYoutube");	
	
}

function menufunction(){

	$('#navi .layer1 a:not(.layer2 a)').bind("click",
		function(){
			if ( $(this).parent('div').parent('li').hasClass('open')){
				$(this).parent('div').parent('li').removeClass("open active");				
				$('#naviYoutube object').css("visibility","hidden");				
				$(this).parent('div').parent('li').children('ul').slideUp("fast", function(){window.setTimeout("$('#naviYoutube object').css('visibility','visible')",250)});	
				return false;
			} else {
				if ( $(this).parent('div').parent('li').is(":has('ul')") ){
					$('#naviYoutube object').css("visibility","hidden");
					$('#navi .layer1 li').removeClass("open active");
					$('#navi .layer1 li').children('ul').slideUp("fast", function(){window.setTimeout("$('#naviYoutube object').css('visibility','visible')",250)});
					$(this).parent('div').parent('li').addClass('open');
					$(this).parent('div').parent('li').children('ul').slideDown("fast");
					return false;
				} else {
					return true;
				}
			}
		}
	);
}

function removeFocus(){
	$('a').each(function(){
		$(this).bind(
			'focus',
				function() {
					this.blur();
				}
		 )
	}); 
}

function wahlinterview(){
	$('#wahlinterview ul li').bind("click", function(){
			if ( $(this).hasClass("open") ){
				$(this).removeClass("open");
				$(this).children('ul').slideUp("fast");
				$(this).css("background-image","url('fileadmin/templates/_img/design/pfeil.gif')")
			} else {
				$(this).addClass("open");
				$(this).children('ul').slideDown("fast");
				$(this).css("background-image","url('fileadmin/templates/_img/design/pfeil_unten.gif')")				
			}
			window.setTimeout("$('#scrollpanearea').jScrollPane({showArrows:true, arrowSize: 0, dragMinHeight:38, dragMaxHeight:38})",250);
	});
}

function videoOverlayHelper(){
	/*$('#content').append('<div id="backgroundoverlay">&nbsp;</div>');
$('#backgroundoverlay').css({"height":$(document).height(),"width":$(document).width(),"opacity":0.5,"z-index":"1000000","top":0-$('#backgroundoverlay').offset().top,"left":0-$('#backgroundoverlay').offset().left,"position":"absolute"});*/

	$('#overlay').show();	
	
}

function friend(){
	$('#overlay').hide();
	$('#tipafriend').show();
}

function close_div(id){
	$('#'+id).hide();		
}

function send_friend(send){
	if (send != '1'){
		error = '';
		if ($('#von').val() == '')	error += "Sie haben keinen Namen eingegeben.\n";
		if ($('#email2').val() == '' || !check_email($('#email2').val())) error += "Ihre E-Mail Adresse ist falsch.\n";
		if ($('#an').val() == '') error += "Sie haben keinen Empfaenger eingegeben.\n";
		if ($('#email1').val() == '' || !check_email($('#email1').val())) error += "Sie haben eine falsche Empfaegner E-Mail Adresse eingegeben.\n";
	
		if ($('#nachricht').val() == '' ) error += "Sie haben keine Nachricht eingegeben\n";	
	
		if (error != ''){
			alert(error);
		}else{
			$('#tipafriendform').submit();
		}	
	} else {
		$('#tipafriendform').submit();		
	}
}

function check_email(address) {
  if ((address == "") || (address.indexOf ('@') == -1) || (address.indexOf ('.') == -1) || (address.indexOf ('+') > -1)) return false; else return true;
}

function popup(site){  
	b_width = 700;  
	b_height = 600;
	w_top = (screen.height/2) - (b_height/2);			
	w_left = (screen.width/2) - (b_width/2);
	window.open('http://www.volvic.de/bundesgeschmackswahl/fileadmin/templates/'+site+'.php','Volvic','width='+b_width+',height='+b_height+',status=no,scrollbars=yes,resizeable=0,top='+w_top+',left='+w_left);
	return false;
} 

function gotoHelper(type,sorte){
	if (type == 'frucht'){
		window.location.href = 'http://www.volvic.de/bundesgeschmackswahl/die-parteien-stellen-sich-vor/volvic-mit-fruchtgeschmack.html?visible=1&sorte='+sorte;
	}
	if (type == 'landfrucht'){
		window.location.href = 'http://www.volvic.de/bundesgeschmackswahl/die-parteien-stellen-sich-vor/volvic-mit-einem-spritzer-saft.html?visible=1&sorte='+sorte;
	}
	if (type == 'tee'){
		window.location.href = 'http://www.volvic.de/bundesgeschmackswahl/die-parteien-stellen-sich-vor/volvic-mit-auszuegen-von-tee.html?visible=1&sorte='+sorte;
	}
	
}

function sortieren(type){
	
		if (type == 'frucht'){
			$('.dotImg').attr("src","fileadmin/templates/_img/design/dot.gif");
			$('#fruchtDot').attr("src","fileadmin/templates/_img/design/dot_active.gif");
			$('#slider .youtubeThumbs').each(function(){
				$(this).hide();																					  
				if ( $(this).attr('rel').indexOf('frucht') > -1){
					$(this).show();	
				}
			});
			init();
		}
		
		if (type == 'saft'){
			$('.dotImg').attr("src","fileadmin/templates/_img/design/dot.gif");			
			$('#saftDot').attr("src","fileadmin/templates/_img/design/dot_active.gif");
			$('#slider .youtubeThumbs').each(function(){
				$(this).hide();																					  
				if ( $(this).attr('rel').indexOf('saft') > -1){
					$(this).show();	
				}
			});		
			init();			
		}
		
		if (type == 'tee'){
			$('.dotImg').attr("src","fileadmin/templates/_img/design/dot.gif");			
			$('#teeDot').attr("src","fileadmin/templates/_img/design/dot_active.gif");			
			$('#slider .youtubeThumbs').each(function(){
				$(this).hide();								
				if ( $(this).attr('rel').indexOf('tee') > -1){
					$(this).show();	
				}
			});	
			init();			
		}		
		
		if (type == 'alle'){
			$('.dotImg').attr("src","fileadmin/templates/_img/design/dot.gif");			
			$('#alleDot').attr("src","fileadmin/templates/_img/design/dot_active.gif");			
			$('#slider .youtubeThumbs').each(function(){			
				$(this).show();											
		  	});
			init();			
		}		
}
