var childs=new Array(null);
var holder;
var lastpic=null;
layerCount=0;
lastvisible="";
showed=false;
onemore=false;
nn = (document.layers)?true:false;
ie = (document.all)?true:false;
function change(obj,pic) { obj.src=pic; }
function getID() { return "yxLayer"+(++layerCount)+""; }
function currID() { return layerCount; }
function CreateRoot()
{
  var _holder=null;
  if (ie) {
    var layerID=getID();
	width = window.document.body.clientWidth/2;
	height = window.document.body.clientHeight;
    document.body.insertAdjacentHTML("BeforeEnd",('<div id="'+layerID+'" style="position:absolute; left:0; top:0; width:'+width+'; background-color:white; height:0; visibility:visible; z-index:0;"></div>'));
    _holder=document.all[layerID];
    _holder.css=_holder.style;
  }
  else {
    _holder=new Layer(1);
    _holder.zIndex=100;
    _holder.visibility="visible";
    _holder.left=0; _holder.top=0;
	_holder.bgcolor = "Green";
	_holder.resizeTo(226,20);
    _holder.css=_holder;
  }
  return _holder;
}

function makeLay(_holder,layerID,_x,_y,_width,_content,_color) {
  if(_holder)
    _holder.insertAdjacentHTML("BeforeEnd",(_content));
}

