// IE versie checker
	
	var Browser = {
	  Version: function() {
	    var version = 999; // we assume a sane browser
	    if (navigator.appVersion.indexOf("MSIE") != -1)
	      // bah, IE again, lets downgrade version number
	      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
	    return version;
	  }
	}
	
// zoekwoord

	function clickclear(thisfield, defaulttext)
	{
		if (thisfield.value == defaulttext)
		{
			thisfield.value = "";
			if(document.getElementById('zoekwoord'))
			{
				document.getElementById('zoekwoord').style.color = '#000000';
			}
		}
	}
	
	function clickrecall(thisfield, defaulttext)
	{
		if (thisfield.value == "")
		{
			thisfield.value = defaulttext;
			if(document.getElementById('zoekwoord'))
			{
				document.getElementById('zoekwoord').style.color = '#b5b5b5';
			}
		}
	}
	
// jQuery

	$(document).ready(function() {

		if(document.getElementById('inloggen'))
		{
			$('#inloggen').click(function(){
				$('#loginbox').toggle();
			});
		}

		if(document.getElementById('winkelwagen'))
		{
			$('.toggleWinkelwagen').click(function(){
				//alert('test');
				$('#winkelwagen').toggle();
			});
		}

		// datepicker
		
			$(".datepicker").datepicker({ minDate: (+1) });
			
		// drag & drop

			if(document.getElementById('winkelwagen2'))
			{
				$("#winkelwagen2").live('mouseover',function(){
					
					//$(".drag",this).css("backgroundColor","#ff66ff");
					$(".drag",this).draggable({
						//opacity: 0.35,
						revert: true,        
			            revertDuration: 350,
			            cursor: 'pointer',
						stop: function(){
							//do something
							cursor: 'auto'
						}
					});
					
			        $(".drop").draggable({
			            axis: "x"
			        });
	
					$(".drop",this).droppable({
			            accept: ".drag",
			            drop: function(event, ui) {
							ui.draggable.effect('transfer', { to: $(this) });
							ui.draggable.fadeTo('normal', 0.0);
	
							var timestamp = $(this).attr('id');
							var productID = ui.draggable.attr("id");
							
							timestamp = timestamp.replace("cadeauverpakking_", "");
							productID = productID.replace("afbeelding_", "");
							
							toevoegenAanCadeauverpakking(productID,timestamp);
						}
					});
	
				});
			}
		
		// fancybox
		
			$("a[rel=lightbox]").fancybox({
				'transitionIn'	: 'fade',
				'transitionOut'	: 'fade'
			});
		
		// rounded corners

			var IE = /*@cc_on!@*/false;
			if(IE){
			} else {
				// optional rounded form elements
				//$("#wrapper.home #top #searchBar input").corner("round 5px");
			}
			
			$("#account").corner("round 10px bottom");
			$("#wrapper.index #top #searchBar ul li a").corner("round 5px");
			$("#wrapper.home #top #searchBar ul li a").corner("round 5px");
			$("#columnMain .itemGrid .item ul li").corner("round 5px");
			$("#columnLeft h1").corner("round 5px");
			$(".item ul li").corner("round 5px");
			$("ul.itemButtons li").corner("round 5px");
			$(".tabContent").corner("round 10px bottom");
			$(".tabContent").corner("round 10px tr");
			$("#tabMenu li a").corner("round 10px top");
					
		// make navigation li's clickable

			$("#columnLeft ul li a").parent().css("cursor","pointer").click(function(){
				window.location = $('a', this).attr('href');
			});
			
			/*
			$(".item ul li a").parent().css("cursor","pointer").click(function(){
				window.location = $('a', this).attr('href');
			});
			*/

	});
	

// AJAX

	function createRequestObject() {
		var ro;
		var browser = navigator.appName;
		if(browser == "Microsoft Internet Explorer"){
			ro = new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			ro = new XMLHttpRequest();
		}
		return ro;
	}

	var http = createRequestObject();
	
	function sndReq(action) {
		http.open('get', '/rpcv2.php?action='+action);
		http.onreadystatechange = handleResponse;
		http.send(null);
	}

	function sndReqArg(action,sub) {
		http.open('get', '/rpcv2.php?action='+action+'&sub='+sub);
		http.onreadystatechange = handleResponse;
		http.send(null);
	}	
	function handleResponse() {
		if(http.readyState == 4){
			var response = http.responseText;
			var update = new Array();
	
			if(response.indexOf('|||') != -1) {
				update = response.split('|||');
				
				
				if (document.getElementById(update[0]))
				{
					document.getElementById(update[0]).innerHTML = update[1];
				}
				
			}

			updateCounter();
		}
	}

