var $$ = function(id) {
  return document.getElementById(id);
};

/**
 * Checks if the cart summary should be displayed.
 */
function checkCart() {
  var theSummary = $$("cart-summary");
  var items = getCartItem(3);
  if (items == 0) theSummary.style.display = "none";
  else {
     changeOpac(0, "cart-summary");
     theSummary.style.display = "block";
     doOpacity("cart-summary", 0, 90, 800);
  }
}

/**
 * Sets a timeout to change the opacity of an element.
 */
function doOpacity(id, opacStart, opacEnd, millisec) {
  var speed = Math.round(millisec / 100);
  var timer = 0;

  if (opacStart > opacEnd) {
    for(var i = opacStart; i >= opacEnd; i--) {
      setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
	timer++;
    }
  } 
  else if (opacStart < opacEnd) {
    for (var i = opacStart; i <= opacEnd; i++) {
      setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
	timer++;
    }
  }
}

/**
 * Cross-browser opacity change.
 */
function changeOpac(opacity, id) {
  var object = $$(id).style; 
  object.opacity = (opacity / 100);
  object.MozOpacity = (opacity / 100);
  object.KhtmlOpacity = (opacity / 100);
  object.filter = "alpha(opacity=" + opacity + ")";
}

//attach the cart check function to the load event
if (window.attachEvent) { 
  window.attachEvent("onload", checkCart); 
} 
else {  
  window.addEventListener("load", checkCart, false); 
}


