$(function() {
	$(document).pngFix();
	
	$('a.lightbox').lightBox();
	
	/* localNav mods */
	$("#localNav li:last").addClass("last");
	
	// Media
	$("div.media").each(function(){
		renderFlash(this);
	});	
	
	//standaard value van zoekform + nieuwsbrief form
	$('#keyWords, #emailAddress')
		.focus(function() {
			if(this.value == this.defaultValue) this.value = "";
		})
		.blur(function() {
			if(this.value == "") this.value = this.defaultValue;
		});	
	
	//uitklapmenu bij globalnav
	$("#globalNav ul li").hover(
		function () {
			$(this).children("ul").css({'display' : 'block'});
		}, 
		function () {
			$(this).children("ul").css({'display' : 'none'});
		}
	);
		
	//uitklapmenu bij header en sportwerelden
	$(".selectBoxSelected").hover(
		function () {
			$(this).children("ul").css({'display' : 'block'});
		}, 
		function () {
			$(this).children("ul").css({'display' : 'none'});
		}
	);
	
	$(".selectBoxSelected ul li:last-child a").css({'borderBottom' : 'none'});
	
	var highlightsHeight = 0;
		
	$('.highlights .content').each(function(){
		if(highlightsHeight < $(this).height()){
			highlightsHeight = $(this).height();
		}
	});
	
	$('.highlights .content').height(highlightsHeight);
	
	if($('.highlights').size() && $('.usp-block').size()){
		
		var height 	= $('.highlights').height();
		var height2 = $('.usp-block').height();
		
		if(height < height2){
			$('.highlights').height(height2);
			$('.usp-block').height(height2);
		}else{
			$('.highlights').height(height);
			$('.usp-block').height(height);
		}
		
	}
	
});


function getProductPrice(nProductID, nVerticalID, nHorizontalID, onreturn) {
	
	var sURL = _root + "include/ajax_getproductprice.asp";
	var sData = "?pid=" + nProductID + "&vid=" + nVerticalID + "&hid=" + nHorizontalID;
	
	$.ajax({
		type: "GET",
		url: sURL + sData,
		cache: false,
		async: true,
		success: function(html){
			
			onreturn(html);

		}, 
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			alert("fout");
			alert(XMLHttpRequest.responseText);
		}
  	});

}

function setProductPrice(s){
	alert(s);
	var newPrice = formatPrice(s);
	var original = $('#innerContent .price').html();
	if (original!=newPrice){
		$('#innerContent .price').html(newPrice);
	}
}

function formatPrice(sVal) {

	sVal = Math.round(sVal*100)/100;
	sVal = sVal.toString();
	
	var nPoint = sVal.indexOf(".");
	var dec = sVal.length - nPoint;
	
	if(nPoint == -1) {
		sVal = sVal + ".00";
	} else if (dec == 2) {
		sVal = sVal + "0";
	}
	
	sVal = sVal.replace(/\./, ",");
	return "&euro; " + sVal;
		
}

function formatPriceCustom(sVal) {

	sVal = Math.round(sVal*100)/100;
	sVal = sVal.toString();
	
	var nPoint = sVal.indexOf(".");
	var dec = sVal.length - nPoint;

	if(nPoint == -1) {
		sVal = sVal + ".00";
	} else if (dec == 2) {
		sVal = sVal + "0";
	}
	
	sVal = sVal.replace(/\./, ",");
	aValues = sVal.split(",");

	return '<span class="price"><span class="valuta">&euro;</span> <span class="main">' + aValues[0] + '</span><span class="separator">,</span><span class="cents">' + aValues[1] + '</span></span>';
}

function getRadioButtonValue(o) {
	
	var sVal;

	for(var i=0;i<o.length;i++) {
		if(o[i].checked) {
			sVal = o[i].value;
		}
	}
	
	return sVal;
	
}


// Flashobject activeX workaround
function makeFlashObj(sID, sPath, sWidth, sHeight, sBG)
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="' + sID + '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + sWidth + '" height="' + sHeight + '">');
	document.write('<param name="movie" value="' + sPath + '">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="bgcolor" value="' + sBG + '">');
	document.write('<embed bgcolor="' + sBG + '" src="' + sPath + '" quality="high" id="' + sID + '" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + sWidth + '" height="' + sHeight + '"></embed>');
	document.write('</object>');
}

// Flashobject activeX workaround
function makeFlashObjLive(sID, sPath, sWidth, sHeight, sBG)
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="' + sID + '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + sWidth + '" height="' + sHeight + '">');
	document.write('<param name="movie" value="' + sPath + '">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="bgcolor" value="' + sBG + '">');
	document.write('<param name="allowScriptAccess" value="always">');	
	document.write('<embed allowScriptAccess="always" bgcolor="' + sBG + '" src="' + sPath + '" quality="high" id="' + sID + '" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + sWidth + '" height="' + sHeight + '"></embed>');
	document.write('</object>');
}

function renderFlash(o){
		
	$(o).html('');
		
	var options 			= $(o).metadata({type:'attr',name:'options'});
	var sSrc 				= options.src;
	var sType 				= options.type;
	var nWidth 				= options.width;
	var nHeight 			= options.height;
	var sLink 				= options.link;
	var bAllowFullScreen 	= options.allowfullscreen;
	
	if(sType=="flash"){
	
		$(o).flash({
			swf: _root + sSrc,
			width: nWidth, 
			height: nHeight,
			expressInstall: true,
			params : {
				allowfullscreen: bAllowFullScreen
			}
		});
	
	}
	else if (sType=="flv"){
		$(o).flash({
			swf: _root + "swf/player.swf",
			width: nWidth, 
			height: nHeight,
			allowfullscreen: 'true',
			expressInstall: true,
			flashvars: {
				file: _root + sSrc,
				autostart: options.autostart,
				type: 'http',
				link: sLink
			},
			params : {
				allowfullscreen: bAllowFullScreen
			}
		});
		
	}
	else if (sType=="mp3"){
	
		$(o).flash({
			swf: _root + "swf/player.swf",
			width: nWidth, 
			height: nHeight,
			allowfullscreen: 'true',
			expressInstall: true,
			flashvars : {
				file: _wwwroot + sSrc,
				autostart: options.autostart,
				type: 'sound',
				link: sLink
			},
			params : {
				allowfullscreen: bAllowFullScreen
			}
		});
		
	}
	else if (sType=="youtube"){
	
		$(o).flash({
			swf: _root + "swf/player.swf",
			width: nWidth, 
			height: nHeight,
			allowfullscreen: 'true',
			expressInstall: true,
			flashvars : {
				file: options.file,
				autostart: options.autostart,
				type: 'youtube'
			},
			params : {
				allowfullscreen: bAllowFullScreen
			}
		});
	
	};

}

