//Chrome Drop Down Menu v2.01- Author: Dynamic Drive (http://www.dynamicdrive.com)

if (window.Node && Node.prototype && !Node.prototype.contains)
{
	Node.prototype.contains = function (arg) {
		return !!(this.compareDocumentPosition(arg) & 16)
	}
}

var cssdropdown={
disappeardelay: 250, //set delay in miliseconds before menu disappears onmouseout
enableswipe: 1, //enable swipe effect? 1 for yes, 0 for no

//No need to edit beyond here////////////////////////
dropmenuobj: null, dropmenuobj2: null, ie: document.all, firefox: document.getElementById&&!document.all, swipetimer: undefined, bottomclip:0, delayhide:null,

getposOffset:function(what, offsettype){
	var totaloffset = (offsettype=="left") ? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
},

swipeeffect:function(dropType){
	if (dropType == 0) {
		if (this.bottomclip<parseInt(this.dropmenuobj.offsetHeight)){
			this.bottomclip+=10+(this.bottomclip/10) //unclip drop down menu visibility gradually
			this.dropmenuobj.style.clip="rect(0 auto "+this.bottomclip+"px 0)"
		}
		else return
	} else {
		if (this.rightclip < parseInt(this.dropmenuobj.offsetWidth)){
			this.rightclip+=10+(this.rightclip/10)
			this.dropmenuobj.style.clip="rect(0 "+this.rightclip+"px auto 0)"
		}
	}
	this.swipetimer=setTimeout("cssdropdown.swipeeffect(" + dropType + ")", 10)
},

showhide:function(obj, e, dropType){
if (this.ie || this.firefox)
this.dropmenuobj.style.left=this.dropmenuobj.style.top="-500px"
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover"){
if (this.enableswipe==1){
if (typeof this.swipetimer!="undefined")
clearTimeout(this.swipetimer)
if (dropType == 0) { obj.clip="rect(0 auto 0 0)"; this.bottomclip=0; }
else { obj.clip="rect(0 0 auto 0)"; this.rightclip=0 }
this.swipeeffect(dropType)
}
obj.visibility="visible"
}
else if (e.type=="click")
obj.visibility="hidden"
},

iecompattest:function(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
},

clearbrowseredge:function(obj, whichedge){
	var edgeoffset=0
	if (whichedge=="rightedge"){
		var windowedge=this.ie && !window.opera? this.iecompattest().scrollLeft+this.iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
		this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetWidth
		if (windowedge-this.dropmenuobj.x < this.dropmenuobj.contentmeasure)  //move menu to the left?
		edgeoffset=this.dropmenuobj.contentmeasure-obj.offsetWidth
	}
	else {
		var topedge=this.ie && !window.opera? this.iecompattest().scrollTop : window.pageYOffset
		var windowedge=this.ie && !window.opera? this.iecompattest().scrollTop+this.iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
		this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetHeight
		if (windowedge-this.dropmenuobj.y < this.dropmenuobj.contentmeasure){ //move up?
			edgeoffset=this.dropmenuobj.contentmeasure+obj.offsetHeight
			if ((this.dropmenuobj.y-topedge)<this.dropmenuobj.contentmeasure) //up no good either?
			edgeoffset=this.dropmenuobj.y+obj.offsetHeight-topedge
		}
	}
	return edgeoffset
},

