// InterDyn - Menu - Vertical - Atmos
// Copyright 2005 JP7
// http://jp7.com.br
// Versão 0.1 - 2005/04/14


// Images

function DMpI(imgPath){
	imgPath=imgPath||'../../img_dyn/DM/'
	this.imgName=this.parent.imgName+'_'+toId(this.arguments[0])
	this.imgClosed=new Image()
	if(is.ie){
		this.imgClosed.src=''
		if(is.mac){
			this.imgClosed.width=''
			this.imgClosed.height=''
		}
	}
	this.imgClosed.onerror=DMpIerror
	this.imgClosed.src=imgPath+this.imgName+'_'+((tipos[this.nivel]==this.arguments[2])?'on':'off')+'_closed.png'
	//this.imgOver=new Image()
	//this.imgOver.onerror=DMpIerror
	//this.imgOver.src=imgPath+this.imgName+'_over.png'
	this.imgOpened=new Image()
	this.imgOpened.onerror=DMpIerror
	this.imgOpened.src=imgPath+this.imgName+'_'+((tipos[this.nivel]==this.arguments[2])?'on':'off')+'_opened.png'
}

function DMpIerror(){this.error=true}

function DMpreload(imgPath){
	for(var i=0;i<this.itens.length;i++){
		this.itens[i].pI(imgPath)
		//if(this.itens[i].itens.length)this.itens[i].preload()
	}
}

function DMcIover(){if(!this.DO.imgOver.error)this.src=this.DO.imgOver.src}
function DMcIout(){if(!this.DO.imgOver.error)this.src=this.DO.imgClosed.src}


// 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){
				loc='http://'+location.host+'/'+path+'site/'+toId(this.arguments[0])+'/?id='+T.arguments[2]
				T.arguments[1]='location=\''+loc+'\''
		}else{
			if(T.arguments[1]=='default'){
				loc='http://'+location.host+'/'+path+'site/'+toId(this.arguments[0])+'/'+toId(T.arguments[0])+'.php'
				T.arguments[1]='location=\''+loc+'\''
			}else if(!T.arguments[1]&&!T.itens.length){
				loc='http://'+location.host+'/'+path+'site/'+toId(T.arguments[0])+'/'
				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=''+
			'<table border=0 cellspacing=0 cellpadding=0>'+
				'<tr>'+
					'<td valign="top"'+((is.sa)?' width=10':'')+'><div class="marcador"'+((is.ie&&is.win)?' style="overflow:hidden"':'')+'></div></td>'+
					'<td>'+T.arguments[0]+'</td>'+
				'</tr>'+
			'</table>'
		}else{
			S='<img name="'+T.imgName+'"'+((T.arguments[1])?' onclick="'+T.arguments[1]+'"':'')+'>'
		}
		d.write('<div id="'+T.id+'Div" class="DM-nivel-'+((T.nivel<4)?T.nivel:'n')+((ok)?' DM-nivel-'+((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-nivel-'+((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
			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.nivel=0         // Nível
DOP.id='DO0'        // ID
DOP.i=0             // Índice
DOP.DL=null         // DL
DOP.DLcontent=null  // DLcontent
DOP.willopen=null
DOP.willclose=null
DOP.opened=null
DOP.onslide=false

DOP.preload=DMpreload
DOP.pI=DMpI
DOP.imgName=null
DOP.imgObj=null
DOP.imgClosed=null
DOP.imgOver=null
DOP.imgOn=null

DOP.querystring=''


// Starter

function newDM(obj,imgPath){
	DOP.id=obj
	DOP.imgName=toId(eval(obj).arguments[0])
	eval(obj).preload(imgPath)
	eval(obj).makeMenu()
}
