$(window).load(function(){
	pagina_instellen();	
});

var fotoheader_huidige_slide;
var fotoheader_aantal_slides;
var fotoalbum_huidige_slide;
var fotoalbum_aantal_slides;

$(document).ready(function(){		
	pagina_instellen();

	//Zoekpagina inputbox invulling + Routeplanner
	//INIT
	if(($("#zoekwoord_input").attr("value")=="")||($("#zoekwoord_input").attr("value")=="Ik zoek een...")){
		$("#zoekwoord_input").attr("value", "Ik zoek een...");$("#zoekwoord_input").css("color", "#787878");
	}
	if(($("#route_straat_input").attr("value")=="")||($("#route_straat_input").attr("value")=="straat")){
		$("#route_straat_input").attr("value", "straat");$("#route_straat_input").css("color", "#787878");
	}
	if(($("#route_plaats_input").attr("value")=="")||($("#route_plaats_input").attr("value")=="plaatsnaam")){
		$("#route_plaats_input").attr("value", "plaatsnaam");$("#route_plaats_input").css("color", "#787878");
	}
	if(($("#form_nieuwsbrief_naam").attr("value")=="")||($("#form_nieuwsbrief_naam").attr("value")=="Naam")){
		$("#form_nieuwsbrief_naam").attr("value", "Naam");$("#form_nieuwsbrief_naam").css("color", "#787878");
	}
	if(($("#form_nieuwsbrief_emailadres").attr("value")=="")||($("#form_nieuwsbrief_emailadres").attr("value")=="E-mailadres")){
		$("#form_nieuwsbrief_emailadres").attr("value", "E-mailadres");$("#form_nieuwsbrief_emailadres").css("color", "#787878");
	}
	
	//WERKING
	$("#zoekwoord_input").focus(function(){
		if($("#zoekwoord_input").attr("value")=="Ik zoek een..."){
			$("#zoekwoord_input").attr("value", "");$("#zoekwoord_input").css("color", "#000");
		}
	}).focusout(function(){
		if($("#zoekwoord_input").attr("value")==""){
			$("#zoekwoord_input").attr("value", "Ik zoek een...");$("#zoekwoord_input").css("color", "#787878");
		}
	});
	$("#route_straat_input").focus(function(){
		if($("#route_straat_input").attr("value")=="straat"){
			$("#route_straat_input").attr("value", "");$("#route_straat_input").css("color", "#000");
		}
	}).focusout(function(){
		if($("#route_straat_input").attr("value")==""){
			$("#route_straat_input").attr("value", "straat");$("#route_straat_input").css("color", "#787878");
		}
	});
	$("#route_plaats_input").focus(function(){
		if($("#route_plaats_input").attr("value")=="plaatsnaam"){
			$("#route_plaats_input").attr("value", "");$("#route_plaats_input").css("color", "#000");
		}
	}).focusout(function(){
		if($("#route_plaats_input").attr("value")==""){
			$("#route_plaats_input").attr("value", "plaatsnaam");$("#route_plaats_input").css("color", "#787878");
		}
	});
	$("#form_nieuwsbrief_naam").focus(function(){
		if($("#form_nieuwsbrief_naam").attr("value")=="Naam"){
			$("#form_nieuwsbrief_naam").attr("value", "");$("#form_nieuwsbrief_naam").css("color", "#000");
		}
	}).focusout(function(){
		if($("#form_nieuwsbrief_naam").attr("value")==""){
			$("#form_nieuwsbrief_naam").attr("value", "Naam");$("#form_nieuwsbrief_naam").css("color", "#787878");
		}
	});
	$("#form_nieuwsbrief_emailadres").focus(function(){
		if($("#form_nieuwsbrief_emailadres").attr("value")=="E-mailadres"){
			$("#form_nieuwsbrief_emailadres").attr("value", "");$("#form_nieuwsbrief_emailadres").css("color", "#000");
		}
	}).focusout(function(){
		if($("#form_nieuwsbrief_emailadres").attr("value")==""){
			$("#form_nieuwsbrief_emailadres").attr("value", "E-mailadres");$("#form_nieuwsbrief_emailadres").css("color", "#787878");
		}
	});
	
	/* Custom selectbox entertainerspagina */
	$("#custom_selectbox").customStyle();
	$("#custom_selectbox").change(function() {
		this.form.submit();
	});	
	
	//Tabs bij de artiesten detailpagina's
	$(".tabbladen").tabs();	
	
	//Koppelingen via gehele blokken
	$("#content_header .artiestenblok .slide").click(function(){ window.location=$("#basepath").attr("value")+$(this).attr("rel"); });
	$("#home_container .nieuws").click(function(){ window.location=$("#basepath").attr("value")+$(this).attr("rel"); });
	$("#home_container .spotlight .item").click(function(){ if($(this).attr("rel")!=""){ window.location=$("#basepath").attr("value")+$(this).attr("rel"); } });
	$("#nieuwspagina_container .overzicht .item").click(function(){ window.location=$("#basepath").attr("value")+$(this).attr("rel"); });
	$("#artiestenpagina_container .overzicht .item").click(function(){ window.location=$("#basepath").attr("value")+$(this).attr("rel"); });
	$("#artiestenpagina_container .random_overzicht .item").click(function(){ window.location=$("#basepath").attr("value")+$(this).attr("rel"); });
	$("#zoeken_container .kolom_zoekresultaten .item").click(function(){ window.location=$("#basepath").attr("value")+$(this).attr("rel"); });
	$("#fotoalbums_container .albums .item").click(function(){ window.location=$("#basepath").attr("value")+$(this).attr("rel"); });
	$("#events_container .item").click(function(){ window.location=$("#basepath").attr("value")+$(this).attr("rel"); });
	$("#wiezijnwij_container .item").click(function(){ window.location=$("#basepath").attr("value")+$(this).attr("rel"); });
	$("#zijkant_kolom .event").click(function(){ window.location=$("#basepath").attr("value")+$(this).attr("rel"); });
	$("#zijkant_kolom .wiezijnwij").click(function(){ window.location=$("#basepath").attr("value")+$(this).attr("rel"); });
	
	//Werking van de faders op de event en wie zijn wij pagina's
	$('#events_container .item .afbeelding, #wiezijnwij_container .item .afbeelding').innerfade({
		speed: 800,
		timeout: 4000,
		type: 'sequence',
		containerheight: '118'
	});
	$('#events_container .detail .afbeelding, #wiezijnwij_container .detail .afbeelding').innerfade({
		speed: 800,
		timeout: 4000,
		type: 'sequence',
		containerheight: '244'
	});
	$('#normaal_container .afbeelding').innerfade({
		speed: 800,
		timeout: 4000,
		type: 'sequence',
		containerheight: '244'
	});
	
	//Werking van de fotoheader
	//Inits
	fotoheader_huidige_slide=1;
	fotoheader_aantal_slides=$("input#hidden_aantal_headers").attr("value");
	//Automatische roulatie
	if(fotoheader_aantal_slides>1){	start_header_fotoslider(); }
	$("#content_header .fotobalk").mouseover(function() {
		if(fotoheader_aantal_slides>1){	stop_header_fotoslider(); }
	}).mouseout(function(){
		if(fotoheader_aantal_slides>1){	start_header_fotoslider(); }
	});
	//Handmatige slide (klik op een navigatienummer)
	$("#content_header .fotobalk .navigatie a").click(function(event){
		event.preventDefault();
		beweeg_fotoheader_naar_slide($(this).attr("rel"));
	});
	//Werking van de artiestenheader
	$('.artiestenblok .artiestenslider').innerfade({
		speed: 800,
		timeout: 8000,
		type: 'sequence',
		containerheight: '230'
	});
	//Werking van de spotlight items
	$('.spotlight').innerfade({
		speed: 800,
		timeout: 8000,
		type: 'sequence',
		containerheight: '133'
	});
	//Werking van de artiestenfoto's
	$('#artiestenpagina_container .entertainer_detail .media .artiest_slideshow').innerfade({
		speed: 800,
		timeout: 4000,
		type: 'sequence',
		containerheight: '180'
	});
	
	//Werking van de fotoalbumviewer
	//Inits
	fotoalbum_huidige_slide=1;
	fotoalbum_aantal_slides=$("input#aantal_slides_fotoalbum").attr("value");
	//Instellen van de navigatie
	$("#fotoalbums_container .fotoviewer .beschrijving").html($("#fotoalbums_container .fotoviewer .slider .slide:eq(0)").attr("rel"));
	$(".fotoviewer .navigator a.vorige").css("visibility","hidden");
	if(fotoalbum_aantal_slides<2){ $(".fotoviewer .navigator a.volgende").css("visibility","hidden"); }
	//Handmatige slide (klik op een navigatie)
	$(".fotoviewer .navigator a.vorige").click(function(event){
		event.preventDefault();
		beweeg_fotoalbum_naar_slide(fotoalbum_huidige_slide-1);
	});
	$(".fotoviewer .navigator a.volgende").click(function(event){
		event.preventDefault();
		beweeg_fotoalbum_naar_slide(fotoalbum_huidige_slide+1);
	});
	
	
	//Werking submenu
	$("#menu>ul>li").mouseover(function() {				
		//breedte menu instellen
		var breedte_ul=0;
		$(this).find("ul").css("display","block");
		$(".splitser", this).each(function(){
			breedte_ul+=$(this).outerWidth();
		});
		$(this).find("ul").css("width",breedte_ul+"px");
			
	}).mouseout(function(){
		$(this).find("ul").css("display","none");
	});
	
	
	//Werking van printen (meerdere pagina's)
	$("a.printen").click(function(event){
		event.preventDefault();
		window.print();
	});
	
	//Werking van de boekingen
	$("a.artiest_boeken, a.boeken").fancybox({
		'width' : 550,
		'height' : 1300,
		'overlayShow' : true,
		'overlayOpacity' : 0.3,
		'overlayColor' : '#494949',
		'hideOnOverlayClick' : false,
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic',
		'showNavArrows' : false,
		'speedIn' : 200, 
		'speedOut' : 200, 
		'type' : 'iframe',
		'padding' : 25
	});	
	
	
	//Werking van de boekingen
	$("a.mailen").fancybox({
		'width' : 550,
		'height' : 450,
		'overlayShow' : true,
		'overlayOpacity' : 0.3,
		'overlayColor' : '#494949',
		'hideOnOverlayClick' : false,
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic',
		'speedIn' : 200, 
		'speedOut' : 200, 
		'type' : 'iframe',
		'padding' : 25
	});
	
	//Werking van de slider van waarderingen op de Referenties pagina
	//Halveren van de hoogte van de slider_container, omdat er 2 keer hetzelfde in zit (met een maximum van 5 hoog)
	
	//Berekening bij het verschuiven en variabelen die daarvoor nodig zijn
	var maximum_slides_hoogte_waarderingen=5;
	var huidige_slide=1;
	var aantal_slides=Number($("#aantal_waarderingen").attr("value"));
	var hoogte_slider=$("#referenties_container .kolom2 .slider_container").outerHeight();
	if(aantal_slides>maximum_slides_hoogte_waarderingen){ deler=maximum_slides_hoogte_waarderingen } else { deler=aantal_slides; }
	stel_nieuwe_hoogte_in_voor_slider_waarderingen(huidige_slide,deler);
	//Werking van de navigatie
	$("a.navigatie_vorige_waardering").click(function(ev){
		ev.preventDefault();
		huidige_slide--;
		//Terug gaan in de slide, als de eerste teruggaat dan eerst vervangen door direct naar de 5de te gaan (direct) en dan omhoog te sliden
		if(huidige_slide==0){
			$("#referenties_container .kolom2 .slider_container .slider").css("margin-top",geef_afstandsverschil_aan_vanaf_boven_slider_waarderingen(aantal_slides+1)+"px");
			huidige_slide=aantal_slides;
			$("#referenties_container .kolom2 .slider_container .slider").animate({marginTop:geef_afstandsverschil_aan_vanaf_boven_slider_waarderingen(huidige_slide)+"px"},{queue:false,duration:350,easing:'easeInOutExpo'});
		} else {
			$("#referenties_container .kolom2 .slider_container .slider").animate({marginTop:geef_afstandsverschil_aan_vanaf_boven_slider_waarderingen(huidige_slide)+"px"},{queue:false,duration:350,easing:'easeInOutExpo'});
		}
		stel_nieuwe_hoogte_in_voor_slider_waarderingen(huidige_slide,deler);
	});
	
	$("a.navigatie_volgende_waardering").click(function(ev){
		ev.preventDefault();
		huidige_slide++;
		//Vooruit gaan in de slide, als de laatste vooruit gaan dan direct door naar de 1set en dan pas omlaag sliden
		if(huidige_slide==(aantal_slides+1)){	
			huidige_slide=1;
			$("#referenties_container .kolom2 .slider_container .slider").animate({marginTop:geef_afstandsverschil_aan_vanaf_boven_slider_waarderingen(aantal_slides+1)+"px"},{queue:false,duration:350,easing:'easeInOutExpo',complete:function(){				
				$("#referenties_container .kolom2 .slider_container .slider").css("margin-top","0px");
			}});						
		} else {
			$("#referenties_container .kolom2 .slider_container .slider").animate({marginTop:geef_afstandsverschil_aan_vanaf_boven_slider_waarderingen(huidige_slide)+"px"},{queue:false,duration:350,easing:'easeInOutExpo'});
		}
		stel_nieuwe_hoogte_in_voor_slider_waarderingen(huidige_slide,deler);
	});
	
});

