// JavaScript Document
$(document).ready(function() {

	menuHovers(); // Hoverstate voor alle menu-items
	alternateBgColor(); // Wissellende achtergrondkleuren voor blokken
	iframeHeight(); // Iframehoogte automatisch aanpassen
	linkTargets(); // Links openen in de juiste vensters
	//countdownTimer(); // Aftel script voor op homepage
	
	$.preloadCssImages(); // Css images preloaden
	
});

function menuHovers() {
	var imgExtension = ".gif"; // Image extenstie
	var imgHoverName = "_active"; // Naam van hoverstate
	
	$(".menu li").find("img").each(function(i) {
		if(!$(this).attr("src").match("_active")) {
			var imgLocation = $(this).attr("src").match(imgHoverName) ?
				$(this).attr("src").split(imgHoverName)[0] :
				$(this).attr("src").split(imgExtension)[0];
							
			$(this).hover(function() {
				$(this).attr("src",imgLocation + imgHoverName + imgExtension);
			}, function() {
				$(this).attr("src",imgLocation + imgExtension);
			});
		}
	});
}

function iframeHeight() {
	$("iframe").load(function() {
		this.style.height = this.contentWindow.document.body.offsetHeight + "px";
    });
}

function countdownTimer() {
	var d = new Date();
	var intCurrentDate = (d.getFullYear()*100 + d.getMonth()+1)*100 + d.getDate();
	var intCountdownDate = 20080912;
	var strHeader = "Tijdelijk";
	var strContent = "Tijdelijk";
		
	if(intCurrentDate < intCountdownDate) {
		strHeader = "Nog " + (intCountdownDate - intCurrentDate) + " dagen...";
		strContent = "Tot de bekendmaking van de genomineerden op<br />12 september";
	} else if(intCurrentDate < intCountdownDate) {
		strHeader = "Nog " + (intCountdownDate - intCurrentDate) + " dagen...";
		strContent = "Tot de bekendmaking van de genomineerden op<br />12 september";
	} else if(intCurrentDate == intCountdownDate) {
		strHeader = "Het is zover";
		strContent = "Lorem ipsum";
	} else if(intCurrentDate > intCountdownDate) {
		strHeader = "Een week na tijd";
		strContent = "Lorem ipsum";
	}
	
	$("h2.countdown").text(strHeader);
	$("p.countdown").html(strContent);
}

function alternateBgColor() {
	$("#page .lightpurple, #page .lightorange").each(function(index) {
		if (index % 2 == 1) {
			$(this).addClass("alt");
		}
	});
}

function linkTargets() {
	$("a[@href^=\"http://\"]").each(function () {
		$(this).attr({
			//target: "_blank",
			href: "javascript:window.open('" + $(this).attr("href") + "');void(0);", 
			title: "Link opent in een nieuw venster"
		});
	});
	
	$("a[rel=\"parent\"]").each(function () {
		$(this).click(function() {
			parent.location.href = $(this).attr("href");
		});
	});
}