// RPC WINKELWAGEN

	function updateCounter()
	{
		http.open('get', '/rpcv2.php?action=updateCounter');
		http.onreadystatechange = handleResponse;
		http.send(null);
	}

	function loadCart()
	{
		http.open('get', '/rpcv2.php?action=loadCart');
		http.onreadystatechange = handleResponse;
		http.send(null);
	}

	function loadCart2(targetDiv)
	{
		http.open('get', '/rpcv2.php?action=loadCart&targetDiv='+targetDiv);
		http.onreadystatechange = handleResponse;
		http.send(null);
		if (targetDiv == 'winkelwagen3')
		{
			// ook verzendkosten berekenen 
		}
	}

	function emptyCart()
	{
		http.open('get', '/rpcv2.php?action=emptyCart');
		http.onreadystatechange = handleResponse;
		http.send(null);
	}

	function addToCart(productID)
	{
		http.open('get', '/rpcv2.php?action=addToCart&productID='+productID);
		http.onreadystatechange = handleResponse;
		http.send(null);
	}

	function addBonusToCart(productID,points)
	{
		http.open('get', '/rpcv2.php?action=addBonusToCart&productID='+productID+'&points='+points);
		http.onreadystatechange = handleResponse;
		http.send(null);
	}

	function changeAmount(productID,amount)
	{
		http.open('get', '/rpcv2.php?action=changeAmount&productID='+productID+'&amount='+amount);
		http.onreadystatechange = handleResponse;
		http.send(null);
	}

	function changeAmount2(productID,amount)
	{
		http.open('get', '/rpcv2.php?action=changeAmount2&productID='+productID+'&amount='+amount);
		http.onreadystatechange = handleResponse;
		http.send(null);
	}

	function increaseAmount(productID)
	{
		http.open('get', '/rpcv2.php?action=increaseAmount&productID='+productID);
		http.onreadystatechange = handleResponse;
		http.send(null);
	}

	function increaseAmount2(targetDiv,productID)
	{
		http.open('get', '/rpcv2.php?action=increaseAmount&productID='+productID+'&targetDiv='+targetDiv);
		http.onreadystatechange = handleResponse;
		http.send(null);
	}

	function decreaseAmount(productID)
	{
		http.open('get', '/rpcv2.php?action=decreaseAmount&productID='+productID);
		http.onreadystatechange = handleResponse;
		http.send(null);
	}

	function decreaseAmount2(targetDiv,productID)
	{
		http.open('get', '/rpcv2.php?action=decreaseAmount&productID='+productID+'&targetDiv='+targetDiv);
		http.onreadystatechange = handleResponse;
		http.send(null);
	}

	function returnVerzendkosten(postcode)
	{
		http.open('get', '/rpcv2.php?action=returnVerzendkosten&postcode='+postcode);
		http.onreadystatechange = handleResponse;
		http.send(null);
	}

	function returnVerzendkosten2(landID)
	{
		http.open('get', '/rpcv2.php?action=returnVerzendkosten2&landID='+landID);
		http.onreadystatechange = handleResponse;
		http.send(null);
	}

	function verwerkCouponcode()
	{
		var couponcode = document.getElementById('couponcode').value;

		http.open('get', '/rpcv2.php?action=verwerkCouponcode&couponcode='+couponcode);
		http.onreadystatechange = handleResponse;
		http.send(null);

		setTimeout("loadCart2('winkelwagen3')", 300);
	}
	
	function kiesCadeauverpakking()
	{
		var cadeauverpakkingID = document.getElementById('cadeauverpakkingID').value;
		//alert(cadeauverpakkingID);
		
		http.open('get', '/rpcv2.php?action=kiesCadeauverpakking&cadeauverpakkingID='+cadeauverpakkingID);
		http.onreadystatechange = handleResponse;
		http.send(null);

		setTimeout("loadCart2('winkelwagen2')", 300);
	}
	
	function verwijderCadeauverpakking(timestamp)
	{
		http.open('get', '/rpcv2.php?action=verwijderCadeauverpakking&timestamp='+timestamp);
		http.onreadystatechange = handleResponse;
		http.send(null);

		setTimeout("loadCart2('winkelwagen2')", 300);
	}
	
	function toevoegenAanCadeauverpakking(productID,timestamp)
	{
		//alert('voeg productID '+productID+' toe aan verpakking '+timestamp);

		http.open('get', '/rpcv2.php?action=toevoegenAanCadeauverpakking&productID='+productID+'&timestamp='+timestamp);
		http.onreadystatechange = handleResponse;
		http.send(null);

		setTimeout("loadCart2('winkelwagen2')", 1300);
	}

	function increaseCadeauverpakking(targetDiv,timestamp)
	{
		http.open('get', '/rpcv2.php?action=increaseCadeauverpakking&timestamp='+timestamp+'&targetDiv='+targetDiv);
		http.onreadystatechange = handleResponse;
		http.send(null);

		setTimeout("loadCart2('winkelwagen2')", 1300);
	}

	function decreaseCadeauverpakking(targetDiv,timestamp)
	{
		http.open('get', '/rpcv2.php?action=decreaseCadeauverpakking&timestamp='+timestamp+'&targetDiv='+targetDiv);
		http.onreadystatechange = handleResponse;
		http.send(null);

		setTimeout("loadCart2('winkelwagen2')", 1300);
	}

// RPC OVERIG
	
	
