var d=document

var FR={
touts:{},
on:{},
tid:null,
id:false,
parents:{},
childs:{},
clearTouts:function(id){
	this.clearT(id)
	if(this.parents[id])this.clearTouts(this.parents[id])
},
show:function(v,id,el,aaa){
//vv(el.parentNode.parentNode.className+' '+el.parentNode.parentNode.id)
	if(el.parentNode.className=='smenu'){
		this.parents[id]=el.parentNode.id
		this.childs[el.parentNode.id]=id
	}

	this.clearTouts(id)
	if(this.id!=id && this.parents[id]!=this.id){
		this.hide(this.id)
	}
	
	this.id=id
	var e=EV.ev(v),o=d.getElementById(id)
	if(!o)return
	var s=o.style

	var w=o.offsetWidth,h=o.offsetHeight,t=0,l=0,w2=0,h2
	if(el&&!aaa){
		var td=el.parentNode
		w2=el.offsetWidth
		h2=el.offsetHeight
		while(el.tagName!="BODY" && el.tagName!="HTML"){
			var y=el.style.top,x=el.style.left
			t+=(y!="")?y.substring(1,y.length-2)*1:el.offsetTop
			l+=(x!="")?x.substring(1,x.length-2)*1:el.offsetLeft		
			el=el.offsetParent
		}
		w2=w2+2
		s.left=(d.body.scrollLeft+l)+'px'
		s.top=(t+h2+0)+'px'
		s.display="block"
	}else{
		t=e.clientY;l=e.clientX
		w2=e.src.offsetWidth
		h2=e.src.offsetHeight
		var coord=getCoord(e.src)
		w2=w2+2
		var bheight=document.body.offsetHeight+document.body.scrollTop
		s.display="block"

		if(bheight<coord.y+o.offsetHeight){
			s.top=(bheight-o.offsetHeight-1)+'px'
		}else{
			s.top=(coord.y)+'px'
		}
		s.left=(coord.x+coord.w+3)+'px'
	}
	this.selects(0)
	this.on[id]=true
	e.stopPropagation()
	return false
},
hide:function(idd){
	if(!idd)id=this.id
	else id=idd
	if(!id)return
	o=d.getElementById(id)
	if(!o)return
	o.style.display="none"
	this.on[id]=false
	if(this.childs[id]){
		this.runT(this.childs[id])
	}
	var ison=false
	for(var i in this.on)if(this.on[i])ison=true
	if(!ison)this.selects_on()
//	this.selects(1,id)
},

clearT:function(id){
	if(!id)id=this.id
	clearTimeout(this.touts[id])
	this.touts[id]=null
//	vv('clear timeout : '+id)
	if(this.parents[id]){
		this.clearT(this.parents[id])
		//vv('clear parent : '+this.parents[id])
	}
},
runT:function(id,t){
	if(!t)t=500
	if(!id)id=this.id
	if(!this.touts[id])this.touts[id]=setTimeout("FR.hide('"+id+"')",t);
//vv('run timeout : '+id)
	if(this.parents[id]){
		this.runT(this.parents[id],1500)
//		vv('hide parent : '+this.parents[id])
	}
},
selects:function(m,id){
	if(!document.all)return
	var i,b=document.getElementsByTagName('SELECT')
	for(i=0;i<b.length;i++){if(FR.intersect(b[i],id))b[i].style.visibility=m?'visible':'hidden'}
},
selects_on:function(){
	if(!document.all)return
	var i,b=document.getElementsByTagName('SELECT')
	for(i=0;i<b.length;i++){b[i].style.visibility='visible'}
},
intersect:function(o,id){
	if(!id)id=this.id
	var o1=getCoord(d.getElementById(id)),o2=getCoord(o)
	var cx=o1.x>o2.x?o1.x<o2.x+o2.w:o1.x+o1.w>o2.x,cy=o1.y>o2.y?o1.y<o2.y+o2.h:o1.y+o1.h>o2.y
	return cx&&cy
},
docOnclick:function(e){
	e=EV.ev(e)
	e=e.src
	alert(FR.id)
	if(e){
		while(e&&e.nodeName!='BODY'){if(e.id==FR.id)return;e=e.parentNode}
	}
	FR.hide()
}
}