function geef_afstandsverschil_aan_vanaf_boven_slider_waarderingen(huidige_slider){
	hoogte=0;		
	for(i=(huidige_slider-1);i>0;i--){ 
		//Hoogte +20 aan margin van elke blok aan de onderzijde
		hoogte+=($("#referenties_container .kolom2 .slider_container .waarderingen[rel='"+(i)+"']").height()+20);	
	}
	return "-"+hoogte;
}

function stel_nieuwe_hoogte_in_voor_slider_waarderingen(huidige_slide,deler){
	nieuwe_hoogte=0;
	for(i=0;i<deler;i++){ 
		//Hoogte +20 aan margin van elke blok aan de onderzijde
		nieuwe_hoogte+=($("#referenties_container .kolom2 .slider_container .waarderingen[rel='"+(huidige_slide+i)+"']").height()+20);
	}
	$("#referenties_container .kolom2 .slider_container").css("height",nieuwe_hoogte+"px");
}

function start_header_fotoslider(){
	header_fotoslider=setInterval(function(){
		if(fotoheader_huidige_slide==fotoheader_aantal_slides){ fotoheader_huidige_slide=1; } else { fotoheader_huidige_slide++; }
		beweeg_fotoheader_naar_slide(fotoheader_huidige_slide);		
	},8000);
}

