backgrounds = new Array();
randomBanners = new Array();

// SHADOWBOX
Shadowbox.init({
	fadeDuration: 0.1,
	/*counterType: "skip",
	counterLimit: 10,*/
	slideshowDelay: 5,
	continuous: true,
	overlayOpacity: 0.8,
	overlayColor: "#000",
	troubleElements: ["object", "embed"],
	onOpen: function() { 
			if((navigator.userAgent.match(/iPhone/i))) { 
					$("#sb-container").css("top", $(window).scrollTop());
					$("#sb-overlay").height($("body").height());
					$(window).bind('scroll', function() { 
							$("#sb-container").css("top", $(window).scrollTop());
							
					}); 
			} 
	}, 
	onClose: function() { 
			if((navigator.userAgent.match(/iPhone/i))) { 
					$(window).unbind('scroll');
					$("div#site").css("visibility", "visible");
			} 
	} 
});

/* Toepassen aan body voor iPhone
	onload="setTimeout(function() { window.scrollTo(0, 1) }, 100);"
*/


$(function(){
	
	// Random background
	cHeader = "";
	if (backgrounds.length > 0 ) {
		randomHeader = Math.floor(Math.random() * backgrounds.length);
		cHeader = backgrounds[randomHeader];
	} else {
		cHeader = "/websites/implementatie/mediadepot/28477f066fb66.jpg"
	}
	$.backstretch(cHeader);
	
	// Random banner
	$(".partners").each(function() {
		if (randomBanners.length > 0 ) {
			randomPartner = Math.floor(Math.random() * randomBanners.length);
			cPartner = randomBanners[randomPartner];
			$(this).html("<div class=\"logo\"><table><tr><td>" + (cPartner[2] != "" ? "<a href=\"" + cPartner[2] + "\" target=\"_blank\">" : "") + "<img src=\"" + cPartner[0] + "\">" + (cPartner[2] != "" ? "</a>" : "") + "<figcaption>" + (cPartner[2] != "" ? "<a href=\"" + cPartner[2] + "\" target=\"_blank\">" : "") + cPartner[1] + (cPartner[2] != "" ? "</a>" : "") + "</figcaption></td></tr></table>");
		}
	});
	
	// Random image
	$(".randomImage").each(function() {
		randomImage = Math.floor(Math.random() * $(this).find("figure").length) + 1;
		$(this).find("figure:nth-child(" + randomImage + ")").show();
	});
	
	// Homepage - equal heights
	if ($("body#home.homepage").length > 0) {
		$content = $("div#content div.content article");
		
		$sidebarItem = $("#sidebar1 section:nth-child(1)").css("min-height", $content.height());
		$content.css("min-height", $sidebarItem.height()); 
		
		
		$("div#bottom section").each(function(index) {
			$block = $("#sidebar1 section:nth-child(" + (index + 2) + ")");
			$block.css("min-height", $(this).height());
			$(this).css("min-height", $block.height());
		});
		
	}

	$("div.collapse").each(function() {
		if (!$(this).next().next().hasClass("collapse")) {
			$(this).css({
				"margin-bottom": "20px"
			}).find("div.block").css({
				"margin-bottom": 0
			})
		}
	});

	$(".toggle_container").hide();

	$("span.trigger").click(function(){
		if ($(this).attr("active") == "true") {
			$(this).removeAttr("active");
			$(this).removeClass("active").next(".toggle_container").slideToggle("slow");
			//$(this).removeClass("active").next(".toggle_container").hide();
		} else {
			$("span.trigger").removeClass("active").removeAttr("active");	
			$(this).attr("active", "true");
			$(".toggle_container").slideUp();
			$(this).addClass("active").next(".toggle_container").slideToggle("slow");
			//$(this).next(".toggle_container").show();
		}
	});
	//$("span.trigger").eq(0).click();
});


/*SWITCHTEXT*/
function switchText(){
	if ($(this).val() == $(this).attr('title'))
		$(this).val('').removeClass('exampleText');
	else if ($.trim($(this).val()) == '')
		$(this).addClass('exampleText').val($(this).attr('title'));
	}

$(function() {
	//INPUTTITLE=TEXT
	$('input[type=text][title!=""]').each(function() {
		if ($.trim($(this).val()) == '') $(this).val($(this).attr('title'));
		if ($(this).val() == $(this).attr('title')) $(this).addClass('exampleText');
	}).focus(switchText).blur(switchText);

	$('form').submit(function() {
		$(this).find('input[type=text][title!=""]').each(function() {
			if ($(this).val() == $(this).attr('title')) $(this).val('');
		});
	});
});

