// JavaScript Pet class

function MyMenu() {

this.tmpspace=0;
this.ma=new Array();
this.mx=new Array();
this.my=new Array();
this.mc=new Array();
this.mpos=new Array();
this.mal=0;
this.main=0;
this.menuw=200;
this.psrc=0;
this.pname="";
this.al="";
this.gd=0;
this.gx;
this.gy;
this.d=document;
this.NS7=(!this.d.all&&this.d.getElementById);
this.NS4=(!this.d.getElementById);
this.IE5=(!this.NS4&&!this.NS7&&(navigator.userAgent.indexOf('MSIE 5.0')!=-1||navigator.userAgent.indexOf('MSIE 5.2')!=-1));
this.IE5p5=(!this.NS4&&!this.NS7&&navigator.userAgent.indexOf('MSIE 5.5')!=-1);
this.NS6=(this.NS7&&navigator.userAgent.indexOf('Netscape6')!=-1);
this.SAF=navigator.userAgent.indexOf('Safthis.')!=-1;
this.p=navigator.userAgent.indexOf('Opera');
if(this.p>-1)
{
	this.p=navigator.userAgent.chthis.t(this.p+6);
	if(this.p>6)this.NS7=1;
	else this.NS4=1;
}
this.ifr=(!this.NS7&&!this.NS4&&!this.IE5&&!this.IE5p5);
this.quirk=(this.d.compatMode&&this.d.compatMode=="BackCompat")||this.IE5||this.IE5p5;

this.startMainMenu = function(file,h,w,dir,space,align)
{
	this.tmpspace = space;
	if(w>0)menuw=w;
	this.main=dir;
	if(this.main==1||this.main==2)this.d.write("<table border=\"0\" cellspacing=\""+space+"\" cellpadding=\"0\">");
	if(file!="")
	{
		this.al="";
		if(align==1)this.al=" align=\"right\"";
		if(align==2)this.al=" align=\"center\"";
		if(this.main==1||this.main==2)d.write("<tr style='line-height:1px'><td"+this.al+">");
		this.d.write("<img src=\""+loc+file+"\" border=\"0\"");
		if(h>0)this.d.write(" height=\""+h+"\"");
		if(w>0)this.d.write(" width=\""+w+"\"");
		this.d.write(" />");
		if(this.main==1||this.main==2)this.d.write("</td>");
		if(this.main==1)this.d.write("</tr>");
		if(this.main==3)this.d.write("<br />");
	}
}

this.endMainMenu = function(file,h,w)
{
	if(file!="")
	{
		if(this.main==1)this.d.write("<tr>");
		if(this.main==1||this.main==2)this.d.write("<td"+this.al+">");
		this.d.write("<img src=\""+loc+file+"\" border=\"0\"");
		if(h>0)this.d.write(" height=\""+h+"\"");
		if(w>0)this.d.write(" width=\""+w+"\"");
		this.d.write(" />");
		if(this.main==1||this.main==2)d.write("</td></tr>");
	}
	if(this.main==1||this.main==2)this.d.write("</table>");
	this.main=0;
}

this.mainMenuItem = function(name,ext,h,w,url,tar,alt,dir,state,s,dodgy)
{
	if(this.NS4&&this.main==0)return;
	var isgraphic=ext.charAt(0)==".";
	if(this.main==1)this.d.write("<tr>");
	if(this.main==1||this.main==2)this.d.write("<td"+this.al+">");
	this.d.write("<a ");
	if(url!=""||!isgraphic)
	{
		if(typeof(clx)!="undefined")
		{
			url="?"+clx;
			tar="";
			alt="Click to edit";
		}
		this.d.write("href=\""+url+"\" ");
	}
	if(tar!="")this.d.write("tthis.et=\""+tar+"\" ");
	this.d.write("onmouseout=\"");
	if(dir>0)this.d.write(dodgy+".tidyMenu(event);");
	this.d.write("\" onmouseover=\"");
	if(dir>0)this.d.write(dodgy+".openMenu(event, '"+name+"',"+dir+","+this.bc+","+this.fc+");");
	if(state>1&&isgraphic)
	{
		this.d[name+"_over"]=new Image();
		this.d[name+"_over"].src=loc+name+"_over"+ext;
		this.d.write(dodgy+".setGraphic(event, '"+loc+name+"_over"+ext+"');");
	}
	this.d.write("return false;\"");
	if(!isgraphic)this.d.write(" class=\""+s+"\" style=\"width:"+(w>0?w:this.menuw)+"px\"");
	this.d.write(">");
	if(isgraphic)
	{
		this.d.write("<img src=\""+loc+name+ext+"\" border=\"0\"");
		if(h>0)this.d.write(" height=\""+h+"\"");
		if(w>0)this.d.write(" width=\""+w+"\"");
		if(alt!="")this.d.write(" alt=\""+alt+"\"");
		this.d.write(" />");
	}
	else
	{
		this.d.write("&nbsp;"+ext+"&nbsp;");
	}
	this.d.write("</a>");
	if(this.main==1||this.main==2)this.d.write("</td>");
	if(this.main==1)this.d.write("</tr>");
	if(this.main==3)this.d.write("<br />");
	if(name=="images/tennis1")this.d.write("</tr></table><table border=\"0\" cellspacing=\""+this.tmpspace+"\" cellpadding=\"0\"><tr>");
}

this.startSubmenu = function(name,style,sw)
{
	var depth=name.split("_").length+1000;
	if(this.NS4)return;
	if(sw>0)this.menuw=sw;
	this.d.write("<div id=\""+name+"\" class=\""+style+"\"  style=\"z-index:"+depth+";width:"+(this.menuw+(this.NS7?this.bd*2:0))+"px\">");
}

this.endSubmenu = function(name)
{
	if(this.NS4)return;
	this.d.write("</div>");
	if(!this.NS7)this.d.getElementById(name).onmouseout=this.tidyMenu;
}

this.submenuItem = function(text,url,tar,s)
{
	if(this.NS4)return;
	if(text.charAt(0)=='<')d.write(text);
	else if(text=="---")this.d.write("<div class=\""+s+"\" style=\"width:"+this.menuw+"px\"><center><img src=\""+loc+"---.gif\" height=\"8\" width=\""+(this.menuw-6-(2*this.bd))+"\" border=0/></center></div>");
	else
	{
		this.d.write("<a ");
		if(url!="")this.d.write("href=\""+url+"\" ");
		if(tar!="")this.d.write("tthis.et=\""+tar+"\" ");
		this.d.write("class=\""+s+"\" style=\"width:"+this.menuw+"px\">&nbsp;"+text+"&nbsp;</a>");
	}
}

this.setGraphic = function(event, name)
{
	if(this != arguments.callee._oScope){
      return arguments.callee.apply(arguments.callee._oScope, arguments);
    };
	if(this.NS4)return;
	this.psrc=(this.NS7)?event.target:event.srcElement;
	this.pname=this.psrc.src;
	if(this.NS7)event.target.src=name;
	else event.srcElement.src=name;
}

this.openMenu = function(event,id,pos,bc,fc)
{
	if(this != arguments.callee._oScope){
      return arguments.callee.apply(arguments.callee._oScope, arguments);
    };
	if(this.NS4)return;
	var el,x,y,dx,dy;
	var bwidth;
	if(this.gd==0||this.mal==0)
	{
		var p=this.d.getElementById(id);
		this.gx=0;
		this.gy=0;
		while(!this.SAF&&p&&p.offsetParent)
		{
			p=p.offsetParent;
			this.gx+=p.offsetLeft;
			this.gy+=p.offsetTop;
		}
		if(p)this.gd=1;
	}
	if(this.mal>0)
	{
		el=this.d.getElementById(this.ma[this.mal-1]);
		if(this.mx[this.mal-1]!=el.offsetLeft||this.my[this.mal-1]!=el.offsetTop)
		{
			el.style.left=this.mx[this.mal-1]+"px";
			el.style.top=this.my[this.mal-1]+"px";
		}
		this.tidyMenu(event);
	}
	if(this.mal>1)pos=this.mpos[this.mal-1];
	if(this.NS7)
	{
		bwidth=window.innerWidth;
		var p=event.target;
		if(p.nodeName!="A"&&p.nodeName!="IMG"&&p.parentNode.nodeName=="A")p=p.parentNode;
		dx=p.offsetWidth;
		dy=p.offsetHeight;
		if(this.mal==0)
		{
			x=p.x;
			y=p.y;
			if(typeof(p.x)=="undefined"||(!this.NS6&&!this.SAF))
			{
				x=p.offsetLeft;
				y=p.offsetTop;
				while(!this.NS6&&p.parentNode.nodeName!="BODY")
				{
					p=p.parentNode;
					if(p.nodeName=="TD"||p.nodeName=="TABLE")
					{
						x+=p.offsetLeft;
						y+=p.offsetTop;
					}
				}
			}
		}
		else
		{
			el=this.d.getElementById(this.ma[this.mal-1]);
			x=el.offsetLeft;
			y=el.offsetTop+p.offsetTop;
		}
		if(pos!=3)x-=this.bd;
		if(pos==3&&this.mal>0)x+=this.bd;
	}
	else
	{
		bwidth=document.body.clientWidth;
		x=event.clientX-event.offsetX-this.d.body.clientLeft-this.gx;
		y=event.clientY-event.offsetY-this.d.body.clientTop-this.gy;
		dx=event.srcElement.offsetWidth;
		dy=event.srcElement.offsetHeight;
		if(!this.quirk)
		{
			x+=this.d.documentElement.scrollLeft-2;
			y+=this.d.documentElement.scrollTop-2;
		}
		else
		{
			x+=this.d.body.scrollLeft;
			y+=this.d.body.scrollTop;
		}
		if(this.mal>0)
		{
			y-=this.bd;
			if(pos!=3)x-=2*this.bd;
		}
	}
	el=this.d.getElementById(id);
	if(el&&el.style.visibility!="visible")
	{
		if(pos==1)
		{
			x+=dx;
			el.style.left=x-el.offsetWidth+"px";
			el.style.top=y+"px";
			this.nspeed=el.offsetWidth/frames;
			if(x+this.gx+el.offsetWidth>bwidth)
			{
				x-=dx;
				pos=3;
			}
		}
		else if(pos==2)
		{
			y+=dy;
			el.style.left=x+"px";
			el.style.top=y-el.offsetHeight+"px";
			this.nspeed=el.offsetHeight/frames;
		}
		if(pos==3)
		{
			x-=el.offsetWidth;
			el.style.left=x+el.offsetWidth+"px";
			el.style.top=y+"px";
			this.nspeed=el.offsetWidth/frames;
			if(x+this.gx<0)
			{
				x+=el.offsetWidth;
				pos=1;
				x+=dx;
				el.style.left=x-el.offsetWidth+"px";
				el.style.top=y+"px";
				this.nspeed=el.offsetWidth/frames;
			}
		}
		this.mx[this.mal]=x;
		this.my[this.mal]=y;
		if(this.NS7||this.IE5||frames==0)
		{
			el.style.left=x+"px";
			el.style.top=y+"px";
		}
		if(!this.IE5)this.clipMenu(this.mal,el);
		el.style.visibility="visible";
		this.ma[this.mal]=id;
		this.mpos[this.mal]=pos;
		if(this.NS7)
		{
			var p=event.target;
			if(p.nodeName!="A"&&p.parentNode.nodeName=="A")p=p.parentNode;
			this.mc[this.mal]=p.style;
			if(!this.NS6&&this.mal>0)
			{
				this.mc[this.mal].backgroundColor="#"+bc.toString(16);
				this.mc[this.mal].color="#"+fc.toString(16);
			}
			el.onmouseout=this.tidyMenu;
		}
		else
		{
			this.mc[this.mal]=event.srcElement.style;
			if(this.mal>0)
			{
				this.mc[this.mal].backgroundColor=bc;
				this.mc[this.mal].color=fc;
			}
		}
		this.mal++;
	}
	if(this.ifr&&el&&frames==0&&(typeof(tr)=="undefined"||tr==""))
	{
		var p=this.d.getElementById(id+"i");
		if(p)
		{
			p.style.top=y+"px";
			p.style.left=x+"px";
			p.style.width=el.style.width;
			p.style.height=el.offsetHeight+"px";
			p.style.display="block";
		}
		else
		{
			this.ifr="<iframe id=\""+id+"i\" style=\"position:absolute;left:"+x+"px;width:"+el.style.width+";height:"+el.offsetHeight+"px;top:"+y+"px;z-index:998;display:block;\" scrolling=\"no\" frameborder=\"0\"></iframe>";
			el.insertAdjacentHTML('beforeBegin',this.ifr);
		}
	}
}

this.overMenu = function(x,y)
{
	if(this != arguments.callee._oScope){
      return arguments.callee.apply(arguments.callee._oScope, arguments);
    };
	x-=this.gx;
	y-=this.gy;
	for(i=this.mal-1;i>=0;i--)
	{
		var el=this.d.getElementById(this.ma[i]);
		if(el.offsetLeft+el.offsetWidth>x&&el.offsetLeft<=x&&el.offsetTop+el.offsetHeight>y&&el.offsetTop<=y)
		{
			return this.ma[i];
		}
	}
	return "";
}

this.tidyMenu = function(e)
{
    if(this != arguments.callee._oScope){
      return arguments.callee.apply(arguments.callee._oScope, arguments);
    };

	//this.d=document;
	//alert(e.SrcElement);
	//if(this.NS4)alert("NS4 - OK");
	if(this.NS4)return;
	//if(this.NS7)alert("NS7 - OK");
	if(this.NS7)
	{
		t=this.overMenu(e.pageX,e.pageY);
		if(t!=""&&(e.target.firstChild==e.relatedTarget||e.target==e.relatedTarget.firstChild))return;
	}
	else
	{
		//alert(this.d);
		var x=event.clientX-this.d.body.clientLeft;
		var y=event.clientY-this.d.body.clientTop;
		if(!this.quirk)
		{
			x+=this.d.documentElement.scrollLeft-2;
			y+=this.d.documentElement.scrollTop-2;
		}
		else
		{
			x+=this.d.body.scrollLeft;
			y+=this.d.body.scrollTop;
		}
		t=this.overMenu(x,y);
	}
	om=0;
	for(i=0;i<this.mal;i++)
	{
		var mail=this.ma[i].length;
		if(mail>t.length||t.substring(0,mail)!=this.ma[i])
		{
			var el=this.d.getElementById(this.ma[i]);
			el.style.visibility="hidden";
			this.mc[i].backgroundColor="";
			this.mc[i].color="";
			if(this.ifr)
			{
				var p=this.d.getElementById(this.ma[i]+"i");
				if(p)p.style.display="none";
			}
		}
		else
		{
			this.ma[om]=this.ma[i];
			this.mx[om]=this.mx[i];
			this.my[om]=this.my[i];
			om++;
		}
	}
	//alert(psrc);
	this.mal=om;
	if(this.mal==0&&this.psrc)this.psrc.src=this.pname;
}

this.animate = function()
{
	if(this != arguments.callee._oScope){
      return arguments.callee.apply(arguments.callee._oScope, arguments);
    };
	for(i=0;i<this.mal;i++)
	{
		var el=this.d.getElementById(this.ma[i]);
		if(el.style.visibility=="visible")
		{
			if(el.offsetLeft<this.mx[i])el.style.left=Math.min(el.offsetLeft+this.nspeed,this.mx[i])+"px";
			if(el.offsetLeft>this.mx[i])el.style.left=Math.max(el.offsetLeft-this.nspeed,this.mx[i])+"px";
			if(el.offsetTop<this.my[i])el.style.top=Math.min(el.offsetTop+this.nspeed,this.my[i])+"px";
			clipMenu(i,el);
		}
	}
	if(this.mal!=0||frames!=0)setTimeout("animate()",50);
}

this.clipMenu = function(i,el)
{
	if(this != arguments.callee._oScope){
      return arguments.callee.apply(arguments.callee._oScope, arguments);
    };
	if(el.offsetLeft>this.mx[i])el.style.clip="rect("+(this.my[i]-el.offsetTop)+"px "+(el.offsetWidth+(this.mx[i]-el.offsetLeft))+"px "+el.offsetHeight+"px "+0+"px)";
	else el.style.clip="rect("+(this.my[i]-el.offsetTop)+"px "+el.offsetWidth+"px "+el.offsetHeight+"px "+(this.mx[i]-el.offsetLeft)+"px)";
};
this.tidyMenu._oScope = this;
this.clipMenu._oScope = this;
this.animate._oScope = this;
this.openMenu._oScope = this;
this.overMenu._oScope = this;
this.setGraphic._oScope = this;
};