$(document).ready(function(){

	
function geld(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	s = s.replace('.', ',');
	return s.replace(',00', ',-');
}
	
	
	
	$(".lister div").hover(
		function()
		{
			$(this).addClass('hover');
		},
		function()
		{
			$(this).removeClass('hover');
		}
	);
		
	$(".lister div").click(function()
	{
		document.location.href = $("a", this)[0].href;
		return false;
	});

	
	$("#merk").load("/includes/engine.php?mode=merk", function()
	{
		if (document.body.className.indexOf("merk") != -1)
		{
			$("#merk").val(document.body.className.substr(4, document.body.className.length));
			$("#model").html("<option>...</option>");
			$("#model").load("/includes/engine.php?mode=model&id=" + this.value, function()
			{
				$("#model")[0].disabled = false;
				//$("#model")[0].focus();
				$("#bestel img")[0].src = "/images/pijli.gif";
				$("#stap2")[0].style.color = '#FFF';
				$("#stap3")[0].style.color = '#808080';
				$("#bestel")[0].style.color = '#808080';
				if (document.body.id.indexOf("model") != -1)
				{
					$("#model").val(document.body.id.substr(5, document.body.id.length));
					$("#bestel img")[0].src = "/images/pijl.gif";
					$("#stap3")[0].style.color = '#FFF';
					$("#bestel")[0].style.color = '#FFF';
					//$("#bestel")[0].focus();
				}
			});
		}
	});
	
	
	$("#merk").change(function()
	{
		$("#model").html("<option>...</option>");
		$("#model").load("/includes/engine.php?mode=model&id=" + this.value, function()
		{
			$("#model")[0].disabled = false;
			$("#model")[0].focus();
			$("#bestel img")[0].src = "/images/pijli.gif";
			$("#stap2")[0].style.color = '#FFF';
			$("#stap3")[0].style.color = '#808080';
			$("#bestel")[0].style.color = '#808080';
		});

	});
		
	
	$("#model").change(function()
	{
		if (parseInt($("#merk")[0].value) * parseInt($("#model")[0].value))
		{
			document.location.href = '/?s_page_id=' + $("#model")[0].value;
		}		
		//$("#bestel img")[0].src = "/images/pijl.gif";
		//$("#stap3")[0].style.color = '#FFF';
		//$("#bestel")[0].style.color = '#FFF';
		//$("#bestel")[0].focus();
	});
		
	$("#bestel").click(function()
	{
		if (parseInt($("#merk")[0].value) * parseInt($("#model")[0].value))
		{
			document.location.href = '/?s_page_id=' + $("#model")[0].value + '#naw';
		}
		return false;
	});		

	$("h1").click(function()
	{
		document.location.href = '/';
		return false;
	});

	function totaalb()
	{
		var bedrag = new Array();
		bedrag[1] = 7;
		bedrag[2] = 10;
		bedrag[3] = 15;		
		this.totaal = $("#aantal").val() * bedrag[$(".pkgr:checked").val()];
		if ($("#aantal").val() > 3)
		{
			if ($("#aantal").val() < 70)
			{
				this.totaal = (this.totaal * (100 - (Math.floor($("#aantal").val()/2) + 5)))/100;	
			}
			else //
			{
				this.totaal = this.totaal * (60)/100;	
			}
		}
		$("#totaal").html(geld(this.totaal));
		$("#totaale").html(' (hier komen verder <i>geen</i> kosten meer bij)');			
	}
	
	$("#aantal"). change(function()
	{
		totaalb();	
		
	});


	$(".pkg").click(function()
	{
		for (i = 1; i < 4; i++)
		{
			if (document.getElementById("pkgi" + i))
			{
				document.getElementById("pkgi" + i).src = "/images/pkg" + i + ".gif";
			}
		}
		document.getElementById(this.id.substr(0, 6)).checked = true;
		/*
		var bedrag = new Array();
		bedrag[1] = 7;
		bedrag[2] = 10;
		bedrag[3] = 15;
		
		$("#totaal").html(bedrag[this.id.substr(5,1)]);
		$("#totaale").html(' (hier komen verder <i>geen</i> kosten meer bij)');
		*/
		totaalb();
		this.getElementsByTagName("img")[0].src = this.getElementsByTagName("img")[0].src.replace(".gif", "_a.gif");
	});

	$("#nogmeer").toggle(
	function()
	{
		$("#meerdere").show();
		return false;
	},
	function()
	{
		$("#meerdere").hide();
		return false;
	}
	
	
	);
	totaalb();

	$("#keurmerk").click(function()
	{
		return false;
	});







// subliminale boodschap experiment :)
// wijzigt title en status (windows)
// kijken of we meer laders per sale verkopen
if ($("#s_bank")[0] && $("#s_bank").attr('title') == "2")
{
	//alert('ja');
	var oldtit = document.title;
	var oldst = window.status;
	if (oldtit.indexOf('oplader') != -1)
	{
		document.title = "Koop nu 2 " + oldtit.replace('oplader','opladers');
		window.status = "Koop nu 2 " + oldtit.replace('oplader','opladers');
		setTimeout(function()
		{
			document.title = oldtit;	
			window.status = oldst;
		}, 200);
	}	
}



});
