var flyingSpeed = 50;
var shopping_cart_div = false;
var flyingDiv = false;

var shopping_cart_x = false;
var shopping_cart_y = false;
var refprod = false;
var etiq1='';
var etiq2='';

function ajoutpanier(productId,coef,e1,e2)
{
	refprod=productId;
	etiq1=e1;
	etiq2=e2;
	
		
	if (etiq1==undefined){etiq1='';}
	if (etiq2==undefined){etiq2='';}
	if(!shopping_cart_div)shopping_cart_div = document.getElementById('panierheader');
	if(!flyingDiv){
		flyingDiv = document.createElement('DIV');
		flyingDiv.style.position = 'absolute';
		document.body.appendChild(flyingDiv);
	}
	
	shopping_cart_x = shoppingCart_getLeftPos(shopping_cart_div);
	shopping_cart_y = shoppingCart_getTopPos(shopping_cart_div);
	currentProductDiv = document.getElementById('slidingProduct' + productId);
	currentXPos = shoppingCart_getLeftPos(currentProductDiv);
	currentYPos = shoppingCart_getTopPos(currentProductDiv);
	switch(coef){ 
	case 2: 
	currentXPos=286;shopping_cart_x-=286;
	break;
	case 3: 
	currentXPos=286;shopping_cart_x-=550;
	break; 
	case 4: 
	currentYPos-=390;shopping_cart_y-=286;
	break; 
	case 5: 
	currentYPos-=390;currentXPos-=250;shopping_cart_y-=286;shopping_cart_x-=286;
	break; 
	case 6: 
	currentYPos-=390;currentXPos-=500;shopping_cart_y-=286;shopping_cart_x-=450;
	break; 

	}

		
	diffX = shopping_cart_x - currentXPos;
	diffY = shopping_cart_y - currentYPos;
	//alert(shopping_cart_x);
	
	var shoppingContentCopy = currentProductDiv.cloneNode(true);
	shoppingContentCopy.id='';
	flyingDiv.innerHTML = '';
	flyingDiv.style.left = currentXPos + 'px';
	flyingDiv.style.top = currentYPos + 'px';
	flyingDiv.appendChild(shoppingContentCopy);
	flyingDiv.style.display='block';
	flyingDiv.style.width = currentProductDiv.offsetWidth + 'px';
	//alert(flyingDiv.style.width);	
	flyToBasket(productId);
}

function shoppingCart_getLeftPos(inputObj)
{
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null){
  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
  }
  return returnValue;
}

function shoppingCart_getTopPos(inputObj)
{		
  var returnValue = inputObj.offsetTop;
  while((inputObj = inputObj.offsetParent) != null){
  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
  }
  return returnValue;
}

function flyToBasket(productId)
{
	var maxDiff = Math.max(Math.abs(diffX),Math.abs(diffY));
	var moveX = (diffX / maxDiff) * flyingSpeed;;
	var moveY = (diffY / maxDiff) * flyingSpeed;	
	
	currentXPos = currentXPos + moveX;
	currentYPos = currentYPos + moveY;
	
	flyingDiv.style.left = Math.round(currentXPos) + 'px';
	flyingDiv.style.top = Math.round(currentYPos) + 'px';	
	
	
	if(moveX>0 && currentXPos > shopping_cart_x){
		flyingDiv.style.display='none';		
	}
	if(moveX<0 && currentXPos < shopping_cart_x){
		flyingDiv.style.display='none';		
	}
	
	if(flyingDiv.style.display=='block')setTimeout('flyToBasket("' + productId + '")',10); else submitForm(document.getElementById('panierheaderdetail'));
}


