function DropdownPing(dropdown) {
	if((typeof dropdown) != "object") { return false; } // oops, we didn't get an object.
	if((typeof dropdown.watcher) == "object") {
		// there's a watcher on this dropdown, let it know we're back.
		dropdown.watcher.CancelShutdown();
	} 
	DropdownShow(dropdown);
}

function DropdownExit(dropdown) {
	if(!(typeof dropdown == "object")) { return false; } // oops, we didn't get an object.
	if((typeof dropdown.watcher) != "object") {
		// there was no watcher, create a new one.
		dropdown.watcher = new watcher(dropdown);
	}
	dropdown.watcher.StartShutdown();
}


function watcher(target,ms) {
	if (typeof target != "object") { alert("Attempted to close a non-existent layer!"); return false; }
	if(!ms) {ms = 2200;} // default to 500 ms.
	this.ms = ms;
	this.dropdown = target;
	return this;
}
watcher.prototype.doClose = watcherDoClose;
watcher.prototype.CancelShutdown = watcherCancelShutdown;
watcher.prototype.StartShutdown = watcherStartShutdown;

function watcherCancelShutdown() {
	if (this.hastimeout) {
		clearTimeout(this.timeout);
		this.hastimeout = false;
	}
}

function watcherStartShutdown(ms) {
	if(!this.hastimeout) {
		this.timeout = setTimeout("var foo = getObject('" + this.dropdown.id + "');foo.watcher.doClose();",this.ms);
		this.hastimeout = true;	
	} else {
		// cancel the shutdown before we start a new one.
		this.CancelShutdown();
		this.StartShutdown(); //rather than recode. :)
	}
}

function watcherDoClose() {
	this.hastimeout = false;
	DropdownHide(this.dropdown);
}


function DropdownShow(dropdown) {
	bwis = new BrowserVersion();
	if (bwis.ns4) {
		dropdown.visibility = "show";
	} else {
		dropdown.style.visibility = "visible";
	}
}

function DropdownHide(dropdown) {
	bwis = new BrowserVersion();
	if (bwis.ns4) {
		dropdown.visibility = "hide";
	} else {
		dropdown.style.visibility = "hidden";
	}
		
}

function getObject(objname) {
	bwis = new BrowserVersion();
   if (bwis.ns4) {
     return document[objname];   
   } else if (bwis.dom) {
      return document.getElementById(objname);
   } else if (bwis.ie4) {
      return document.all(objname);
   } else {
     return 0;
   }
}

function BrowserVersion() {
	this.ver=navigator.appVersion;
	this.agent=navigator.userAgent;
	this.dom=document.getElementById?1:0;
	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0;
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6;
	this.mac=this.agent.indexOf("Mac")>-1;
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5);
	return this;
}