// VIEWPORTS
$(function() {
	//if (navigator.userAgent.match(/iPhone/i)) { 
	if (screen.width <= 768) {
		$("head").append("<meta name=\"viewport\" content=\"width=480px\">");
	}
});

// MENU
$(function() {
	var deviceAgent = navigator.userAgent.toLowerCase();
	var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
	if (!agentID) {
		var config = {
			sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
			interval: 0,  // number = milliseconds for onMouseOver polling interval    
			over: doOpen,   // function = onMouseOver callback (REQUIRED)    
			timeout: 0,   // number = milliseconds delay before onMouseOut    
			out: doClose    // function = onMouseOut callback (REQUIRED)    
		};
		// $("ul.dropdown li").hoverIntent(config);
	} else {
			$("ul.dropdown li").hover(function(){
				$(this).addClass("hover");
				$('ul:first',this).css('visibility', 'visible');
			}, function(){
				$(this).removeClass("hover");
				$('ul:first',this).css('visibility', 'hidden');
			});
	}
	

	positionMenu();
	
});

$(window).resize(function() { positionMenu(); })
function positionMenu() {
	$("nav.standaard ul.dropdown > li").each(function(){
		if($(this).position().left > 520) {
			$(this).addClass("right");
		}
	});
}

function doOpen() {
	$(this).addClass("hover");
	if ($("body#feansjop").length <= 0) {
		$('ul:first',this).css('visibility', 'visible');
	}
}

function doClose() {
	$(this).removeClass("hover");
	if ($("body#feansjop").length <= 0) {
		$('ul:first',this).css('visibility', 'hidden');
	}
}

