/*
CrossBrowser Menu ver0.22 [2001112152017]
Copyright 2001 Mugi
mail : mugi@email.ee
site : http://mugi.ca.tc/
*/

var menu=new Array()
var opened=new Array()
var next=new Array()
var hover=new Array()
var menuid=new Array()
var paritm=new Array()
var border=new Array()
var shift=new Array()
var mouse=0
var dir=1
var vert=false
var popup=""
var oflag=0
var pflag=0
var rflag=1
var ie=!!document.all&&navigator.platform=="Win32"
var nn=navigator.appName=="Netscape"&&navigator.appVersion.charAt(0)=="4"
var gk=(navigator.userAgent.match(/Gecko/i)!=null)
if(gk){document.all=document.getElementById}

function changevis(id,visible){
if(ie||gk){
document.all(id).style.visibility=(visible?"inherit":"hidden")
}else
if(nn){
popup.document.layers[id].visibility=(visible?"inherit":"hide")
}
}

top.onresize=window.onresize=new Function("if(!rflag){location.reload()}")

function add(id,txt,loc,msg,par){
if(arguments.length<5){par=msg;msg=null}
var a=paritm[par]||menu
a[id]=new Array()
a[id][0]=txt
a[id][1]=loc
a[id][2]=msg
paritm[id]=a[id]
}

function createlayer(id,z,win){
if(ie){
var r=document.body.createTextRange()
r.collapse(false)
r.pasteHTML("<span id="+id+" style=z-index:"+z+";text-align:left;position:absolute;left:0;top:0;width:1;height:"+h+";visibility:hidden>&nbsp;</span>")
return document.all(id)
}else
if(gk){
var e=document.createElement("div")
e.id=id
e.setAttribute("style","z-index:"+z+";position:absolute;left:0;top:0;height:"+h+";visibility:hidden")
document.body.appendChild(e)
return document.getElementById(id)
}else
if(nn){
var lay=new Layer(w,win)
lay.moveTo(0,0)
lay.resizeTo(window.innerWidth,h)
lay.clip.height=window.innerHeight
lay.document.open()
lay.document.write("")
lay.document.close()
lay.zIndex=z
lay.visibility="hide"
return lay
}
}

window.onload=init
function init(){
if(mouse==1||mouse==0&&ie&&!window.print){mouse=-1}
if(mouse==2&&!(ie&&!window.print)){mouse=0}
if(type!=2){popup=""}
if(type!=0){if(type<0)vert=true;type=1}
if(type==1){document.onmousedown=function(){hoveract(0,null);hidemenu(0,1);if(mouse==1){mouse=-1}}}
if(popup==""){
if(ie||gk){popup=document.body}else
if(nn){popup=window}
}else{
pflag=1
if(ie){
if(popup=="window"){
document.oncontextmenu=function(){event.returnValue=false}
document.onmousedown=showpopup
}else{
document.all(popup).oncontextmenu=function(){event.returnValue=false}
document.all(popup).onmousedown=showpopup
}
}else
if(gk){
if(popup=="window"){
document.onmousedown=showpopup
}else{
document.getElementById(popup).onmousedown=showpopup
}
}else
if(nn){
if(popup=="window"){
document.captureEvents(Event.MOUSEDOWN)
document.onmousedown=showpopup
}else{
document.layers[popup].captureEvents(Event.MOUSEDOWN)
document.layers[popup].onmousedown=showpopup
}
}
popup=createlayer("popup",100,window)
}
comment=createlayer("comment",101,popup)
var s=createmenu("",menu,0,0,0)
showmenu("",0)
if(ie||gk){
document.all(border[0]).style.width=w*s+2+(gk?2:0)
document.all(border[0]).style.height=h*Math.ceil((menuid[""].split("@").length-1)/s)+2
}else
if(nn){
popup.document.layers[border[0]].resizeTo(w*s+2,h*Math.ceil((menuid[""].split("@").length-1)/s)+2)
}
setTimeout("rflag=0",0)
}

