var x,y,w,h,wh,ww,wy,i,el;
var Maxzindex=1;
var timer=null;
var press=false;
var gogo=false;
var menus=13;
var antiIE=20;
var menu=new Array();
function showdiv(name)
{
	if (gogo==false) { return; }
	for (i=1;i<=menus;i++)
		{ hidediv('menu'+i); }
	el=document.getElementById(name);
	el.style.visibility='visible';
	el.style.display='block';
	updiv(name);
}
function updiv(name)
{
	if (gogo==false) { return; }
	el=document.getElementById(name);
	el.style.zIndex=Maxzindex++;
	press=true;
	for (i=1;i<=menus;i++)
		{ menu[i]=false; }
}
function hidediv(name)
{
	if (gogo==false) { return; }
	el=document.getElementById(name);
	el.style.zIndex=-1;
	el.style.visibility='hidden';
//	el.style.display='none';
}
function getPos(name) 
{
    el=document.getElementById(name);
	x=0;y=0;
	w=el.offsetWidth;
	h=el.offsetHeight;
    while(el.offsetParent != null && el.tagName != 'BODY') 
	{
        x += el.offsetLeft;
        y += el.offsetTop;
        el = el.offsetParent;
    }
}
function position(name,xx,yy)
{
	el=document.getElementById(name);
	el.style.visibility='visible';
	el.style.display='block';
	el.style.left=Math.max(Math.min(xx, ww-el.offsetWidth-antiIE), 0);
	el.style.top=Math.max(Math.min(yy, wh-el.offsetHeight-wy-antiIE), 0);
//	el.style.display='none';
	el.style.visibility='hidden';
	el.style.zIndex=1;
}
function onload()
{
	if (document.getElementById)
		{ gogo=true; }
	else
		{ return 0; };		
	ww=(window.innerWidth)?window.innerWidth:((document.all)?document.body.offsetWidth:0);
	wh=(window.innerHeight)?window.innerHeight:((document.all)?document.body.offsetHeight:0);
	railways=false;
	roads=false;
	docks=false;
	airports=false;
	trees=false;
	getPos('lastbutton');
	wy=y+h;
	getPos('name');
	wh=wh-h;
	getPos('railway');
	position('railway',Math.random()*(ww-w),Math.random()*(wh-wy-h)+wy);
	hidediv('railway');
	getPos('monorail');
	position('monorail',Math.random()*(ww-w),Math.random()*(wh-wy-h)+wy);
	hidediv('monorail'); 
	getPos('maglev');
	position('maglev',Math.random()*(ww-w),Math.random()*(wh-wy-h)+wy);
	hidediv('maglev');
	getPos('road');
	position('road',Math.random()*(ww-w),Math.random()*(wh-wy-h)+wy);
	hidediv('road');
	getPos('dock');
	position('dock',Math.random()*(ww-w),Math.random()*(wh-wy-h)+wy);
	hidediv('dock');
	getPos('airport');
	position('airport',Math.random()*(ww-w),Math.random()*(wh-wy-h)+wy);
	hidediv('airport');
	getPos('tree');
	position('tree',Math.random()*(ww-w),Math.random()*(wh-wy-h)+wy);
	hidediv('tree');
	for (i=1;i<=menus;i++)
	{ 
		getPos('menub'+i); 
		y+=h;
		position('menu'+i,x,y);
		hidediv('menu'+i);
	}
	control();
}
function control()
{
	if (press==false)
	{
		for (i=1;i<=menus;i++)
		{
			if (menu[i]==false)
				{ hidediv('menu'+i); };
		}
	}
	else
	{
		press=false;
	}
	timer=setTimeout("control();",1000);	
}
