
var flyingSpeed = 15;


var side_titles_div = false;
var flyingDiv = false;
var currentproductDiv = false;

var side_titles_x = false;
var side_titles_y = false;

var slide_xFactor = false;
var slide_yFactor = false;

var diffX = false;
var diffY = false;

var currentXPos = false;
var currentYPos = false;


function shoppingCart_getTopPos(inputObj)
{
  var returnValue = inputObj.offsetTop;
  while((inputObj = inputObj.offsetParent) != null){
  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
  }
  return returnValue;
}

function shoppingCart_getLeftPos(inputObj)
{
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null){
  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
  }
  return returnValue;
}


function addToBasket(productId)
{
	side_titles_div = document.getElementById('flyhere');
	if(!flyingDiv){
		flyingDiv = document.createElement('DIV');
		flyingDiv.style.position = 'absolute';
		document.body.appendChild(flyingDiv);
	}

	side_titles_x = shoppingCart_getLeftPos(side_titles_div);
	side_titles_y = shoppingCart_getTopPos(side_titles_div);

	currentproductDiv = document.getElementById('slidingproduct' + productId);

	currentXPos = shoppingCart_getLeftPos(currentproductDiv);
	currentYPos = shoppingCart_getTopPos(currentproductDiv);

	diffX = side_titles_x - currentXPos;
	diffY = side_titles_y - currentYPos;


	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';
	flyToBasket(productId);

}


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 > side_titles_x){
		flyingDiv.style.display='none';
	}
	if(moveX<0 && currentXPos < side_titles_x){
		flyingDiv.style.display='none';
	}

	if(flyingDiv.style.display=='block')setTimeout('flyToBasket("' + productId + '")',10);
}