function createmenu(a,menu,n,o,p){
var b=false,s,arrow,m=0,hide,show,comm,link,none,over,down
for(var i in menu){
if(i+""!="0"&&i+""!="1"&&i+""!="2"){
b=true
if(menuid[a]==void(0)){menuid[a]=""}
if(type==1&&p==0&&(pflag&&n>0||x+w*n+w>(window.innerWidth||document.body.clientWidth))){m=n;n=0;y+=h}
if(type==1&&p>0&&!pflag&&(dir<0||x+w*(n+1+1)>(window.innerWidth||document.body.clientWidth))){dir=-1}
if(type==0||vert&&p==0){n=0}
if(dir==-1&&x+w*(n-1)<0){dir=1}
if(p==0){a=""}
s=createmenu(a+i,menu[i],n+1*dir*type-dir*(!vert&&!pflag&&type==1&&p==0?1:0),o+(type==0?1:0)+(!vert&&!pflag&&type==1&&p==0?1:0),p+1)
arrow=((p>0||type==0)&&s?ie?"</td><td align=right style=font-size:7px>&gt;&gt;&nbsp;&nbsp;":"<div style=position:relative;text-align:right;font-size:7px;top:-"+font+">&gt;&gt;&nbsp;&nbsp;</div>":"")
hide="hidemenu("+p+");hoveract("+p+",this,"+(menu[i][0]=="---")+");"
show="showmenu('"+a+i+"',"+(p+1)+");"
comm=";changevis(comment.id,false)"+((s||!menu[i][2])?"":";showcomm('"+menu[i][2]+"',"+(ie?"event.clientX":"event.pageX")+","+(ie?"event.clientY":"event.pageY")+")")
link="go('"+menu[i][1]+"');"
none=";void(0)"+(ie||gk?";event.cancelBubble=true":"")
over=((type==1?hide+(s?show:none):none)+comm)
down=(menu[i][0]=="---"?none:hide+(s?(type==1?none:show):link+none))
if(ie){
if(!border[p]){
var r=document.body.createTextRange()
r.moveToElementText(popup)
r.collapse(pflag)
r.pasteHTML("<div id=border"+p+" style=z-index:"+(10+2*p-1)+";font-size:1px;position:absolute;visibility:hidden;width:"+(w+2)+";background:"+bc+"></div>")
border[p]="border"+p
}
var r=document.body.createTextRange()
r.moveToElementText(popup)
r.collapse(pflag)
r.pasteHTML("<table cellspacing=0 cellpadding=0 id="+a+i+" onmouseover=\""+over+"\" onmousedown=\"if(event.button==1){"+down+"}\""+(type==0?" onmouseout=changevis(comment.id,false)":"")+" style=z-index:"+(10+2*p)+";text-align:left;cursor:default;visibility:hidden;overflow:hidden;position:absolute;color:"+fg+";background-color:"+bg+";font-size:"+font+"px;left:"+(x+w*n)+";top:"+(y+h*o)+";width:"+w+";height:"+h+";clip:rect(0,"+w+","+h+",0)><tr valign=middle><td nowrap style=padding-left:"+(2+!type*10*p)+">"+(menu[i][0]=="---"?"<hr width="+(w-4-!type*10*p-4)+">":menu[i][0]+arrow)+"</td></tr></table>")
menuid[a]+="@"+a+i
}else
if(nn){
if(!border[p]){
var lay=new Layer(w,popup)
lay.zIndex=(10+2*p-1)
lay.clip.width=w+2
lay.bgColor=bc
border[p]=lay.id
}
var lay=new Layer(w,popup)
lay.document.open()
lay.document.write(menu[i][0]=="---"?"<hr style=padding-left:"+(2+!type*10*p)+" width="+(w-4-!type*10*p-4)+">":"<table cellspacing=0 cellpadding=0 border=1 height="+(h*2)+"><tr><td width="+w+" valign=middle><a href=# style=font-size:"+font+"px;font-weight:normal;color:"+fg+";text-decoration:none;padding-left:"+(2+!type*10*p)+">"+menu[i][0]+"</a></td>"+((p>0||type==0)&&s?"<td align=right style=font-size:7px;color:"+fg+">&gt;&gt;</td>":"")+"</tr>"
+"<tr><td valign=middle><a href=# style=font-size:"+font+"px;font-weight:normal;color:"+hf+";text-decoration:none;padding-left:"+(2+!type*10*p)+";>"+menu[i][0]+"</a></td>"+((p>0||type==0)&&s?"<td align=right style=font-size:7px;color:"+hf+">&gt;&gt;</td>":"")+"</tr></table>")
lay.document.close()
lay.bgColor=bg
lay.moveTo(x+w*n,y+h*o)
lay.resizeTo(w,h)
lay.clip.width=w
lay.clip.height=h
lay.zIndex=(10+2*p)
lay.visibility="hidden"
lay.captureEvents(Event.CLICK)
lay.onclick=new Function("event",down+";return false")
lay.onmouseover=new Function("event",over)
if(type==0){lay.onmouseout=new Function("changevis(comment.id,false)")}
menuid[a]+="@"+lay.id
}else
if(gk){
if(!border[p]){
var e=document.createElement("div")
e.id="border"+p
e.setAttribute("style","z-index:"+(10+2*p-1)+";position:absolute;visibility:hidden;width:"+(w+2*2)+";background:"+bc)
popup.appendChild(e)
border[p]="border"+p
}
var e=document.createElement("div")
e.innerHTML="<nobr>"+(menu[i][0]=="---"?"<hr size=1 width="+(w-4-!type*10*p)+">":menu[i][0]+arrow)+"</nobr>"
e.id=a+i
e.setAttribute("style","z-index:"+(10+2*p)+";cursor:default;visibility:hidden;overflow:hidden;padding-left:"+(2+!type*10*p)+";padding-top:"+((h-font)/2)+";position:absolute;color:"+fg+";background-color:"+bg+";font-size:"+font+"px;left:"+(x+w*n)+";top:"+(y+h*o)+";width:"+(w-!type*10*p)+";height:"+(h-(h-font)/2))
e.onmouseover=new Function("event",over)
e.onmousedown=new Function("event","if(event.which==1){"+down+"}")
if(type==0){e.onmouseout=new Function("changevis(comment.id,false)")}
popup.appendChild(e)
menuid[a]+="@"+a+i
}
if(p==0){
if(type==0||vert&&p==0){o++}
changevis(nn?lay.id:a+i,true)
n++
}else{
o++
}
}
}
return p==0?m>0?m:n:b
}