dropit:function(obj, e, dropmenuID, dropType) {
	if ((this.dropmenuobj!=null)&&(!this.dropmenuobj.contains(obj))) { //hide previous menu
		this.dropmenuobj.style.visibility="hidden" //hide menu
	} else if (this.dropmenuobj!=null) {
		this.dropmenuobj2 = this.dropmenuobj;
	}
	if ((this.dropmenuobj2!=null)&&(!this.dropmenuobj2.contains(obj))) this.dropmenuobj2.style.visibility="hidden" //hide menu
	this.clearhidemenu()
	if (this.ie||this.firefox){
		obj.onmouseout=function(){cssdropdown.delayhidemenu()}
		if (obj.href.substr(obj.href.length - 1) == '#') obj.onclick=function() { return false; }
		this.dropmenuobj=document.getElementById(dropmenuID)
		this.dropmenuobj.onmouseover=function(){ cssdropdown.clearhidemenu() }
		this.dropmenuobj.onmouseout=function(e){ cssdropdown.dynamichide(e) }
		this.dropmenuobj.onclick=function(){cssdropdown.delayhidemenu() }
		this.showhide(this.dropmenuobj.style, e, dropType)
		this.dropmenuobj.x=this.getposOffset(obj, "left")
		this.dropmenuobj.y=this.getposOffset(obj, "top")
		if (dropType == 1) {
			this.dropmenuobj.x+=obj.offsetWidth;
			this.dropmenuobj.y-=obj.offsetHeight;
		} else {
			this.dropmenuobj.y+=obj.offsetHeight/2;
		}
		this.dropmenuobj.style.left=this.dropmenuobj.x-this.clearbrowseredge(obj, "rightedge")-30+"px"
		var temp = this.clearbrowseredge(obj, "bottomedge")
		if (temp != 0) temp -= 50;
		if (this.firefox) temp += 4;
		else temp += 12;
		this.dropmenuobj.style.top=this.dropmenuobj.y-temp+obj.offsetHeight+"px"
	}
},

contains_firefox:function(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
},

dynamichide:function(e){
var evtobj=window.event? window.event : e
if (this.ie&&!this.dropmenuobj.contains(evtobj.toElement)) {
	this.delayhidemenu()
}
else if (this.firefox&&evtobj.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget)) {
	var it = evtobj.currentTarget.getElementsByTagName("a");
	var found = false;
	for (var i = 0; i < it.length; i++) {
		if (it[i].getAttribute("rel")) {
			var tmp = document.getElementById(it[i].getAttribute("rel"));
			if ((evtobj.relatedTarget == tmp) || this.contains_firefox(tmp, evtobj.relatedTarget)) {
				found = true;
				break;
			}
		}
	}
	if (!found) this.delayhidemenu();
}
},

delayhidemenu:function(){
this.clearhidemenu();
this.delayhide=setTimeout("cssdropdown.dropmenuobj.style.visibility='hidden'; if(cssdropdown.dropmenuobj2 != null) cssdropdown.dropmenuobj2.style.visibility='hidden';",this.disappeardelay) //hide menu
},

clearhidemenu:function(){
if (this.delayhide!=null)
clearTimeout(this.delayhide)
this.delayhide=null
},

startchrome:function() {
	var dropType = arguments[arguments.length - 1]
	for (var ids=0; ids<arguments.length; ids++){
		if (ids != (arguments.length - 1)) {
			var menuitems=document.getElementById(arguments[ids]).getElementsByTagName("a")
			for (var i=0; i<menuitems.length; i++){
				if (menuitems[i].getAttribute("rel")){
					menuitems[i].onmouseover=function(e){
						var event=typeof e!="undefined"? e : window.event
						cssdropdown.dropit(this,event,this.getAttribute("rel"),dropType)
					}
					var it = document.getElementById(menuitems[i].getAttribute("rel")).getElementsByTagName("a");
					for (var h = 0; h < it.length; h++) {
						if (it[h].getAttribute("rel")) {
							it[h].onmouseover=function(e) {
								var event=typeof e!="undefined"? e : window.event
								cssdropdown.dropit(this,event,this.getAttribute("rel"),1)
							}
						} else {
							it[h].onmouseover=function() {
								if((cssdropdown.dropmenuobj2!=null)&&(cssdropdown.dropmenuobj2.contains(this)))
									cssdropdown.dropmenuobj.style.visibility="hidden";
							}
						}
					}
				}
			}
		}
	}
}

}