// InterDyn - Menu - Abre e Fecha
// Copyright 2005 JP7
// http://jp7.com.br
// Versão 0.2 - 2005/08/11


// Constructor 

function DMmakeMenu(){
	for(var i=0;i<this.itens.length;i++){
		var T=this.itens[i]
		T.i=i
		T.nivel=T.parent.nivel+1
		T.id=T.parent.id+i
		eval(T.id+'=T')
		
		if(T.nivel>1){
			if(!T.arguments[1]||T.arguments[1]=='default'){
				//loc='http://'+location.host+'/'+path+'site/'+toId(this.arguments[0])+'/?id='+T.arguments[2]
				loc='http://'+location.host+'/'+path+lang_path+toId(this.arguments[3])+'/'+toId(T.arguments[3])+'.php'
				T.arguments[1]='location=\''+loc+'\''
			}
		}else{
			if(T.arguments[1]=='default'){
				loc='http://'+location.host+'/'+path+lang_path+toId(this.arguments[3])+'/'+toId(T.arguments[3])+'.php'
				T.arguments[1]='location=\''+loc+'\''
			}else if(!T.arguments[1]&&!T.itens.length){
				loc='http://'+location.host+'/'+path+lang_path+toId(T.arguments[3])+'/'
				T.arguments[1]='location=\''+loc+'\''
			}
		}
		var ok=false
		if(tipos[this.nivel]==T.arguments[2]||tipo_id==T.arguments[2]){
			ok=true
			this.opened=T
		}
		contentStyle=(ok)?'display:block;overflow:visible':'display:none;overflow:hidden;height:1'
		
		if(T.nivel>1)S=T.arguments[0]
		else S='<img name="'+T.imgName+'"'+((T.arguments[1])?' onclick="'+T.arguments[1]+'"':'')+'>'
		d.write('<div id="'+T.id+'Div" class="DM_level_'+((T.nivel<4)?T.nivel:'n')+((ok)?' DM_level_'+((T.nivel<4)?T.nivel:'n')+'-on':'')+'">'+S+'</div>\n')
		T.DL=new DL(T.id+'Div')
		T.DL.elm.onclick=T.clickMenu
		if(T.itens.length){
			d.write('<div id="'+T.id+'ContentDiv" class="DM_level_'+((T.nivel<4)?T.nivel:'n')+'-content" style="'+contentStyle+'">\n')
			T.DLcontent=new DL(T.id+'ContentDiv')
		}
		if(T.nivel==1){
			T.imgObj=T.DL.doc.images[T.imgName]
			T.imgObj.src=(ok&&T.itens.length)?T.imgOpened.src:T.imgClosed.src
			//T.imgObj.src=T.imgClosed.src
			//T.imgObj.onmouseover=DMcIover
			//T.imgObj.onmouseout=DMcIout
		}

		if(T.itens.length){
			T.makeMenu()
			d.write('</div>')
		}
	}
}


// Methods

function DMclickMenu(){
	//var T=this.DO
	var T=eval(this.id.substring(0,this.id.length-3))
	
	if(T.parent.willopen)return false
	T.parent.willopen=T

	if(T.nivel==1&&T.parent.willopen!=T.parent.opened&&T.itens.length){
		if(!T.imgOpened.error)T.imgObj.src=T.imgOpened.src
		//T.imgObj.onmouseover=null
		//T.imgObj.onmouseout=null
	}
	if(T.parent.opened){
		if(T.parent.opened.nivel==1){
			T.parent.opened.imgObj.src=T.parent.opened.imgClosed.src
			//T.parent.opened.imgObj.onmouseover=DMcIover
			//T.parent.opened.imgObj.onmouseout=DMcIout
		}
		T.parent.opened.closeMenu()
	}else T.openMenu()
}

function DMopenMenu(){
	var T=this
	if(T.parent.onslide){
		setTimeout(T.id+'.openMenu()',10)
		return false
	}
	if(T.parent.opened!=T.parent.willopen){
		if(T.itens.length)T.moveMenuContent('show')
		else T.openMenuFin()
	}
	else{
		T.parent.opened=null
		T.parent.willopen=null
		if(T.nivel>1)T.openMenuFin()
	}
}

function DMopenMenuFin(){
	this.parent.opened=this
	this.parent.willopen=null
	eval(this.arguments[1])
}

function DMcloseMenu(){
	var T=this
	if(!T.opened){
		if(T.itens.length)T.moveMenuContent('hide')
		else T.parent.opened.closeMenuFin()
	}else{
		T.parent.willclose=T
		T.opened.closeMenu()
	}
}

function DMcloseMenuFin(){
	var T=this
	if(T.parent.parent){
		if(T.parent.parent.willclose&&!T.opened){
			setTimeout(T.id+'.parent.opened=null;'+T.id+'.parent.parent.willclose.closeMenu();'+T.id+'.parent.parent.willclose=null',100)
			return false
		}
	}
	if(!T.opened)setTimeout(T.id+'.parent.willopen.openMenu()',100)
}

function DMmoveMenuContent(action){
	var T=this.DLcontent
	var distY=20
	this.parent.onslide=true
	if(action=='hide'){
		T.css.overflow='hidden'
		if(!is.mac||!is.ie){
			if(!T.h)T.h=T.elm.scrollHeight
			if(T.h-distY<=0)T.h=T.elm.offsetHeight // Bug Tableless
			T.rTo(null,T.h-distY)
		}
		if((!is.mac||!is.ie)&&T.h-distY>1)setTimeout(this.id+'.moveMenuContent(\'hide\')',20)
		else{
			T.rTo(null,1)
			T.css.display='none'
			setTimeout(this.id+'.parent.onslide=false',100)
			this.closeMenuFin()
		}
	}else{
		T.css.display='block'
		T.css.height=''
		if(!is.mac||!is.ie){
			if(!T.elm.alpha){
				T.h=0
				T.elm.alpha=T.elm.scrollHeight
			}
			T.rTo(null,T.h+distY)
		}
		if((!is.mac||!is.ie)&&T.h+distY<T.elm.alpha)setTimeout(this.id+'.moveMenuContent(\'show\')',20)
		else{
			T.rTo(null,T.elm.alpha)
			T.css.overflow='visible'
			T.css.height=''
			setTimeout(this.id+'.parent.onslide=false',100)
			this.openMenuFin()
		}
		this.parent.opened=this
	}
}

var DOP=DO.prototype

DOP.makeMenu=DMmakeMenu
DOP.clickMenu=DMclickMenu
DOP.openMenu=DMopenMenu
DOP.openMenuFin=DMopenMenuFin
DOP.closeMenu=DMcloseMenu
DOP.closeMenuFin=DMcloseMenuFin
DOP.moveMenuContent=DMmoveMenuContent

DOP.i=0             // Índice
DOP.willopen=null
DOP.willclose=null
DOP.opened=null
DOP.onslide=false

DOP.querystring=''


// Starter

function newDM(obj,imgPath){
	DOP.id=obj
	DOP.imgName=toId(eval(obj).arguments[0])
	eval(obj).preload(imgPath)
	eval(obj).makeMenu()
}