function hoveract(n,item,hr){
if(n>0&&!pflag){
if(ie||gk){
hover[0].style.color=fg
hover[0].style.backgroundColor=bg
}else
if(nn){
hover[0].bgColor=bg
if(hover[0].clip.top>0){
hover[0].clip.top=0
hover[0].clip.bottom=h
hover[0].top+=h
}
}
}
if(type==0){
for(var i=0;i<hover.length;i++){
if(hover[i]==item){oflag=1;setTimeout("hover.length="+i+";oflag=0",0);break}
}
}
for(var i=(type==0?0:n);i<hover.length;i++){
if(ie||gk){
hover[i].style.color=fg
hover[i].style.backgroundColor=bg
}else
if(nn){
hover[i].bgColor=bg
if(hover[i].clip.top>0){
hover[i].clip.top=0
hover[i].clip.bottom=h
hover[i].top+=h
}
}
}
if(item&&!hr&&!oflag){
hover[n]=item
if(ie||gk){
hover[n].style.color=hf
hover[n].style.backgroundColor=hb
}else
if(nn){
hover[n].bgColor=hb
hover[n].clip.top=h
hover[n].clip.bottom=h*2
hover[n].top-=h
}
}
}

function showmenu(id,d){
if(!oflag){
var a=menuid[id].split("@")
if(type==0){
shift[d]=new Array()
shift[d][0]=h*(a.length-1)
shift[d][1]=d-1
for(var x=0;x<opened.length;x++){
for(var i=1;i<opened[x].length;i++){
if(ie||gk){
if(parseInt(document.all(opened[x][i]).style.top)>=parseInt(document.all(a[1]).style.top)){
document.all(opened[x][i]).style.top=parseInt(document.all(opened[x][i]).style.top)+shift[d][0]
shift[d][shift[d].length]=opened[x][i]
}
}else
if(nn){
if(document.layers[opened[x][i]].top>=document.layers[a[1]].top){
document.layers[opened[x][i]].moveBy(0,shift[d][0])
shift[d][shift[d].length]=opened[x][i]
}
}
}
}
}
for(var i=1;i<a.length;i++){
changevis(a[i],true)
}
opened[opened.length]=a
if(ie){
document.all(border[d]).style.pixelLeft=document.all(a[1]).style.pixelLeft-1
document.all(border[d]).style.pixelTop=document.all(a[1]).style.pixelTop-1
document.all(border[d]).style.pixelHeight=h*(a.length-1)+2
}else
if(nn){
popup.document.layers[border[d]].moveTo(popup.document.layers[a[1]].left-1,popup.document.layers[a[1]].top-1)
popup.document.layers[border[d]].clip.height=h*(a.length-1)+2
}else
if(gk){
document.getElementById(border[d]).style.left=parseInt(document.getElementById(a[1]).style.left)-1
document.getElementById(border[d]).style.top=parseInt(document.getElementById(a[1]).style.top)-1
document.getElementById(border[d]).style.height=h*(a.length-1)+2
}
changevis(border[d],type==1)
}
}