function stop_header_fotoslider(){
	window.clearInterval(header_fotoslider);
}

function beweeg_fotoheader_naar_slide(slide){
	//Alle actieve buttons uitschakelen
	$("#content_header .fotobalk .navigatie a").removeClass("actief");
	$("#content_header .fotobalk .navigatie a[rel=\""+slide+"\"]").addClass("actief");
	$("#content_header .fotobalk .fotoslider").animate({marginLeft:-(695*(slide-1))+"px"},{queue:false,duration:900,easing:'easeInOutExpo'});
	$("#content_header .fotobalk .info").animate({bottom:-500},{queue:false,duration:200,easing:'easeInOutExpo',complete:function(){
			$("#content_header .fotobalk .info").animate({bottom:500},{queue:false,duration:0,easing:'easeInOutExpo'});
			//Omzetten van de link en de tekst
			$("#content_header .fotobalk .info h3").html($("#content_header .fotobalk .fotoslider img[rel=\""+slide+"\"]").attr("data-titel"));
			//Link tonen als deze er is
			if($("#content_header .fotobalk .fotoslider img[rel=\""+slide+"\"]").attr("data-url")!=""){
				$("#content_header .fotobalk .info a").css("display","block");
				$("#content_header .fotobalk .info a").attr("href",$("#content_header .fotobalk .fotoslider img[rel=\""+slide+"\"]").attr("data-url"))
			} else {
				$("#content_header .fotobalk .info a").css("display","none");
			}
			$("#content_header .fotobalk .info").animate({bottom:10},{queue:false,duration:800,easing:'easeInOutExpo'});
		}
	});
	//Aanpassen van de huidige slider	
	fotoheader_huidige_slide=slide; 	
}

