var tipShown = false;
var cart_loaded = false;

function goToCart() {
	window.location = "cart.php";
}

function relocateCart()
{
  cart_loaded = true;
  // relocate cart
  object = document.getElementById("cart");
  if(document.body.scrollTop < 0)
  {
    object.style.top = 0;
  }
  else
  {
    object.style.top = document.body.scrollTop;
  }
  
  if(document.body.clientWidth > 990)
  {
    object.style.left = document.body.clientWidth - (document.body.clientWidth - 990) / 2 - object.clientWidth;
  }
  else
  {
    object.style.left =  document.body.scrollLeft + document.body.clientWidth - object.clientWidth;
  }
  object.style.visibility = "visible";

  if(tipShown)
  {
  	showCartTip()
  }
}

function refreshCart()
{
  if(cart_loaded) {
	  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;
	      }
	    }
	  }
	  xmlHttp.onreadystatechange=function()
	  {
	    if(xmlHttp.readyState==4)
	    {
		  //Show cart icon
		  document.cart_img.src = "images/cart.png";
		  
		  var responseText = xmlHttp.responseText;
		  var responseTokens = responseText.split( "|" );
		  var itemAdded = false;
		  
		  if(responseTokens[0].indexOf("true") == 0) {
		  	itemAdded = true;
		  }
	  
	      document.getElementById("itemCount").innerHTML=responseTokens[1];
	      hideDetails();
	            
	      var countTipShown = readCookie("cart_tip_count");
	      if(countTipShown == "")
	      {
	      	countTipShown = 0;
	      }
	      
	      if(countTipShown < 5)
	      {
		      showCartTip();
		      setTimeout("hideCartTip();",5000);
		      countTipShown++;
		      setCookie("cart_tip_count",countTipShown,30)
		  }
	    }
	  }
	  xmlHttp.open("GET","get_cart_info.php?sid="+Math.random(),true);
	  xmlHttp.send(null);
	}
}

function showCartTip()
{
  // relocate cart tip
  object = document.getElementById("cart_tip");
  if(document.body.scrollTop < 30)
  {
    object.style.top = 60;
  }
  else
  {
    object.style.top = document.body.scrollTop + 60;
  }
  
  if(document.body.clientWidth > 990)
  {
    object.style.left = document.body.clientWidth - (document.body.clientWidth - 990) / 2 - object.clientWidth;
  }
  else
  {
    object.style.left =  document.body.scrollLeft + document.body.clientWidth - object.clientWidth;
  }
  object.style.visibility = "visible";
  tipShown = true;
}

function hideCartTip()
{
  object = document.getElementById("cart_tip");
  object.style.visibility = "hidden";
  object.style.top = 0;
  object.style.left = 0;
  
  tipShown = false;
}