function hidemenu(depth,m){
depth++
for(var x=shift.length-1;x>=depth;x--){
for(var i=2;i<shift[x].length;i++){
if(ie||gk){
document.all(shift[x][i]).style.top=parseInt(document.all(shift[x][i]).style.top)-shift[x][0]
}else
if(nn){
document.layers[shift[x][i]].moveBy(0,-shift[x][0])
}
}
shift[x].length=0
}
for(var i=depth;i<opened.length;i++){
if(!opened[i])break
for(var a=1;a<opened[i].length;a++){
changevis(opened[i][a],false)
}
changevis(border[i],false)
}
opened.length=depth
if(m&&pflag){
if(nn){
popup.visibility="hide"
popup.moveTo(0,0)
}else{
if(ie||gk){
changevis(popup.id,false)
popup.style.left=0;popup.style.top=0
if(gk){document.onmouseup=null}
}
}
}
changevis(comment.id,false)
}

function showpopup(e){
if(type==1){
hoveract(0,null)
hidemenu(0,1)
}
if((mouse*=(Math.abs(mouse)==1?-1:1))!=-1){
if(ie){
if(mouse!=1&&event.button==2||mouse==1&&event.button==1){
popup.style.left=event.clientX+document.body.scrollLeft
popup.style.top=event.clientY+document.body.scrollTop
popup.style.visibility="visible"
if(mouse==2){rflag=1;event.srcElement.blur();window.blur();setTimeout("setTimeout('self.resizeBy("+document.body.clientWidth+","+document.body.clientHeight+");window.focus();popup.focus();rflag=0',100)",100);self.resizeBy(-document.body.clientWidth,-document.body.clientHeight)}
event.cancelBubble=true
event.returnValue=false
}
}else
if(nn){
if(mouse!=1&&e.which==3||mouse==1&&e.which==1){
popup.moveTo(e.pageX,e.pageY)
popup.visibility="show"
return false
}
}else
if(gk){
if(mouse!=1&&e.which==3||mouse==1&&e.which==1){
document.oncontextmenu=function(){document.oncontextmenu=null;return false}
popup.style.left=e.pageX
popup.style.top=e.pageY
popup.style.visibility="visible"
e.cancelBubble=true
return false
}
}
}
}

function showcomm(html,x,y){
html="<table cellpadding=0 cellspacing=0 bgcolor="+cb+"><tr><td style=color:"+cf+";font-size:"+font+"px nowrap>"+html+"</td></tr></table>"
if(ie||gk){
comment.innerHTML=html
comment.style.left=x+(ie?document.body.scrollLeft:0)+10
comment.style.top=y+(ie?document.body.scrollTop:0)+10
if(ie&&!window.print){
var r=document.body.createTextRange()
r.moveToElementText(comment)
comment.style.width=r.boundingWidth
}
}else
if(nn){
with(comment.document){open();write(html);close()}
comment.pageX=x+10
comment.pageY=y+10
comment.clip.width=comment.document.width
comment.clip.height=comment.document.height
}
changevis(comment.id,true)
}

function go(url){
if(type==1){
hoveract(0,null)
hidemenu(0,1)
if(mouse==1){mouse=-1}
}
url=url.split(";")
if(url.length==1){
location.href=url[0]
}else
if(url[1].charAt(0)=="@"){
top.frames[url[1].substring(1)].location.href=url[0]
}else
if(url[1].charAt(0)=="*"){
window.open(url[0],url[1].substring(1))
}else
top.location.href=url[0]
}
