/************************************************************************************************************
// FILE IS CREATED BY JITENDRA UPRAITY
// ON                 09 APRIL, 2007
// PURPOSE            FUNCTION FILE FOR JAVASCRIPT

************************************************************************************************************/

var flyingSpeed = 15;
var flyingSpeedDel = 5;//25;

var shopping_cart_div = false;
var flyingDiv = false;
var currentProductDiv = false;

var shopping_cart_x = false;
var shopping_cart_y = false;

var slide_xFactor = false;
var slide_yFactor = false;

var diffX = false;
var diffY = false;

var currentXPos = false;
var currentYPos = false;
var op=100;
var qry;
var bflag=false;//browser flag
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(obj,productId,qry)
{
	var qty = eval(obj);
	if(isNaN(qty))
	{
		alert("Please Enter Numeric Quantity");
		return false;
	}
	if((qty <= 0))
	{
		alert("Please Enter Valid Quantity");
		return false;
	}
	if(qty.indexOf(".")!=-1)
	{
		alert("Please Enter Valid Quantity");
		return false;
	}
	if(qry == undefined)
	{
		qry="1";
	}
	if(!shopping_cart_div)shopping_cart_div = document.getElementById('mini_cart');
	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);
	
	
	if(navigator.appName=="Netscape")
	{
		var br = navigator.userAgent;
		
		if(br.indexOf("Firefox")==-1)
		{
		
			if(currentProductDiv.attributes[0].value=="feature_prod")
			{
				currentXPos = currentXPos+300;
				bflag=true;
			}
			else
			{
				bflag=false;
			}
		}
		else
		{
			if(currentProductDiv.attributes[0].value=="feature_prod")
			{
				currentXPos = currentXPos;
			}
		}
	}
	
	diffX = shopping_cart_x - currentXPos;
	diffY = shopping_cart_y - currentYPos;
	if(bflag)
	{
		shopping_cart_x=shopping_cart_x+260;
	}
	var shoppingContentCopy = currentProductDiv.cloneNode(true);
	shoppingContentCopy.id='';
	flyingDiv.innerHTML = '';
	//flyingDiv.innerHTML = '<table width="100%"  border="0" cellpadding="0" cellspacing="0"><tr><td width="25%" align="center" valign="middle" class="frmlabel1">Qty<img src="images/spacer.gif" width="5" height="8" alt="" title=""></td>                                                         <td width="8%" align="center" valign="middle"><input name="IR_quantity13" type="text" value="1" size="1"></td><td width="67%" align="right"><img src="images/spacer.gif" alt="" width="5" height="8" border="0" title=""><img src="images/but_addtocart1.gif" alt="Add To Cart" border="0" align="top" title="Add To Cart"></td></tr></table>';
	flyingDiv.style.width = currentProductDiv.offsetWidth + 'px';
	flyingDiv.style.left = currentXPos + 'px';
	flyingDiv.style.top = currentYPos + 'px';
	flyingDiv.appendChild(shoppingContentCopy);
	flyingDiv.style.display='block';
	
	
    w=currentProductDiv.style.width;
    h=currentProductDiv.style.height;
	flyToBasket(productId,qry);

}


function flyToBasket(productId,qry)
{
	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 + '","'+qry+'")',10);
    else page_submit(productId,qry);
}

function delFromBasket(productId)
{
    if(!shopping_cart_div)shopping_cart_div = document.getElementById('del_cart');
	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('slidingCart' + productId);

	currentXPos = shoppingCart_getLeftPos(currentProductDiv);
	currentYPos = shoppingCart_getTopPos(currentProductDiv);

	diffX = shopping_cart_x - currentXPos;
	diffY = shopping_cart_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';
    currentProductDiv.style.visibility='hidden';
	flyFromBasket(productId);

}

function flyFromBasket(productId)
{
    var maxDiff = Math.max(Math.abs(diffX),Math.abs(diffY));

	var moveX = (diffX / maxDiff) * flyingSpeedDel;
	var moveY = (diffY / maxDiff) * flyingSpeedDel;

	currentXPos = currentXPos + moveX;
	currentYPos = currentYPos + moveY;

	flyingDiv.style.left = Math.round(currentXPos) + 'px';
	flyingDiv.style.top = Math.round(currentYPos) + 'px';
    flyingDiv.style.filter='alpha(opacity='+op+')';
    flyingDiv.style.opacity=parseFloat(op/100);
    if(op>0)
    op=op + moveY;



	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('flyFromBasket("' + productId + '")',100);
    else
    {
        op=100;
        flyingDiv.style.filter='alpha(opacity='+op+')';
    	flyingDiv.style.opacity=1;
        delete_from_cart(productId);
    }
}