
// Bortkommenterat 090713 av Esbjörn, orsakade javascriptfel
// document.getElementById("movie-slide").onload = this.className = "ffmac-fix";	

function initCart()
{
  var tweenTrigger = document.getElementById("toggle-cart");
  var tweenObj = document.getElementById("shop-basket");

  if(typeof tweenObj.opened == "undefined")
  {
	  tweenObj.opened = false;
  }
  
  // FF-mac fix
 /* initCart.ffmacfix = function()
  {
  if(tweenObj.opened != true || typeof tweenObj.opened == "undefined")
  {
	document.getElementById("movie-slide").className = "ffmac-fix";
  }
  }
  initCart.ffmacfix;*/
  
  document.getElementById("movie-slide").className = "ffmac-fix";
  
  // Safari fix
  // This will check if the cart is opened (forced open by "show_cart=true"+TYPO3) and,
  // if that is the case, it will add the style display='none' to the cart, to efficiently 
  // block it from being rendered.
  // Erik Frögéli, 071114
  if(tweenObj.style.height!='320px'){
    tweenObj.style.display = "none";
  }
  
  tweenTrigger.oldText = tweenTrigger.innerHTML;
  
  
  docLang = document.getElementById("lang").getAttribute("content");
  
 initCart.isOpen = function()
 {
	 return tweenObj.opened;
 }
  
	initCart.action = function(param)
	{
		
	  if(docLang == "sv")
	  {
	  tweenTrigger.newText = "Stäng X";
	  }
	  else
	  {
	  tweenTrigger.newText = "Close X";  
	  }
		
		  // Check if the cart is open as a result of a request
		  // henrik@pool.se, 071023
		  if (tweenObj.style.height!='' && tweenObj.style.height!='0px') {
				tweenObj.opened = true;
				tweenTrigger.innerHTML = tweenTrigger.newText;
		  } else {
			  tweenObj.opened = false;
		  }
		  
			  if(param == "open")
			  {		  
				  tweenObj.style.display = "block";
				  tweenTrigger.innerHTML = tweenTrigger.newText;
				  tweenObj.opened = true;
				  tweenObj.animationTimer = setInterval('moveTweenObject(document.getElementById("shop-basket"), 320, 30)', 25);
				  return false;
			  }
			  else if(param == "close")
			  {
				  initCart.ffmacfix;
				  tweenTrigger.innerHTML = tweenTrigger.oldText;
				  tweenObj.opened = false;
				  tweenObj.animationTimer = setInterval('moveTweenObject(document.getElementById("shop-basket"), 0, 30)', 25);
				  return false;
			  }
			  else
			  {
				return true;
			  }
		  
	
	} // action()
	
	
	if(typeof tweenObj != "undefined" && typeof tweenTrigger != "undefined"){
		
		tweenTrigger.onclick = function()
		{
			if(tweenObj.opened == false)
			{
			 initCart.action("open");
			 return false;
			}
			else if(tweenObj.opened == true)
			{
			 initCart.action("close");
			 return false;
			}
		 }
	 }

return true;
}

/* JSant 1.0 Animation */

function moveTweenObject(target, destinationHeight, maxSpeed)
{
 
  var currentHeight = parseInt(retrieveComputedStyle(target, "height"));
  var friction = 6;
  
  
   if (isNaN(currentHeight))
  {
    currentHeight = 0;
  }

  if (typeof target.floatingPointTop == "undefined")
  {
    target.floatingPointTop = currentHeight;
  }

   var decelerateTop = 1 + Math.abs(destinationHeight - target.floatingPointTop) / friction;

   if (decelerateTop > maxSpeed)
  {
    decelerateTop = maxSpeed;
  }

  
  if (target.floatingPointTop < destinationHeight)
  {
    target.floatingPointTop += decelerateTop;

    if (target.floatingPointTop > destinationHeight)
    {
      target.floatingPointTop = destinationHeight;
    }
  }
  else
  {
    target.floatingPointTop -= decelerateTop;

    if (target.floatingPointTop < destinationHeight)
    {
      target.floatingPointTop = destinationHeight;
    }
  }

   target.style.height = parseInt(target.floatingPointTop) + "px";

  if (target.floatingPointTop == destinationHeight)
  {

	
	if(destinationHeight == "320")
	{
	target.style.display = "block";	
	document.getElementById("movie-slide").className = "";
	   
	}
	else
	{
	target.style.display = "none";
	initCart.ffmacfix;
   
	}
	clearInterval(target.animationTimer);
		
  }
}


function retrieveComputedStyle(element, styleProperty)
{
  var computedStyle = null;

  if (typeof element.currentStyle != "undefined")
  {
    computedStyle = element.currentStyle;
  }
  else
  {
    computedStyle = document.defaultView.getComputedStyle(element, null);
  }

  return computedStyle[styleProperty];
}


