debug = 0;

function layerobj(section) {
   this.name = section;
   this.bwis = new checkBrowser();
   this._layer = getLayerRef(this.name, this.bwis);
   if (debug){alert("Anonymous constructor created.  Returning..");}
   return this;
}

layerobj.prototype.on = _show;
layerobj.prototype.off = _unshow;
layerobj.prototype.relocate = _relocate;
layerobj.prototype.dumpdebug = _debuginfo;

function getLayerRef(objname, bwis) {
   if (bwis.ns4) {
      if(debug){alert("Detected NS4 and allocating appropriate object");alert(document.eval(objname));}
      return document.eval(objname);
   } else if (bwis.dom) {
      if(debug){alert("Detected w3c-compliant browser with getElementByID and allocating appropriate object");}
      return document.getElementById(objname);
   } else if (bwis.bw) {
      if(debug){alert("Detected an old IE with document.all and allocating appropriate object");}
      return document.all(objname);
   } else {
      if(debug){alert("Detected an non-DHTML browser.  Not allocating any object.");}
      return 0;
   }
}

function _debuginfo() {
   var debugtext = "";
   debugtext = debugtext + "Layer name for this object is " + this.name + "\n";
   debugtext = debugtext + "Detected browser is " + this.bwis.ver + " with DOM of " + this.bwis.dom + "\n";   
   debugtext = debugtext + "Type of the child layer object is  " + typeof(this._layer) + "\n";
   debugtext = debugtext + "Children of this object are:\n" ;
   for (i in this) {
      debugtext = debugtext + "   "+ i + ": " + this[i] + "\n";
   }
   
   debugtext = debugtext + "Children of the layer oject are: :\n" ;
   for (i in this._layer) {
      debugtext = debugtext + "   "+ i + ": " + this._layer[i] + "\n";
   }
   return debugtext;
}


function _show() {
   if(debug){alert("Show Layer function was called on " + this._layer);}
   if(this.bwis.ns4) {
      if(debug){alert("using NS4 show routine");}
      this._layer.visibility = "show";
      if(debug){alert("success");}
   } else {
      this._layer.style.visibility = "visible";
   }
   return false;
}

function _unshow() {
   if(debug){alert("Hide Layer function was called");}
   if(this.bwis.ns4) {
      this._layer.visibility = "hide";
   } else {
      this._layer.style.visibility = "hidden";
   }
   return false;
}

function _relocate(userxoffset,useryoffset) {
   if(debug){alert("Relocate Layer function was called");}
   if (!userxoffset) {userxoffset= 0;}
   if (!useryoffset) {useryoffset = 0;}
   if (this.bwis.ns4) {
      if(debug){alert('using ns relo commands');}
      var yoffset = window.pageYOffset;
      var xoffset = window.pageXOffset;
      var pageheight = window.innerHeight;
      var pagewidth = window.innerWidth - 20;
      var layerHeight = this._layer.clip.height;
      var layerWidth = this._layer.clip.width;
      if(debug){alert("moving to:" + (yoffset + pageheight - useryoffset) + "y and " + (xoffset + pagewidth  - userxoffset) + "x.\n");}
      this._layer.moveToAbsolute((xoffset + pagewidth - userxoffset - layerWidth), (yoffset + pageheight - useryoffset - layerHeight));
   } else {
      if(debug){alert('using ie relo commands');}
   	var yoffset = document.body.scrollTop;
      var xoffset = document.body.scrollLeft;
   	pagewidth = document.body.clientWidth;
   	pageheight = document.body.clientHeight;
   	if(this.bwis.ie4) {
         var layerHeight = this._layer.scrollHeight;
         var layerWidth = this._layer.scrollWidth;
      } else {
         var layerHeight = this._layer.offsetHeight;
         var layerWidth = this._layer.offsetWidth;
      }
      //alert("Move params: xoffset:" + xoffset + " pagewidth:" + pagewidth + " userx:" + userxoffset + " layerwid:" + layerWidth);
      this._layer.style.left = xoffset + pagewidth - userxoffset - layerWidth;
      this._layer.style.top = yoffset + pageheight - useryoffset - layerHeight;
   }
   return false;
}

function checkBrowser(){
   // borrowed from thomas bratta (bratta.com)
   // in the cool menus script
	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;
}

if(debug){alert('Floater script loaded successfully');}
