var SKU_IDs = Array();

function Scroll_To(StartX, StartY, EndX, EndY, Percent)
{
	var NewPercent = Percent + 10;
	window.scrollTo(StartX + (EndX - StartX) * (NewPercent / 100), StartY + (EndY - StartY) * (Percent / 100));
	if (NewPercent < 100)
	{
		setTimeout("Scroll_To(" + StartX + ", " + StartY + ", " + EndX + ", " + EndY + ", " + NewPercent + ")", 10);
	}
}


// Initialize animation variables
var Paused =  Array();
var Current_Left = Array();
var Current_Top = Array();
var Current_Direction = Array();
var Time_By = Array();
var Time_By_Speed = Array();

function Start_Vanita_Phone_Company()
{


	
	// Randomly generate animation start positions and other variables
	for ( SKU_Index = 0; SKU_Index  < 6; SKU_Index ++)
	{
		Paused[SKU_Index] = false;
		Current_Left[SKU_Index] = Math.round(Math.random() * 3385);
		Current_Direction[SKU_Index] = 1 - (Math.round(Math.random()) * 2);
		Current_Top[SKU_Index] = Math.round(Math.random() * 600);
		Time_By[SKU_Index] = Math.round(Math.random() * 600);
		Time_By_Speed[SKU_Index] = Math.random() * 2 + .3;
		
		Refill_ID = SKU_IDs[Math.floor(Math.random() * SKU_IDs.length)]
		Fill("Flying_SKU_Wrapper_" + SKU_Index, "/SKU/" + Refill_ID + "/Flying_SKU/Raw:SKU_Index=" + SKU_Index);	
	}
	
	//Begin animation thread
	Animate();
}




// Animation timeout function
function Animate()
{
	for ( SKU_Index = 0; SKU_Index  < 6; SKU_Index ++)
	{
		if (!Paused[SKU_Index])
		{
			Flying_SKU_Element = $("Flying_SKU_Wrapper_" + SKU_Index);
			if ( Current_Top[SKU_Index] > 600)
			{
				Flying_SKU_Element.style.display= "none";			
			}
			else
			{
				Flying_SKU_Element.style.display= "block";
			}
			if (Current_Left[SKU_Index] < 0 || Current_Left[SKU_Index] >3385)
			{
				//refill
				Refill_ID = SKU_IDs[Math.floor(Math.random() * SKU_IDs.length)]
				Fill("Flying_SKU_Wrapper_" + SKU_Index, "/SKU/" + Refill_ID + "/Flying_SKU/Raw:SKU_Index=" + SKU_Index);	
				
				// change speed
				Time_By_Speed[SKU_Index] = Math.random()* 2 + .3;
				
				// turn around and reposition
				if (Current_Left[SKU_Index] < 0)
				{
					Current_Direction[SKU_Index] = 1;
					Current_Left[SKU_Index] = 1;
				}
				else
				{
					Current_Direction[SKU_Index]  = -1;
					Current_Left[SKU_Index] = 3385;
				}
		
				Current_Top[SKU_Index] = Math.round(Math.random() * 600);
					
			}
			
			// who knows
			Current_Left[SKU_Index] += Math.round(Time_By_Speed[SKU_Index] * Current_Direction[SKU_Index]);	
			Current_Top[SKU_Index] += Math.round(Math.sin(Time_By[SKU_Index]/100) * 5);
			Flying_SKU_Element.style.left = Current_Left[SKU_Index] + "px";
			Flying_SKU_Element.style.top = Current_Top[SKU_Index] + "px";
			Time_By[SKU_Index] ++;			
		}
	}
	setTimeout("Animate()", 30);
}
	
function Open_Flying_SKU(Flying_SKU_Index)
{ 
	Paused[Flying_SKU_Index] = true;
	$("Flying_SKU_Triangle_" + Flying_SKU_Index).style.display = "none";
	$("Flying_SKU_Triangle_Expanded_" + Flying_SKU_Index).style.display = "block";
}

function Close_Flying_SKU(Flying_SKU_Index)
{
	Paused[Flying_SKU_Index] = false;
	$("Flying_SKU_Triangle_" + Flying_SKU_Index).style.display = "block";
	$("Flying_SKU_Triangle_Expanded_" + Flying_SKU_Index).style.display = "none";
}
	