$(function(){
	
	$('.slideshow').each(function(index){
		var $pArr = $(this).find(" div.slideImg");
		var pArrLen = $pArr.length;
		var pPerDiv = 4;
		for (var i = 0; i < pArrLen; i += pPerDiv){
			$pArr.filter(':eq('+i+'),:lt('+(i+pPerDiv)+'):gt('+i+')').wrapAll('<div class=\"slide\">');
		}
		
		$cycle = $(this).parent(".cycle");
		/*$cycle.find(".page").addClass("page" + index);*/
		$cycle.find(".next").addClass("next" + index);
		$cycle.find(".prev").addClass("prev" + index);
		$(this).cycle({ 
			fx:     'scrollHorz', 
			speed:   900, 
			timeout: 0, 
			easeIn:  'easeOutExpo', 
			easeOut: 'easeOutExpo', 
			/*pager:  '.page' + index,*/
			next:	'.next' + index,
			prev:   '.prev' + index
		});
	});





	$('body#splash div.slides').each(function(index){
		$cycle = $(this).parent(".cycle");
		$cycle.find("#nav").addClass("page" + index);
		$(this).cycle({ 
			fx:     'fade', 
			speed:  '400', 
			timeout: 6000,
			pager:  '.page' + index
		});
	});

	// SPLASH
/*	$('body#splash div.slides') 
		.before('<div id="nav">') 
		.cycle({ 
			fx:     'fade', 
			speed:  '400', 
			timeout: 6000,
			pager:  '#nav'
		});*/

	$('body#splash div.splashThumb').cycle({ 
			fx:     'fade', 
			speed:  '400', 
			timeout: 6000
		});

	// FEANSJOP SPLASH
	$('body#feansjop.FSsplash div.slides').each(function(index){
		$cycle = $(this).parent(".cycle");
		$cycle.find("#nav").addClass("page" + index);
		$(this).cycle({ 
			fx:     'fade', 
			speed:  '400', 
			timeout: 6000,
			pager:  '.page' + index
		});
	});
	
/*	$('body#feansjop.FSsplash div.slides') 
		.before('<div id="nav">') 
		.cycle({ 
			fx:     'fade', 
			speed:  '400', 
			timeout: 6000,
			pager:  '#nav'
		});*/

	// REMOVE MARGIN BIJ OPEENVOLGENDE AFBEELDINGEN
	$("figure.left, figure.right").each(function() {
		if ($(this).next("figure.left, figure.right").length >= 1) {
			if (!$(this).hasClass("noMargin")) {
				$(this).next().addClass("noMargin");
			}
		}
	});

	// PRINT PAGINA'S
	$("input[value*=print], [value*=Print], input[value*=afdruk], input[value*=Afdruk]").click(function() {
		window.print();
		return false;
	});

	// VERBERG SLIDESHOW WANNEER LEEG (OOK IN IE7)
	if ($('div#slideshow').is(':empty')) {
		$("div#slideshow").css("display", "none");
	}

	// VERBERG FEANSJOP SUBMENU WANNEER LEEG
	if($("body#feansjop aside div#FSsubmenu ul li").length < 1){
		$("body#feansjop aside div#FSsubmenu").css("display", "none");
	}
	$("#feansjop nav ul.dropdown li").each(function() {
		$(this).find(".FSsub div").each(function() {
			if ($(this).find("ul").length <= 0) {
				$(this).remove();
			};
		});
	});
	$("#feansjop ul.sub_menu").each(function() {
		$(this).width($(this).find(">li").width() + 10);
		if ($(this).width() < 480) {
			$(this).css({"left": 0});
		} else {
			$(this).css({"left": -140});
		}
	});
	
	// LOADER BIJ VERVERSEN VARIATIES
	$("#feansjop .variation select").change(function() {
		$("#wrapper").css({"opacity": "0.4"})
		$("#fsLoad").show();
	});

	// AANTAL VERVERSEN IN FEANSJOP
	$("#feansjop a.updateProduct").click(function() {
		$input = $(this).closest("td").find("input");
		link = $(this).attr("href").replace("{}", $input.val());
		document.location = link;
		return false;
	});

	// AKKOORD MET DE BESTELLING
	$("input#akkoord").closest("form").submit(function() {
		if ($(this).find("#akkoord:checked").length > 0) {
			return true;
		} else {
			$("<div title='Bestelling controleren'>Controleer je bestelling goed. Als alle gegevens correct zijn ingevuld selecteer je 'Ik ga akkoord met de bestelling' alvorens de  bestelling af te ronden</div>").dialog({
				resizable: false,
				height: 180,
				modal: true,
				buttons: {
					"OK": function() {
						$(this).dialog( "close" );
					}
				}
			});
			return false;
		}
	});

	// SHIRT TONEN (EIGEN NAAM EN RUGNUMMER)
	$("#customToggle").click(function() {
		showCustomShirt();
	});
	$("#CZthumbs a:not(:last)").click(function() {
		$("#customNumberView, #customNameView").hide();
	});
	$("#CZthumbs a:last").click(function() {
		$("#customNumberView, #customNameView").show();
	});
	$("#customName, #customNumber").bind("keydown keyup click change paste", function() {
		$("#customName").val($("#customName").val().replace(/[^a-z ]/gi, '').toUpperCase());
		$("#customNumber").val($("#customNumber").val().replace(/[^0-9]/gi, ''));
		$("#customNameView").html($("#customName").val());
		$("#customNumberView").html($("#customNumber").val());

		// Prijzen bijwerken
		var prijs = parseFloat($("#prijs").data("baseprice"));
		prijs += $("#customName").val().length * parseFloat($("#customName").data("extraprice"));
		prijs += $("#customNumber").val().length * parseFloat($("#customNumber").data("extraprice"));
		
		$("#prijs").html(prijs.toFixed(2).replace(".", ",").replace(",00", ",-"));

	});



	// VERBERG SIDEBAR (IN IE7 VERSCHIJNT LEEGRUIMTE)
	if ($('body#template1 aside#sidebar').is(':empty')) {
		$("body#template1 aside#sidebar").css("display", "none");
	}

	// TEL AANTAL LI IN HOOFDMENU
	$('ul.dropdown li.vertical ul').addClass(function () {
		return 'menu-' + $(this).children('li').size();
	});

	// CLEAR CTA'S
	$("a.cta").each(function(){
		$(this).before("<div class=\"clear\"></div>");
		$(this).after("<div class=\"clear\"></div>");
	});

	//TABLEROW KLIKBAAR (SELECTIE)
	$('article .selectie tr, table.programma tr, table.news tr, table.ticketing tr').click(function() {
		var href = $(this).find("a").attr("href");
		if(href) {
			window.location = href;
			}
		});

	//OPEN LINKS IN NEW VENSTER
	$('div#FSwinkelwagen a.empty').click( function() {
		return false;
	});

	//OPEN LINKS NIET
	$('div#businessPartners a, div#hoofdsponsor a, div#suppliers:not(.kids) a').click( function() {
		window.open(this.href);
		return false;
	});

	//DATEPICKER
	$(".datepicker").datepicker({
		dateFormat: 'dd-mm-yy',
		firstDay: 1,
		nextText: 'volgende',
		prevText: 'vorige',
		dayNames: ['Zondag', 'Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag'],
		dayNamesShort: ['Zon', 'Maa', 'Din', 'Woe', 'Don', 'Vrij', 'Zat'],
		dayNamesMin: ['Zo', 'Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za'],
		monthNames: ['Januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','November','December'],
		monthNamesShort: ['Jan','Feb','Maa','Apr','Mei','Jun','Jul','Aug','Sep','Okt','Nov','Dec']
	});

	// TABS 
	var disabledTabs = new Array();
	$("#wedstrijdTabs li").each(function(index) {
		if ($(this).hasClass("disabled")) {
			disabledTabs.push(index);
		}
	});
	$("#wedstrijdTabs").tabs({ 
		selected: $("#wedstrijdTabs ul li:not(.disabled):last").index(),
		disabled: disabledTabs
	});
	$("div.tabs").tabs();

	// BREADCRUMBS / LAATSTE ITEM NIET KLIKBAAR MAKEN
	$(function() {
		$("#breadcrumb span:last").find("a").each(function() {
			$(this).replaceWith($(this).html());
		});
		
		$("#feansjop #breadcrumb .home").hide();
	});

	// SELECTIE
	$("div.spelersportret a.speler").click(function() {return false;});

	// KIKAMETER 
	$("#kikaMeter div.bedrag").appendTo($("#kikaMeter div.bedrag").closest(".bar").parent());
	
	
	// CLOUD ZOOM
	$('.cloud-zoom, .cloud-zoom-gallery').CloudZoom();

});