var FEM={
tid:null,
id:false,
show:function(v,id,el){
	clearTimeout(this.tid)
//	if(this.id==id){this.hide();return}
	if(this.id!=id)this.hide()
	this.id=id
	var e=EV.ev(v),o=d.getElementById(id)
	if(!o)return
	var s=o.style
	s.display="block"
	var w=o.offsetWidth,h=o.offsetHeight,t=0,l=0,w2=0,h2
	if(el){
		var td=el.parentNode
		w2=el.offsetWidth
		h2=el.offsetHeight
		while(el.tagName!="BODY" && el.tagName!="HTML"){
			var y=el.style.top,x=el.style.left
			t+=(y!="")?y.substring(1,y.length-2)*1:el.offsetTop
			l+=(x!="")?x.substring(1,x.length-2)*1:el.offsetLeft		
			el=el.offsetParent
		}
	}else{
		t=e.clientY;l=e.clientX
		w2=e.offsetWidth
		h2=e.offsetHeight
	}
	w2=w2+2
	s.left=(d.body.scrollLeft+l)+'px'
	s.top=(t+h2)+'px'
	this.selects(0)
	e.stopPropagation()
	return false
},
hide:function(){
	if(!this.id)return
	this.selects(1)
	o=d.getElementById(this.id)
	if(!o)return
	o.style.display="none"
	this.id=null
},
selects:function(m){
	if(!document.all)return
	var i,b=document.getElementsByTagName('SELECT')
	for(i=0;i<b.length;i++){if(FEM.intersect(b[i]))b[i].style.visibility=m?'visible':'hidden'}
},
intersect:function(o){
	var o1=getCoord(d.getElementById(this.id)),o2=getCoord(o)
	var cx=o1.x>o2.x?o1.x<o2.x+o2.w:o1.x+o1.w>o2.x,cy=o1.y>o2.y?o1.y<o2.y+o2.h:o1.y+o1.h>o2.y
	return cx&&cy
},
clearT:function(){
	clearTimeout(this.tid)
},
runT:function(){
	this.tid=setTimeout("FEM.hide()",500);
},
docOnclick:function(e){
	e=EV.ev(e)
	e=e.src
	alert(FEM.id)
	if(e){
		while(e&&e.nodeName!='BODY'){if(e.id==FEM.id)return;e=e.parentNode}
	}
	FEM.hide()
}
}
function getCoord(o){
	var o2={w:o.offsetWidth,h:o.offsetHeight,x:o.offsetLeft,y:o.offsetTop}
	var p=o.offsetParent
	while(p!=null){o2.y+=p.offsetTop;o2.x+=p.offsetLeft;p=p.offsetParent}
	return o2
}
CEl=function(tagName,parent,doc){
	if(!doc)doc=document
	var el=doc.createElement(tagName)
	if(parent)parent.appendChild(el)
	return el
}
var EV={
	add:function(o,t,fp,cap){
		cap=cap||false
		if(o.addEventListener)o.addEventListener(t,fp,cap)
		else if(o.attachEvent)o.attachEvent('on'+t,fp)
	}, 
	remove:function(o,t,fp,cap){
		cap=cap||false
		if(o.removeEventListener)o.removeEventListener(t,fp,cap)
		else if(o.detachEvent)o.detachEvent('on'+t,fp)
	},
	ev:function(e){ 
		e=e?e:window.event
		if(!e)return
		e.src=e.srcElement?e.srcElement:e.target
		if(!e.preventDefault)e.preventDefault=function(){return false}
		if(!e.stopPropagation)e.stopPropagation=function(){
			if(window.event)window.event.cancelBubble=true;
		}
		return e
	}
}

function getE(id){return document.getElementById(id)}
