window.onload=load;

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function GetTopLeft(elmId)

{

var x, y = 0;

var elm=document.getElementById(elmId);

//set x to elm’s offsetLeft
x = elm.offsetLeft;


//set y to elm’s offsetTop
y = elm.offsetTop;


//set elm to its offsetParent
elm = elm.offsetParent;


//use while loop to check if elm is null
// if not then add current elm’s offsetLeft to x
//offsetTop to y and set elm to its offsetParent 

while(elm != null)
{

x = parseInt(x) + parseInt(elm.offsetLeft);
y = parseInt(y) + parseInt(elm.offsetTop);
elm = elm.offsetParent;
}

//here is interesting thing
//it return Object with two properties
//Top and Left 

return {Top:y, Left: x}; 

}

var x=0;
var van;
var start;

function load()
{
	//Page finished loading...  Lets start the JavaScript magic!
	
	//First, we'll gather the van's element
	van=document.getElementById("van");

	//Only proceed if the van element exists
	if (!van) return;

	//Setup the van's standard data
	van.style.width="244px";
	van.style.height="141px";
	van.style.visibility="hidden";
	
	//Start the process
	van.load=start_animate();
}

function start_animate()
{
	van.style.visibility="visible";
	
	//Then, calculate where we want the van to start animating from
	var start=van.offsetWidth+(f_clientWidth()/2)+10;

	//Now set the van's top speed before van starts slowing down
	x=0;
	speed=0;
	while (x<start)
	{
		speed+=1;
		x+=speed;
	}

	//All set and ready to go...  Move the van to its starting position
	van.style.left="-"+x+"px";
	
	//Start the animation process!
	animate();
}

function animate()
{
	//Move the van forwards accoring to current speed
	x-=speed;
	
	//Slow the speed down ready for the next animate call
	speed-=1;

	//If van not yet in its finishing position, set the timer ready for the next frame
	if (x>0) setTimeout('animate()',100); else x=0;

	//Reposition van according to its new current position
	van.style.left="-"+x+"px";
}

