var isNetscape=false;
var isNS4 = false;
//typeOfCursor="hand";
if (navigator.appName=='Netscape'){isNetscape = true;if (navigator.product!='Gecko'){isNS4=true;}else{document.all=document.getElementsByTagName('*');}}
var agent=navigator.userAgent
var opera=(agent.indexOf("Opera")!=-1)?true:false
var isNS61 = isNetscape? ((parseInt(navigator.productSub)<=20021119)?true:false) : false
var ie5gt = (navigator.appVersion.indexOf("MSIE 5.0")>0 || (!document.getElementById&&document.all) )? false: true
var mDS={
	color:{
		normal:"#fff",
		hover:"#fff",
		selected:"#fff"
	},
	bgColor:{
		normal:"#515151",
		hover:"#2563ac",
		selected:"#515151"
	},
	font:{
		family:"Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif",
		size:11,
		weight:"normal",
		style:"normal"
	},
	padding:{
		vertical:2,
		left:6
	},
	border:{
		width:1,
		color:"#000"
	},
	separator:{
		width:1,
		color:"#000"
	}//,
//	submenu:{
//		img:"/images/navigate/arrow.gif",
//		imghi:"/images/navigate/arrow.gif",
//		width:7,
//		height:7
//	}//,
//	nosubmenu:{
///		img:"/images/empty.gif",
//		imghi:"/images/empty.gif",
//		width:0,
//		height:0
//	}
}

