var disappeardelay=250; // Menu disappear speed onMouseout (in milliseconds)
var enableanchorlink=0; // Enable or disable the anchor link when clicked on? (1=e, 0=d)
var hidemenu_onclick=1; // Hide menu when user clicks within menu? (1=yes, 0=no)

/////No further editing needed

var ie5=document.all;
var ns6=document.getElementById&&!document.all;

function getposOffset(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;
}

function showhide(obj, e, visible, hidden){
	if (ie5||ns6)
		dropmenuobj.style.left=dropmenuobj.style.top=-500;
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
		obj.visibility=visible;
	else if (e.type=="click")
		obj.visibility=hidden;
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset=0
	if (whichedge=="rightedge"){
		var windowedge=ie5 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15;
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth;
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth;
	}else{
		var topedge=ie5 && !window.opera? iecompattest().scrollTop : window.pageYOffset;
		var windowedge=ie5 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight;
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
			edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight;
			if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
				edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge;
		}
	}
	return edgeoffset;
}

function dropdownmenu(obj, e, dropmenuID){
	if (window.event) 
		event.cancelBubble=true;
	else if (e.stopPropagation) 
		e.stopPropagation();
	if (typeof dropmenuobj!="undefined") //hide previous menu
		dropmenuobj.style.visibility="hidden";
	clearhidemenu();
	if (ie5||ns6){
		//obj.onmouseout=delayhidemenu;
		assignHandler( obj, 'onmouseout', delayhidemenu );
		
		dropmenuobj=document.getElementById(dropmenuID);
		if (hidemenu_onclick){ 
			dropmenuobj.onclick=function(){
				dropmenuobj.style.visibility='hidden';
			}
		}

		dropmenuobj.onmouseover=clearhidemenu;		
		dropmenuobj.onmouseout=ie5? function(){ dynamichide(event)} : function(event){ dynamichide(event)};
		
		showhide(dropmenuobj.style, e, "visible", "hidden");
		dropmenuobj.x=getposOffset(obj, "left");
		dropmenuobj.y=getposOffset(obj, "top");
		dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px";
		current_url = document.URL;
		
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px";
		if( whichBrs() == "Safari")
		{
			dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+18+obj.offsetHeight+"px";
		}
		
		// if( whichBrs() == "Safari"  && current_url == "http://sociusconstruction.com/index.php" )
		// {
			// dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+18+obj.offsetHeight+"px";
			// alert(1);
		// }
		
		
		// dropmenuobj.style.top="313px"; //edit by elson james solano
		// alert(dropmenuobj.x+"&"+dropmenuobj.y);
		// alert(dropmenuobj.style.left+"&"+dropmenuobj.style.top);
	}
	return clickreturnvalue();
}

function clickreturnvalue(){
	if ((ie5||ns6) && !enableanchorlink) 
		return false;
	else
		return true;
}

function contains_ns6(a, b) {
	while (b.parentNode)
		if ((b = b.parentNode) == a)
			return true;
	return false;
}

function dynamichide(e){
	if (ie5&&!dropmenuobj.contains(e.toElement))
		delayhidemenu();
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
		delayhidemenu();
}

function delayhidemenu(){
	delayhide=setTimeout("dropmenuobj.style.visibility='hidden'",disappeardelay);
}

function clearhidemenu(){
	if (typeof delayhide!="undefined")
		clearTimeout(delayhide);
}

function assignHandler( object, pName, handler ){
	if( !object[pName] ){
		object[pName] = handler;
	}else if( !object['___old___' + pName] ){
		object['___old___' + pName] = object[pName];
		object['___new___' + pName] = handler;
		object[pName] = new Function( 'this.___old___' + pName + '();this.___new___' + pName + '();' );
	}
}

// Browser Detection Javascript
// copyright 1 February 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function whichBrs() {
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1) return 'Opera';
	if (agt.indexOf("staroffice") != -1) return 'Star Office';
	if (agt.indexOf("webtv") != -1) return 'WebTV';
	if (agt.indexOf("beonex") != -1) return 'Beonex';
	if (agt.indexOf("chimera") != -1) return 'Chimera';
	if (agt.indexOf("netpositive") != -1) return 'NetPositive';
	if (agt.indexOf("phoenix") != -1) return 'Phoenix';
	if (agt.indexOf("firefox") != -1) return 'Firefox';
	if (agt.indexOf("safari") != -1) return 'Safari';
	if (agt.indexOf("skipstone") != -1) return 'SkipStone';
	if (agt.indexOf("msie") != -1) return 'Internet Explorer';
	if (agt.indexOf("netscape") != -1) return 'Netscape';
	if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
	if (agt.indexOf('\/') != -1) {
	if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
	return navigator.userAgent.substr(0,agt.indexOf('\/'));}
	else return 'Netscape';} else if (agt.indexOf(' ') != -1)
	return navigator.userAgent.substr(0,agt.indexOf(' '));
	else return navigator.userAgent;
}
