function Entry(listname,index,label,x,y,w,lnk,style,target,sublnk,subtarget){
	this.name = listname+index
	this.label = label
	this.x = x
	this.y = y
	this.w = w
	this.lnk = lnk
	this.style = style
	this.target = target
	this.sublnk = sublnk
	this.subtarget = subtarget
	this.enabled = false	
	this.listname=listname
	this.build = EntryBuildCssDiv
	this.activate = EntryActivate
	this.over = EntryOver
	this.out = EntryOut
	this.clk = EntryClick	
	this.moveTo = EntryMoveTo
	this.resize = EntryResize
	this.onclk = new Function()
	this.obj = this.name + "Entry"
	eval(this.obj + "=this")
	this.build()
}
function EntryBuildCssDiv(){
	var alignment = 'text-align:' + this.style.txtalign 
	this.css = css(this.name + 'off',this.x,this.y,this.w,null,this.style.bgoffcolor,null,null,alignment)
	this.css += css(this.name+'on',this.x,this.y,this.w,null,this.style.bgoncolor,null,null,alignment)
	this.div = '<div id="' + this.name + 'on"><a href="#" class="'+this.listname+'on" onMouseOver="'+this.obj+'.over()" onMouseOut="'+this.obj+'.out()" onClick="'+this.obj+'.clk()">' + this.label + '</a></div>\n'
	this.div += '<div id="' + this.name + 'off"><a href="#" class="'+this.listname+'off" onMouseOver="'+this.obj+'.over()" onMouseOut="'+this.obj+'.out()" onClick="'+this.obj+'.clk()">'+ this.label + '</a></div>\n'
}
function EntryActivate(){
	this.lyroff = new DynLayer(this.name + 'off')
	this.lyron = new DynLayer(this.name+'on')	
	this.h = (is.ns)?this.lyroff.doc.height:this.lyroff.elm.scrollHeight
	this.enabled = true	
}
function EntryResize(w){
	this.w=w
	this.lyroff.resize(w)
	this.h = this.lyroff.h
	this.lyron.resize(w)
}
function EntryOver(){
	if (this.enabled){
		this.lyroff.hide()
		this.lyron.inherit()
	}
}
function EntryOut(){
	if (this.enabled){
		this.lyron.hide()
		this.lyroff.inherit()
	}			
}
function EntryClick(){
	if (this.enabled){
		if (this.lnk !=null) {
			if (this.target != null && eval(this.target)) eval(this.target+'.location.href="'+this.lnk+'"') 
			else location.href = this.lnk
		}	
		if (this.sublnk !=null) {
			if (this.subtarget != null && eval(this.subtarget)) eval(this.subtarget+'.location.href="'+this.sublnk+'"') 
			else location.href = this.sublnk
		}	
		this.onclk()
		this.enabled = false
	}
}
function EntryMoveTo(x,y){
	this.lyron.moveTo(x,y)
	this.lyroff.moveTo(x,y)	
	this.x = x
	this.y = y
}
function List(name,x,y,w,distance,maxh,border){
	this.name = name
	this.x = x
	this.y = y
	this.w = w
	this.maxh = maxh
	this.distance = distance
	this.containernum = 0
	this.child = null
	this.mother = null
	this.entries = new Array()
	this.style = new Object()
	this.style.fontname = 'Verdana'
	this.style.fontsize = '1'
	this.style.bgoncolor = null
	this.style.bgoffcolor = null
	this.style.txtoncolor = '#CC0000'
	this.style.txtoffcolor = '#666666'
	this.style.txtalign = 'left'
	this.border = border	
	this.add = ListAddEntry
	this.build = ListBuildCssDiv
	this.activate = ListActivate
	this.clk = ListClk
	this.reset = ListReset
	this.resize = ListResize
	this.defaultentry = ListDefault
	this.onclk = new Function()
	this.setstyle = ListSetStyle
	this.obj = this.name + "List"
	eval(this.obj + "=this")
}
function ListSetStyle(fontname,fontsize,bgoncolor,bgoffcolor,txtoncolor,txtoffcolor,txtalign){
	if (arguments.length>=1 && fontname!=null) this.style.fontname = fontname
	if (arguments.length>=2 && fontsize!=null) this.style.fontsize = fontsize
	if (arguments.length>=3 && bgoncolor!=null) this.style.bgoncolor = bgoncolor
	if (arguments.length>=4 && bgoffcolor!=null) this.style.bgoffcolor = bgoffcolor
	if (arguments.length>=5 && txtoncolor!=null) this.style.txtoncolor = txtoncolor
	if (arguments.length>=6 && txtoffcolor!=null) this.style.txtoffcolor = txtoffcolor
	if (arguments.length>=7 && txtalign!=null) this.style.txtalign = txtalign
}
function ListAddEntry(label,lnk,ismother,sublnk){
	var i = this.entries.length
	var indent = (this.indent != null)? this.indent : 0 
	this.entries[i] = new Entry(this.name,i,label,0,0,this.w-indent,lnk,this.style,this.target,sublnk,this.subtarget)
	if (ismother) {		
		this.containernum++
		this.entries[i].ismother = true
	}	
}
function ListBuildCssDiv(){
	var fontstyle = 'font-family:'+this.style.fontname+'; font-size:'+this.style.fontsize+'em;font-weight: bold;'
	this.css = ''
	var str = ''	
	var vis= 'inherit'
	if (this.border >=1){
		var indent = (this.indent != null)? this.indent : 0 
		this.css += css(this.name+'borderlyr',0,0,this.w-(indent/2),this.maxh,'#999999')
		this.css += css(this.name+'borderlyr1',0,0,this.w-(indent/2)-this.border,this.maxh,'#FFCCCC')
		str = '<div id="'+this.name+'borderlyr"><div id="'+this.name+'borderlyr1">'
		vis= 'hidden'
	}	
	this.css += css(this.name,this.x,this.y,this.w,this.maxh,this.style.bg,vis,null,fontstyle)	
	this.css += '.'+this.name+'on {color:'+this.style.txtoncolor+'}\n'
	this.css += '.'+this.name+'off {color:'+this.style.txtoffcolor +'}\n'
	this.divs = new Array()
	this.divs[0] = new Object()
	this.divs[0].id = 0
	this.divs[0].content = '<div id="'+this.name+'">\n' + str
	var bg = (this.style.bgoffcolor != null)? this.style.bgoffcolor : '#FFCC00'
	for (var i=0;i<this.entries.length;i++) {
		this.css += this.entries[i].css			
		var j = this.divs.length
		this.divs[j-1].content += this.entries[i].div
		if (this.entries[i].ismother) {			
			this.css += css('container'+i,this.entries[i].x,this.entries[i].y,this.w,this.maxh,bg)
			this.divs[j] = new Object()
			this.divs[j].id = i
			this.divs[j].content = '<div id="container'+i+'">\n'
		}		
	}	
	for (var i=0;i<this.containernum;i++) {
		this.divs[this.divs.length-1].content += '</div>\n'
	}
	if (str != '') this.divs[this.divs.length-1].content += '</div></div></div>'
	else this.divs[this.divs.length-1].content += '</div>'
}
function ListResize(w){
	var y 
	var resety
	this.w = w	
	this.lyr.resize(this.w)
	this.h = 0
	for (var i=0;i<this.entries.length;i++) {		
		if (this.mother != null) this.entries[i].resize(this.w-this.indent)
		else this.entries[i].resize(this.w)
		if (i>0 && !resety) y = this.entries[i-1].y + this.entries[i-1].h + this.distance
		else {
			y = this.distance
			resety = false
		}	
		this.entries[i].moveTo(null,y)		
		if (this.entries[i].ismother) {			
			eval("this.container" +i+".resize("+this.w+","+this.maxh+")")
			y = this.entries[i].y+this.entries[i].h
			eval("this.container" +i+".moveTo("+null+","+y+","+this.maxh+")")
			resety=true
		}	
		this.h += this.entries[i].h + this.distance
	}
	if (this.mother != null && this.border >=1){
		var indent = (this.indent != null)? this.indent : 0 
		var tempw =  this.w-(indent/2)
		eval("this.borderlyr.resize("+tempw+","+this.h+")")
		tempw =  tempw-this.border
		eval("this.borderlyr1.resize("+tempw+","+this.h+")")
	}		
}
function ListActivate(){
	var y 
	var resety
	this.lyr = new DynLayer(this.name)	
	this.h = 0 
	for (var i=0;i<this.entries.length;i++) {
		this.entries[i].activate()
		if (i>0 && !resety) y = this.entries[i-1].y + this.entries[i-1].h + this.distance
		else {
			y = this.distance
			resety = false
		}	
		this.entries[i].moveTo(null,y)
		this.entries[i].onclk = new Function(this.obj+'.clk('+i+'); return false;')	
		if (this.entries[i].ismother) {
			eval("this.container" +i+"= new DynLayer('container" +i+"')")
			y = this.entries[i].y+this.entries[i].h
			eval("this.container" +i+".moveTo("+null+","+y+")")
			resety=true
		}	
		this.h += this.entries[i].h + this.distance
	}		
	if (this.border >=1){
		var indent = (this.indent != null)? this.indent : 0 
		this.borderlyr = new DynLayer(this.name+'borderlyr')	
		this.borderlyr1 = new DynLayer(this.name+'borderlyr1')	
		this.borderlyr.clipTo(0,this.w-(indent/2),this.h,0)
		this.borderlyr1.clipTo(0,this.w-(indent/2)-this.border,this.h,0)
	}	
}	