// EIGEN NAAM EN RUGNUMMER FEANSJOP
function showCustomShirt() {
	$("#custom").slideDown();
	$("#CZthumbs a:last").trigger("click");
	$("#customNumberView, #customNameView").show();
	$("#customName").trigger("click");
}

function hideCustomShirt() {
	$("#custom").slideUp();
	$("#customNumberView, #customNameView").hide();
}

// OPSTELLING GOED UITLIJNEN
$(function() {
	$("div.opstelling").each(function() {
		$(this).find("div.keeper").addClass("linie_" + $(this).find("div.keeper").length);
		$(this).find("div.verdediger").addClass("linie_" + $(this).find("div.verdediger").length);
		$(this).find("div.middenvelder").addClass("linie_" + $(this).find("div.middenvelder").length);
		$(this).find("div.aanvaller").addClass("linie_" + $(this).find("div.aanvaller").length);
	});

	$("div.opstelling div.speler").hover(function() {
		$(this).closest("div.opstelling").find("div.speler[data-id!='" + $(this).attr("data-id") + "']").removeClass("hover");
		$(this).closest(".opstellingWrapper").find("tr[data-id!='" + $(this).attr("data-id") + "']").removeClass("hover");
		$(this).closest(".opstellingWrapper").find("tr[data-id='" + $(this).attr("data-id") + "']").addClass("hover");
		$(this).addClass("hover");
	}, function() {
	});

	$("div.opstellingWrapper table.opstelling tr").hover(function() {
		$(this).closest("div.opstellingWrapper").find("div.opstelling div.speler[data-id!='" + $(this).attr("data-id") + "']").removeClass("hover");
		$(this).closest("table.opstelling").find("tr[data-id!='" + $(this).attr("data-id") + "']").removeClass("hover");
		$(this).addClass("hover");
		$(this).closest("div.opstellingWrapper").find("div.opstelling div.speler[data-id='" + $(this).attr("data-id") + "']").addClass("hover");
	}, function() {
	});

	// Tabs tonen
	$("div.opstellingTab").tabs({
		selected: $("ul.schUit").length >= 1 ? 1 : 0
	});

	// Opstelling klikbaar
	$(".opstellingWrapper.schThuis.uit, .opstellingWrapper.schUit.thuis").find("a").click(function() {
		return false;
	});
	$(".opstellingWrapper.schThuis.thuis div.speler, .opstellingWrapper.schUit.uit div.speler").click(function() {
		document.location = $(this).find("a").attr("href");
	});

});

// MINMIALE HOOGTE CONTENT + SIDEBAR
if (screen.width > 480) {
	$(window).load(function() {
		$("#home #content").css({"min-height": $("#sidebar2").height()})
	});
}