function MeMenu(label, width, x, y, style, doHide, onHide ) {
	this.parent = null
	this.items = new Array()
	
	this.label=label
	this.width=width||100
	this.height=0
	style=style||mDS;
	if(!style.padding)style.padding={}
	style.padding.vertical=style.padding.vertical||(mDS.padding&&mDS.padding.vertical)||0;
	style.padding.vertical=style.padding.left||(mDS.padding&&mDS.padding.left)||0;
	if(!style.border)style.border={}
	style.border.width=style.border.width||(mDS.border&&mDS.border.width)||0;
	if(!style.separator)style.separator={}
	style.separator.width=style.separator.width||(mDS.separator&&mDS.separator.width)||0;
	if(!style.submenu)style.submenu={}
	style.submenu.width=style.submenu.width||(mDS.submenu&&mDS.submenu.width)||0;
	style.submenu.imghi=style.submenu.imghi||style.submenu.img
	if(!style.nosubmenu)style.nosubmenu={}
	if(style.nosubmenu.img&&!style.nosubmenu.imghi)style.nosubmenu.imghi=style.nosubmenu.img
	this.style=style
	this.doHide=doHide
	this.onHide=onHide||null
	this.px=x||0
	this.py=y||0
	
	if (!window.MeMenus) window.MeMenus=[]
	this.menuId=window.MeMenus.length
	window.MeMenus[window.MeMenus.length]=this
	
	this.addItem=function(label, click, isCurrent) {
		var ii={}
		ii.menu=this
		ii.label=label
		ii.click=click||""
		isCurrent=isCurrent||false
		ii.ncolor=isCurrent?this.style.color.selected:this.style.color.normal
		ii.nbgcolor=isCurrent?this.style.bgColor.selected:this.style.bgColor.normal
		
		if (label.items) {
			ii.hasSubmenu=true
			ii.hasSImage=true
			ii.label=label.label
			label.parent=ii
			ii.submenu=label
		} else {
			ii.hasSubmenu=false
			ii.hasSImg=this.style.nosubmenu.img!=null
			ii.label=label
			ii.submenu=null
		}
		ii.isSeparator=false
		var ind=this.items.length
		ii.ind=ind
		this.items[ind]=ii
	}

	this.menuOn=function(ev, rightClick) {
		clearTimeout(memeTimeout)
		var m=this
		if (m.root!=MeMeRootHi) memeHideAll(m.root)
		MeMeRootHi=m.root
		if (ev != null) {
			if (rightClick && ev.button!=2) return true
			var cy=ev.clientY+m.py+m.height
			cy=(cy>document.body.clientHeight)?(document.body.clientHeight-cy-2):0
			var cx=ev.clientX+m.px+m.width;
			cx=(cx>document.body.clientWidth)?(document.body.clientWidth-cx-2):0
			m.cont.style.left=ev.clientX+document.body.scrollLeft+m.px+cx+"px"
			m.cont.style.top=ev.clientY+document.body.scrollTop+m.py+cy+"px"
		}
		m._activateMenu()
		clearTimeout(memeTimeout)
		return false
	}

	this.menuOnXY=function(x, y) {
		clearTimeout(memeTimeout)
		var m=this
		if (m.root!=MeMeRootHi) memeHideAll(m.root)
		MeMeRootHi=m.root
		m.cont.style.left=x+"px"
		m.cont.style.top=y+"px"
		m._activateMenu()
		clearTimeout(memeTimeout)
		return false
	}
	
	this.menuOff=function() {
		clearTimeout(memeTimeout)
		memeTimeout=setTimeout("memeHideAll(-1)",this.DefTimeout)
	}

	this.writeMenu=function() {
//		if (!window.MeMenuRoots) window.MeMenuRoots=[]
//		var root=window.MeMenuRoots.length
//		window.MeMenuRoots[root]=[]
		if (!MeMenu.prototype.MeMenuRoots) MeMenu.prototype.MeMenuRoots=[]
		var root=this.MeMenuRoots.length
		this.MeMenuRoots[root]=[]
		this._writeMenu(root)
	}
	
	// private :)

	this._activateMenu=function() {
		this.cont.style.visibility="visible"
		if (this.hilited!=null) memeLo(this.hilited)
	}
	this._leaveItem=function(menuId, it) {
		var m=window.MeMenus[menuId]
		var ii=window.MeMenus[menuId].items[it]
		var hi=m.hilited
		memeTimeout=setTimeout("memeHideAll(-1)",m.DefTimeout)
	}

	this._writeMenu=function(root, xx, yy, zz) {
		var m=this
		var typeOfCursor=isNetscape?"pointer":"hand";
		m.root=root
		this.MeMenuRoots[root][this.MeMenuRoots[root].length]=m
		var x=xx||0
		var y=yy||0
		var z=zz||100
		if (null==m.parent) {
			x=m.px; y=m.py;
		} else {
			x+=m.px; y+=m.py;
		}
		var i, ii, k, kk
		var s=m.style
		var w=m.width + 2*s.border.width
		var hi=2*s.padding.vertical+s.font.size+(s.font.size%2)
		var h=m.items.length*(hi+s.separator.width)-s.separator.width
		m.height=isNS4?(h+2*s.border.width):h
		
		for (i=0; i<m.items.length; ++i) {
			ii=m.items[i]
			if (ii.hasSubmenu) ii.submenu._writeMenu(root, x+w, y+s.border.width + (hi+s.separator.width)*i, z+10)
		}
		
		var container = document.createElement("div")
		container.id = "mecont"+m.menuId
		container.style.position = "absolute"
		container.style.top=y+"px"
		container.style.left=x+"px"
		container.style.width=w+"px"
		container.style.height=(h+2*s.border.width)+"px"
		container.style.visibility=((1==m.doHide)?"hidden":"visible")
		container.style.zIndex=(196+z)
		container.style.backgroundColor="white"
		document.body.appendChild(container)
		
		if (ie5gt && !opera && !isNS61) {
			var iframe=document.createElement("iframe")
			iframe.id="iff"+m.menuId
			iframe.name="iff"+m.menuId
			iframe.frameborder=0
			iframe.src=''
			iframe.style.position="absolute"
			iframe.style.borderWidth=0
			iframe.style.borderStyle="none"
			iframe.style.width=w+"px"
			iframe.style.height=(h+2*s.border.width)+"px"
			iframe.style.zIndex=0+z
			container.appendChild(iframe)
		}
		var borderDiv=document.createElement("div")
		borderDiv.id="border"+m.menuId
		borderDiv.style.position="absolute"
		borderDiv.style.width=w+"px"
		borderDiv.style.height=(h+2*s.border.width)+"px"
		borderDiv.style.backgroundColor=s.border.color
		borderDiv.style.zIndex=(198+z)
		container.appendChild(borderDiv)
		var menuDiv=document.createElement("div")
		menuDiv.id="meins"+m.menuId
		menuDiv.style.position="relative"
		menuDiv.style.top=s.border.width+"px"
		menuDiv.style.left=s.border.width+"px"
		menuDiv.style.width=m.width+"px"
		menuDiv.style.height=h+"px"
		menuDiv.style.backgroundColor=s.separator.color
		borderDiv.appendChild(menuDiv)
	
		for (k=0; k<m.items.length; ++k) {
			kk = m.items[k]
		
			if (kk.isSeparator) {
				menuDiv.innerHTML=ll.label
				continue
			}
			var meitem=document.createElement("div")
			meitem.id="meitem-"+m.menuId+"-"+k
			meitem.onmouseover=function(id,n){return function(){memeOn(id,n)}}(m.menuId,k)
			meitem.onmouseout=function(id,n){return function(){m._leaveItem(id,n)}}(m.menuId,k)
			meitem.oncontextmenu=function(){return function(){return false}}()
			meitem.onclick=function(action){return function(){memeHideAll(-1);eval(action)}}(kk.click)
			meitem.style.position="absolute"
			meitem.style.top=(k*(hi+s.separator.width))+"px"
			meitem.style.left=0
			meitem.style.width=m.width+"px"
			meitem.style.height=hi+"px"
			meitem.style.cursor=typeOfCursor
			meitem.style.backgroundColor=kk.nbgcolor
			menuDiv.appendChild(meitem)
			var memeitem=document.createElement("div")
			memeitem.id="memeitem-"+m.menuId+"-"+k
			memeitem.style.position="absolute"
			memeitem.style.top=(s.padding.vertical-2)+"px"
			memeitem.style.left=s.padding.left+"px"
			memeitem.style.width=m.width+"px"
			memeitem.style.color=kk.ncolor
			memeitem.style.fontSize=s.font.size+"px"
			memeitem.style.fontFamily=s.font.family
			memeitem.style.fontWeight=s.font.weight
			memeitem.style.fontStyle=s.font.style
			meitem.appendChild(memeitem)
			memeitem.innerHTML=kk.label
			var meimg
			if (kk.hasSImg) {
				var meitem1=document.createElement("div")
				meitem1.id="meitem1-"+m.menuId+"-"+k
				meitem1.onmouseover=meitem1.onmouseover
				meitem1.onmouseout=meitem1.onmouseout
				meitem1.oncontextmenu=meitem1.oncontextmenu
				meitem1.onclick=meitem1.onclick
				meitem1.style.position="absolute"
				meitem1.style.top=(k*(hi+s.separator.width)+s.padding.vertical-2)+"px"
				meitem1.style.left=(m.width-(kk.hasSImg?s.submenu.width:0)+s.border.width)+"px"
				meitem1.style.cursor=typeOfCursor
				menuDiv.appendChild(meitem1)
				meimg=document.createElement("img")
				meimg.alt=''
				meimg.src=(kk.hasSubmenu?s.submenu.img:s.nosubmenu.img)
				meimg.name="meimg-"+m.menuId+"-"+k
				meimg.width=(kk.hasSubmenu?s.submenu.width:(s.nosubmenu.width?s.nosubmenu.width:s.submenu.width))+"px"
				meimg.height=(kk.hasSubmenu?s.submenu.height:(s.nosubmenu.height?s.nosubmenu.height:s.submenu.height))+"px"
				meitem1.appendChild(meimg)
			}
			kk.l=meitem
			kk.l1=memeitem
			kk.img=meimg
			meitem.item=kk
		}
		m.cont = container
	}
	
}
MeMenu.prototype.timeout=null
MeMenu.prototype.DefTimeout=1000

