// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
//																								   //
//									WWW.YALLA.CO.IL												   //
//							      @ כל הזכויות שמורות @											   //
//																								   //
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //

function Px2Num (px)
{
	return parseInt(px.substring(0,px.indexOf('p')));	// p of 'px'
}

var yallaCartElm 					= null;
var yallaFloatCart_top		= 100;
var yallaFloatCart_outside	= 120;
var cartWidth				= 0;	// p of 'px'

var slideEffect				= 'off';
var window_scrollPos		= 0;
var slideFPS				= 10;
var isOpenedFirstTime		= false;


function YallaFloatCart ()
{
	yallaCartElm 		= document.getElementById('yallaFloatCart');
	
	if	(yallaCartElm)
	{
		cartWidth 			= Px2Num(yallaCartElm.style.width);
		cartLeft = ((cartWidth - yallaFloatCart_outside) * -1);
		
        YallaFloatCart_Slide();
		//YallaFloatCart_Float();
	}
}

function YallaFloatCart_Slide ()
{				
	if	(slideEffect == 'off')
	{
		
	}
	else if	(slideEffect == 'slide_in')
	{
        cartCurrLeft = Px2Num(document.getElementById('yallaFloatCart').style.marginLeft);

		if	(cartCurrLeft < 0)
		{
			document.getElementById('yallaFloatCart').style.marginLeft = (cartCurrLeft + 10);
		}
		else
		{
			slideEffect = 'off';
		}
	}
	else if	(slideEffect == 'slide_out')
	{
		cartCurrLeft = Px2Num(document.getElementById('yallaFloatCart').style.marginLeft);
		
		if	(cartCurrLeft > ((cartWidth - yallaFloatCart_outside) * -1))
		{
			document.getElementById('yallaFloatCart').style.marginLeft = (cartCurrLeft - 10);
		}
		else
		{
			slideEffect = 'off';
		}
	}
	
	setTimeout("YallaFloatCart_Slide()",slideFPS);
}

/*
function YallaFloatCart_Float ()
{
	scrollTop = document.body.scrollTop;
	
	if	(window_scrollPos != scrollTop)
	{
		window_scrollPos = scrollTop;
		
		YallaFloatCart_Scroll();
	}
	
	setTimeout("YallaFloatCart_Float()",30);
}
*/
/*
function YallaFloatCart_Scroll ()
{
	scrollTop = document.body.scrollTop;
	requiredTop = (yallaFloatCart_top + scrollTop);
	
	pxPerSec = Math.abs(requiredTop - scrollTop) / 5;
	
	if	(pxPerSec < 0) pxPerSec = 1;
	
	if	(Px2Num(yallaCartElm.style.top) < requiredTop)
	{
		newTop = Px2Num(yallaCartElm.style.top) + 5;
		
		newTop = (newTop > requiredTop) ? requiredTop : newTop;
		
		yallaCartElm.style.top = newTop + 'px';
		
		setTimeout("YallaFloatCart_Scroll()",1);
	}
	else if	(Px2Num(yallaCartElm.style.top) > requiredTop)
	{
		newTop = Px2Num(yallaCartElm.style.top) - 5;
		
		newTop = (newTop < requiredTop) ? requiredTop : newTop;
		
		yallaCartElm.style.top = newTop + 'px';
		
		setTimeout("YallaFloatCart_Scroll()",1);
	}	
}
*/

function YallaFloatCart_Open (storeid,page)
{

	slideEffect = 'slide_in';
	
	if	(!isOpenedFirstTime)
	{
		 addToCart(0,storeid,'view',page,'onload');
		 
		 isOpenedFirstTime = true;
	}
}

function YallaFloatCart_Close ()
{
	slideEffect = 'slide_out';
}

function YallaFloatCart_OpenAndClose ()
{
	YallaFloatCart_Open();
	
	setTimeout("YallaFloatCart_Close()",3000);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  //
// ריחוף המוצר לסל הקניות - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  //

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 Fly2Cart (productId)
{
	var id = 'productTemp' + new Date().getTime() + '_' + productId;
	var flyingDiv = document.getElementById(id);
	
	if	(!flyingDiv)
	{
		flyingDiv = document.createElement('DIV');
		flyingDiv.style.position = 'absolute';
		flyingDiv.id = id;
		document.body.appendChild(flyingDiv);
	}
	
	var productElm 	= document.getElementById('productDiv_' + productId);
	var productTop 	= shoppingCart_getTopPos(productElm);
	var productLeft = shoppingCart_getLeftPos(productElm);
	
	flyingDiv.innerHTML = productElm.innerHTML;
	
	flyingDiv.style.top 	= productTop;
	flyingDiv.style.left 	= productLeft;
	
	Fly2CartAction (id,productTop,productLeft);
}

function Fly2CartAction (flyingDiv,productTop,productLeft)
{
	var productElm 	= document.getElementById(flyingDiv);
	
	if(!productTop) productTop = 0;
	if(!productLeft) productLeft = 0;
	
	productElm.style.top 	= productTop;
	productElm.style.left 	= productLeft;
	
	if	(productTop > 0 && productLeft > 0)
	{
		setTimeout("Fly2CartAction('"+flyingDiv+"',"+(productTop-5)+","+(productLeft-15)+")",1);
	}
	else
	{
		productElm.style.display = 'none';
	}
}