// Cufon
$(function() {
	Cufon.replace("h1, h2, div.productOverlay, #items .title, #items ul li, #items .item .contact, #items .item a.button, #tagcloud, #header #payoff", 
	{hover: true});
});

// Menu
$(function() {

	// Voeg de klasse 'hasSubmenu' toe aan alle LI-items die een submenu hebben
	$("#mainMenu .submenu").parent("li").addClass("hasSubmenu")
		// Voeg een hover-effect toe aan deze elementen
	/*
		.hoverIntent({
			over: function() {
				$(this).addClass("active");
				$(this).find(".submenu").slideDown("fast");
			}, 
			out: function() {
				$(this).removeClass("active");
				$(this).find(".submenu").hide();
			},
			timeout: 25,
			sensitivity: 12
		});
	*/
	.hover(function() {
		$(this).addClass("active");
		$(this).find(".submenu").show();
	}, function() {
		$(this).removeClass("active");
		$(this).find(".submenu").hide();
	});


	// Sitemenu: PWR pack selecteren
	$("#menu_344").parent().addClass("active");
});

// productImage
$(function() {
	// Voor en na een overzicht van productImages een lege div toevoegen
	$("<div></div>").insertAfter("div.productImage:last").addClass("clear");
	$("<div></div>").insertBefore("div.productImage:first").addClass("clear");

	// onClick toevoegen voor de overlay
	$(".productImage").each(function() {
		$link = $(this).find("a");
		$(this).find(".productOverlay").attr("href", $link.attr("href"));
		if ($link.length > 0) {
			$(this).find(".productOverlay").click(function() {
				document.location = $(this).attr("href");
			}).css({"cursor": "pointer"});
		}
	});
});

// productIcons
$(function() {
	// Voor en na een overzicht van productImages een lege div toevoegen
	$("<div></div>").insertAfter("div.productIcon:last").addClass("clear");
	$("<div></div>").insertBefore("div.productIcon:first").addClass("clear");

	// onClick toevoegen voor de overlay
	$(".productIcon").each(function() {
		$link = $(this).find("a");
		$(this).attr("href", $link.attr("href"));
		if ($link.length > 0) {
			$(this).click(function() {
				document.location = $(this).attr("href");
			}).css({"cursor": "pointer"});
		}
	});
});

//defaultValue
$(function() {
	$("#searchField").defaultValue();
});

// product tabel
$(function() {
	$(".tableLink").parents("tr").click(function() {
		document.location = $(this).find(".tableLink").attr("href");
	}).css({"cursor": "pointer"});
});

// jCarousel 
$(function() {
	$("#slider").jcarousel({
		auto: 0,
		wrap: "last"
	});
});

// Shadowbox 
	Shadowbox.init({
		players:    ["flv", "iframe"]
	});


	function playVideo(pURL) {
		Shadowbox.open({
			content:    pURL,
			player:     "flv",
			title:      "",
			height:     585,
			width:      730
		});
	}

	function sendVideo(pURL) {
		var url = pURL.substr(pURL.lastIndexOf("/")).replace("/md", "").replace(".flv", "");
		Shadowbox.open({
			content:    $.actual.serverpad + "pageid=380/lang="+$.actual.language+"/video=" + url + "/video.html",
			player:     "iframe",
			title:      "",
			height:     448,
			width:      592
		});
	}

// Form check

	// Bepaal de stijl van de custom alerts
	$(function() {
		$.alerts.overlayOpacity = 0.75;
		$.alerts.overlayColor = "#000000";
	});

	// De functie validField controleert of een bepaald veld correct is ingevuld
	function validField(field) {
			// Wanneer het veld leeg is, maak dit dan visueel
			if (field.value == "") {
					// Geef bijvoorbeeld een andere randkleur aan het element.
					//  Andere opties zijn een andere tektkleur, teksten bold maken etc.
					$(field).addClass("invalid");
					return false;
			} else {
					// Wanneer het veld wel correct is ingevuld, zet dan de standaard stijlen weer terug
					$(field).removeClass("invalid");
					return true;
			}
	}

	function checkVideoForm(lang) {
		var bValid = true;

		if (!validField(document.getElementById("pwrUwNaam")))			{ bValid = false; }
		if (!validField(document.getElementById("pwrUwEmailadres")))	{ bValid = false; }
		if (!validField(document.getElementById("pwrOntvNaam")))		{ bValid = false; }
		if (!validField(document.getElementById("pwrOntvEmailadres")))	{ bValid = false; }

		// Als alle verplichte velden correct zijn ingevuld, geef dan als resultaat 'true' terug
		if (bValid) {
				return true;
		} else {
				// Wanneer niet alle velden correct zijn ingevuld, laat dan middels een jQuery-plugin (jAlert) een melding zien
				//  (melding + titel)
				switch (lang) {
					case "EN":
						jAlert("Not all of required fields are filled out", "Redirect this film");
						break;
					case "DE":
						jAlert("Füllen Sie bitte alle Felden gut aus", "Senden Sie diesen Film weiter");
						break;
					default:
						jAlert("Je hebt niet alle velden correct ingevuld", "Video doorsturen");
						break;
				}
				// En geef als resultaat 'false' terug. Hierdoor zal het formulier niet worden verstuurd
				return false;
		}
	}