var memeTimeout=null


function memeHi(ii) {
	clearTimeout(memeTimeout)
	ii.l.style.backgroundColor=ii.menu.style.bgColor.hover
	ii.l1.style.color=ii.menu.style.color.hover
	if(ii.hasSImg) ii.img.src=ii.hasSubmenu?ii.menu.style.submenu.imghi:ii.menu.style.nosubmenu.imghi
	ii.menu.hilited=ii
}

function memeLo(ii) {
	ii.l.style.backgroundColor=ii.nbgcolor
	ii.l1.style.color=ii.ncolor
	if(ii.hasSImg) ii.img.src=ii.hasSubmenu?ii.menu.style.submenu.img:ii.menu.style.nosubmenu.img
	ii.menu.hilited=null
	if (ii.hasSubmenu) memeHide(ii.submenu)
}

var MeMeRootHi = null;

function memeOn(menuId, it) {
	var m=window.MeMenus[menuId]
	if (m.root!=MeMeRootHi) memeHideAll(m.root)
	MeMeRootHi=m.root
	var ii=m.items[it]
	var hi=m.hilited
	if (hi!=null) {
		if (ii!=hi && hi.hasSubmenu) memeHide(hi.submenu)
		memeLo(m.hilited)
	}
	memeHi(ii)
	if(m.parent!=null) memeHi(m.parent)
	clearTimeout(memeTimeout)
	if(ii.hasSubmenu) ii.submenu._activateMenu()
}

function memeHide(m) {
	if (1==m.doHide) m.cont.style.visibility="hidden"
	if (m.onHide!=null) eval(m.onHide)
	if (m.hilited!=null) {
		if (m.hilited.hasSubmenu) memeHide(m.hilited.submenu)
		memeLo(m.hilited)
	}
}

function memeHideAll(root) {
	for (var i=0; i<MeMenu.prototype.MeMenuRoots.length; ++i)
		if (i!=root)
			for (var j=0; j<MeMenu.prototype.MeMenuRoots[i].length; ++j)
				memeHide(MeMenu.prototype.MeMenuRoots[i][j])
	MeMeRootHi = null
}