function ListReset(i){
	var y = eval("this.entries[" +i+"].y") + eval("this.entries[" +i+"].h")
	eval("this.container" +i+".moveTo(null,"+y+")")
}
function ListClk(entry){
	if (this.activeentry != null) {
		this.entries[this.activeentry].enabled = true
		this.entries[this.activeentry].out()
	}	
	this.activeentry = entry
	this.onclk()	
}
function ListDefault(entry){
	this.entries[entry].over()
	this.entries[entry].clk()
}
function Menu(name,x,y,w,h,distance,indent,target,subtarget,marginW){
	this.name = name
	this.x = x
	this.y = y
	this.w = w
	this.h = h
	this.distance = distance 
	this.indent = indent
	this.target = target
	this.subtarget = subtarget
	this.inc = 5
	this.speed = 20
	this.lists = new Array()
	this.mother = null
	this.marginW= (marginW!=null) ? marginW : 0
	this.add = MenuAdd
	this.build = MenuBuildCssDiv 
	this.activate = MenuActivate
	this.clk = MenuClk	
	this.collapse = MenuCollapse
	this.shrink = MenuShrink
	this.resize = MenuResize
	this.getdiv = MenuGetDiv
	this.sfinish = MenuSFinish
	this.cfinish = MenuCFinish
	this.start = MenuStart
	this.stop = MenuStop
	this.obj = this.name + "Menu"
	eval(this.obj + "=this")	
}
function MenuAdd(mother,motherentry,distance,border){
	var i = this.lists.length
	var dvar = (distance != null)? distance : this.distance
	if (mother !=null && motherentry != null){
		this.lists[i] = new List(this.name+i,0,0,this.w-this.marginW,dvar,this.h,border)
		this.lists[i].indent = this.indent
		this.lists[i].mother = mother
		this.lists[i].motherentry = motherentry
		this.lists[mother].ismother = true
		this.lists[mother].entries[motherentry].child = this.lists[i]
	} else{
		this.lists[i] = new List(this.name+i,0,0,this.w,dvar,this.h)
	}	
	this.lists[i].target = this.target
	this.lists[i].subtarget = this.subtarget
}
function MenuBuildCssDiv(){
	this.css = css(this.name,this.x,this.y,this.w-this.marginW,this.h,'#FFCC00')
	this.css += css(this.name+'canvas',0,0,this.w-this.marginW,this.h,'#FFCC00')
	this.div = '<div id="'+this.name+'">\n'
	for (var i=0;i<this.lists.length;i++) {
		this.lists[i].build()
		this.css += this.lists[i].css
	}	
	this.getdiv(this.lists[0])	
	this.div += '<div id="'+this.name+'canvas">\n</div>'
	this.div += '</div>'
	
}
function MenuGetDiv(list){
	this.div += list.divs[0].content
	for (var j=1;j<list.divs.length;j++) {		
		if (list.entries[list.divs[j].id].child != null) this.getdiv(list.entries[list.divs[j].id].child)
		this.div += list.divs[j].content
	}
}
function MenuActivate(){
	for (var i=0;i<this.lists.length;i++) {		
		this.lists[i].activate()
		if (this.lists[i].mother != null) {
			var y = this.lists[this.lists[i].mother].entries[this.lists[i].motherentry].y  + this.lists[this.lists[i].mother].entries[this.lists[i].motherentry].h
			this.lists[i].lyr.moveTo(null,y)
		}
		this.lists[i].onclk = new Function(this.obj+'.clk('+i+'); return false;')			
	}	
	this.lyr = new DynLayer(this.name)	
	this.canvas = new DynLayer(this.name+'canvas')	
	//if (is.ie) this.resize(1)
	this.canvas.slideTo(null,this.lists[0].h,this.inc,this.speed,this.obj+'.start()')	
}
function MenuStart(){
	this.canvas.hide()
	//this.lists[0].defaultentry(0)
}
function MenuClk(list){
	var clickedentry = this.lists[list].entries[this.lists[list].activeentry]
	if (this.collapsing || this.shrinking) this.stop()
	if (clickedentry.child != null && clickedentry.child != this.activelist){	
		if (this.activelist != null && this.activelist.mother == list) this.shrink(list)	
		else this.collapse(eval('this.lists['+list+'].container'+this.lists[list].activeentry),this.lists[list].entries[this.lists[list].activeentry].child)
	} else 
		if (this.activelist != null && this.activelist.mother == list) this.shrink()	
}
function MenuShrink(list){
	this.shrinking = true
	var container = eval('this.lists['+this.activelist.mother+'].container'+this.activelist.motherentry)	
	if (list != null) container.slideTo(null,container.y-this.activelist.h,this.inc,this.speed,this.obj+'.sfinish('+list+')')
	else container.slideTo(null,container.y-this.activelist.h,this.inc,this.speed,this.obj+'.sfinish()')
}
function MenuCollapse(container,submenu){
	this.collapsing = true
	this.activelist = submenu	
	submenu.lyr.show()
	container.slideTo(null,container.y+submenu.h,this.inc,this.speed,this.obj+'.cfinish()')	
}
function MenuSFinish(list){
	this.shrinking = false
	this.activelist.lyr.hide()
	if (this.activelist.activeentry != null){
		this.activelist.entries[this.activelist.activeentry].enabled = true
		this.activelist.entries[this.activelist.activeentry].out()
	}	
	this.activelist = null
	if (list != null) this.collapse(eval('this.lists['+list+'].container'+this.lists[list].activeentry),this.lists[list].entries[this.lists[list].activeentry].child)	
}
function MenuCFinish(){
	this.collapsing = false
	//this.activelist.defaultentry(0)
}
function MenuStop(){
	var container = eval('this.lists['+this.activelist.mother+'].container'+this.activelist.motherentry)
	container.slideActive = false
	eval('this.lists['+this.activelist.mother+'].reset('+this.activelist.motherentry+')')	
	this.activelist.lyr.hide()	
	this.collapsing = false
	this.shrinking = false
	this.activelist = null
}
function MenuResize(getmargin){
	this.w = (is.ns)? (window.innerWidth) : (document.body.offsetWidth)
	this.h = (is.ns)? (window.innerHeight) : (document.body.offsetHeight)
	if (getmargin && !this.inscroll) this.marginW = Math.round(this.w/10)
	if (is.ie) {	
		this.lyr.resize(this.w-this.marginW)
		this.canvas.resize(this.w-this.marginW,this.h)
		for (var i=0;i<this.lists.length;i++) {
			this.lists[i].resize(this.w-this.marginW)
			if (this.lists[i].mother!=null) {
				var y = this.lists[this.lists[i].mother].entries[this.lists[i].motherentry].y  + this.lists[this.lists[i].mother].entries[this.lists[i].motherentry].h
				this.lists[i].lyr.moveTo(null,y)
			}			
		}		
		if (this.activelist != null) {
			var container = eval('this.lists['+this.activelist.mother+'].container'+this.activelist.motherentry)
			container.moveTo(null,container.y+this.activelist.h)			
		}				
	} else if (!this.inscroll) history.go(0)
}
