/**
 * @author pieterjan
 */

function fadeCart(){
	document.getElementById('shopframe').style.display = "none";
	document.getElementById('tab').style.display = "block";
}

function handleHttpResponse() {

  if (http.readyState == 4) {

	results = http.responseText;

	document.getElementById('shopcart').innerHTML = results;

  }

}

function addItem(product,aantal,prijs){
	
	var url = "shopcart.php?p="+product+"&a="+aantal+"&e="+prijs;
	
	http.open("GET", url, true);

	http.onreadystatechange = handleHttpResponse;

	http.send(null);
	
	document.getElementById('shopframe').style.display = "block";
	document.getElementById('tab').style.display = "none";
	
}
function clearArray(){
	
	var url = "shopcart.php?clear=true";
	
	http.open("GET", url, true);

	http.onreadystatechange = handleHttpResponse;

	http.send(null);
	
	setTimeout(fadeCart,1000);
}
function hideCart(){
	setTimeout(fadeCart,500);
}
function showCart(){
	document.getElementById('shopframe').style.display = "block";
	document.getElementById('tab').style.display = "none";
	addItem("","","");
}

function moveCart(){
	var el = document.getElementById('shopframe');
	el.top = window.scrollTop; 
}

function getHTTPObject() {

	var xmlHttp;
	try
		{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		}
	catch (e)
	{
	// Internet Explorer
	try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch (e)
		{
		try
			{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		catch (e)
			{
			alert("Your browser does not support AJAX!");
			return false;
			}
		}
	}
	return xmlHttp;
}
var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
function floatDiv(id, sx, sy)
{
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	var px = document.layers ? "" : "px";
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.right=x+px;this.style.top=y+px;};

	el.floatIt=function()
	{
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth :
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
  pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.floatIt()", 40);
	}
	return el;
}

function togglePromoties()
{
  if (document.getElementById('promoties'))
  {
    if (document.getElementById('promoties').style.display != 'block')
    {
      var stijl = 'block';
    }
    else
    {
      var stijl = 'none';
    }
    
    document.getElementById('promoties').style.display = stijl;
  }
}

var http = getHTTPObject();