function makeLayer(_holder,_x,_y,_width,_content,_color,vs) {
  var layer=null;
  _index=layerCount;
    layerID=getID();
  if (ie) {
    _holder.insertAdjacentHTML("BeforeEnd",('<div id="'+layerID+'" style="position:absolute; left:'+_x+'; top:'+_y+'; width:'+_width+((_color!="")?('; background-color:'+_color):"")+'; visibility:visible; z-index:'+_index+';">'+_content+'</div>'));
    layer=_holder.document.all[layerID];
    layer.css=layer.style;
  }
  else {
    layer=new Layer(_width,_holder);
    layer.zIndex=_index;
    layer.visibility=vs;
    layer.left=_x; layer.top=_y;
    with (layer.document) {
      open(); writeln(_content); close();
    }
    if (_color!="") { layer.bgColor=_color; }
//	alert(layer.name);
    layer.css=layer;
  }
  return layer;
}
function check(e)
{
  if(ie)
  {
    obj=document.elementFromPoint(event.x,event.y);if (obj.id) ShowLayer(obj.id); else if(lastvisible) hidelayer();
  }
  else
  {
    if(onemore){onemore=false;return;}
    if(lastvisible!="")
	{
	 x=e.pageX;
	 y=e.pageY;
	 hx=holder.left+childs[lastvisible].left;
	 hw=hx+childs[lastvisible].document.width;
	 hy=holder.top;
	 hh=hy+childs[lastvisible].document.height+20;
//	 alert(x+"="+hx+";"+x+"="+hw+";"+y+"="+hy+";"+y+"="+hh+";res= "+(x>hx && x<hw && y>hy && y<hh));
//	 if(y<(hy+20) && x>(hx+lastpic.width))
	 if(y<(hy+20) && x>(hx+childs[lastvisible-1].document.width))
	   hidelayer();
	 if(x>hx && x<hw && y>hy && y<hh)
	   return;
	 hidelayer();
	}
  }
}
function hidelayer()
{
  if(ie)
  {obj=eval('document.all.d'+lastvisible);obj.style.visibility='hidden';}
  else
  {
    childs[lastvisible].visibility="hidden";
	holder.resizeTo(226,20);
	lastvisible="";
  }
}
function ShowLayer(name,obj,pic)
{
  if(ie)
  {
    if(lastvisible!="" && lastvisible!=name)
	{
	  obj=eval('document.all.d'+lastvisible);
	  obj.style.visibility='hidden';
	}
	obj=eval('document.all.d'+name);
	if(obj)
	{
	  obj.style.visibility='visible';
	  lastvisible=name;
	}
  }
/*  if(nn)
  {
    change(obj,pic);
 	lastpic = obj;
   if(lastvisible!="" && lastvisible!=name)
	  hidelayer()
	onemore=true;
    holder.resizeBy(100,childs[name].document.height)
    childs[name].visibility="show";
	lastvisible=name;
  }*/
}
function ShowLayerb(name)
{
  if(nn)
  {
//    change(obj,pic);
//	lastpic = obj;
    if(lastvisible!="" && lastvisible!=name)
	  hidelayer()
	onemore=true;
    holder.resizeBy(100,childs[name].document.height)
    childs[name].visibility="show";
	lastvisible=name;
  }
}
function createmenu(params,path)
{
    absmenux=params[0];
    absmenuy=params[1];
	image=params[2];
	imagelink=params[3];
	if (path!="")
	  image1=path+image;
	else
	  image1="img/"+image;
    layerID=getID();
	if(ie)
	{
	  menu='<div style="position:absolute; background-color:black; top:'+absmenuy+'; left:'+absmenux+'; visibility:visible;"><a class=noline href='+imagelink+'><img name='+image+' id='+layerID+' src="'+image1+'.gif" height=12 border=0></a></div>';
//	  menu='<div id='+layerID+' style="position:absolute;height:20; top:'+(absmenuy+2)+'; left:'+absmenux+'; visibility:visible;"><a class=noline href='+imagelink+'><p id='+layerID+' class=menutext>'+image+'</p></a></div>';
//	  menu=''
      menu=menu+'<div id="d'+layerID+'" style="filter:alpha(opacity=100); position:absolute;width:150; top:'+(absmenuy+12)+'; left:'+absmenux+'; visibility:hidden;"><table  width=100% cellpadding=0 border=0 cellspacing=0>';
	  for(i=4;i<params.length;i+=2)
	  {
	    menu=menu+'<tr bgcolor="#294881"><td id="'+layerID+'">&nbsp;</td><td id="'+layerID+'"><a class=fnt id="'+layerID+'" href="'+params[i+1]+'">'+params[i]+'</a></td></tr>';
	  }
	  menu=menu+'<tr bgcolor="#294860"><td colspan=2><img width=200 height=8 border=0 alt=0></td></tr></table></div>';
	  makeLay(holder,layerID,absmenux,absmenuy,200,menu,"");
	}
	else
	{
	  next=childs.length;
	  nextn=next+1;
//	  header='<a href='+imagelink+' onmouseover="javascript:ShowLayer('+nextn+',document.'+image+',\''+image1+'_.gif\')" onmouseout="javascript:change(document.'+image+',\''+image1+'.gif\')"><img name='+image+' src="'+image1+'.gif" height=20 border=0></a>';
	  header='<table height=20 cellspacing=0 cellpadding=0 border=0><tr><td valign=middle><a href='+imagelink+' onmouseover="javascript:ShowLayerb('+nextn+')"><p class=menutextnn>'+image+'</p></a></td></tr></table>';
//      childs[next]=new makeLayer(holder,absmenux-100,absmenuy-62,150,header,"","show");
      childs[next]=new makeLayer(holder,absmenux,absmenuy,150,header,"","show");

	  next=childs.length;
	  menu="";
      menu=menu+'<table  width=100% cellpadding=0 border=0 cellspacing=0>';

	  for(i=4;i<params.length;i+=2)
	  {
	    menu=menu+'<tr bgcolor="#294881"><td>&nbsp;&nbsp;</td><td><a class=fnt href="'+params[i+1]+'">'+params[i]+'</a></td></tr>';
	  }

	  menu=menu+'<tr bgcolor="#294881"><td colspan=2><img width=150 height=8 border=0 alt=0></td></tr></table></div>';
//      childs[next]=new makeLayer(holder,absmenux-100,absmenuy-42,150,menu,"","hidden");
      childs[next]=new makeLayer(holder,absmenux,absmenuy+20,150,menu,"","hidden");
	}
}
function start()
{
  if(holder)holder.destroy;
  holder=CreateRoot();

  if(nn)
  {
    if(window.innerWidth>770)
	  holder.moveTo(((window.innerWidth-770)/2)+369,(window.innerHeight/2)-228);
	else if(window.innerWidth==770)
	  holder.moveTo(369,(window.innerHeight/2)-228);
	else
	  holder.moveTo(377,(window.innerHeight/2)-228);
/*
    if(window.innerWidth==770)
	  holder.moveTo(377,62);
	else if(window.innerWidth<770)
	  holder.moveTo(377,74);
	else
	  holder.moveTo(((window.innerWidth-770)/2)+377,(window.innerHeight/2)-228);
*/
  }
  StartMenu();
  if(ie)
  {
/*    holder.style.pixelTop = maindiv.offsetTop;
    holder.style.pixelLeft = ((maindiv.offsetWidth - 770) / 2) + 376; */
    document.body.onmousemove=check;
  }
  else
  {
	window.captureEvents(Event.MOUSEMOVE);
	window.onmousemove=check;
  }
}