function beweeg_fotoalbum_naar_slide(slide){
	$("#fotoalbums_container .fotoviewer .slider").animate({marginLeft:-(785*(slide-1))+"px"},{queue:false,duration:300,easing:'easeInOutExpo'});
	if(slide==fotoalbum_aantal_slides){ $(".fotoviewer .navigator a.volgende").css("visibility","hidden"); } else { $(".fotoviewer .navigator a.volgende").css("visibility","visible"); }
	if(slide==1){ $(".fotoviewer .navigator a.vorige").css("visibility","hidden"); } else { $(".fotoviewer .navigator a.vorige").css("visibility","visible"); }
	//Titel van de afbeelding tonen
	$("#fotoalbums_container .fotoviewer .beschrijving").html($("#fotoalbums_container .fotoviewer .slider .slide:eq("+(slide-1)+")").attr("rel"));
	fotoalbum_huidige_slide=slide; 	
}

function pagina_instellen(override){
	//Even hoog maken van de verschillende footerblokken
	var hoogte=0;
	$("#footer .blok").each(function(){
		if(hoogte<$(this).outerHeight()){
			hoogte=$(this).outerHeight();
		}
	});
	$("#footer .blok").each(function(){
		$(this).css("height",hoogte);
	});
	//Even hoog maken van de verschillende blokken bij het team
	var hoogte=0;
	$("#team_container .item").each(function(){
		if(hoogte<$(this).outerHeight()){
			hoogte=$(this).outerHeight();
		}
	});
	$("#team_container .item").each(function(){
		$(this).css("height",hoogte);
	});
	//Even hoog maken van de verschillende blokken bij de links
	var hoogte=0;
	$("#links_container .item").each(function(){
		if(hoogte<$(this).outerHeight()){
			hoogte=$(this).outerHeight();
		}
	});
	$("#links_container .item").each(function(){
		$(this).css("height",hoogte);
	});
	//Even hoog maken van de verschillende blokken bij de nieuws
	var hoogte=0;
	$("#nieuwspagina_container .overzicht .item").each(function(){
		if(hoogte<($(this).outerHeight()-50)){
			hoogte=($(this).outerHeight()-50);
		}
	});
	$("#nieuwspagina_container .overzicht .item").each(function(){
		$(this).css("height",hoogte);
	});
	//Even hoog maken van de verschillende blokken bij de nieuws
	var hoogte=0;
	$("#nieuwsarchiefpagina_container .overzicht .item").each(function(){
		if(hoogte<($(this).outerHeight()-50)){
			hoogte=($(this).outerHeight()-50);
		}
	});
	$("#nieuwsarchiefpagina_container .overzicht .item").each(function(){
		$(this).css("height",hoogte);
	});
}

