


CSS = function(eID)
{
      if(document.getElementById)
      {
         this.layer=document.getElementById(eID);
         this.css=document.getElementById(eID).style;
      } // IE 5.0+, Firefox, Mozilla

      else if(document.layers)
      {
           this.layer=document.layers[eID];
           this.css=document.layers[eID];
      } // NS 4.0+
      else if(document.all)
      {
           this.layer=document.all[eID];
           this.css=document.all[eID].style;
      } // IE 4.0+ Opera
      else return false;

      return this;
}

/*               This notice must be untouched at all times.           */
/************************************************************************
The code contained here is the sole property of Forward Minds Inc. and
ModernCode. Unauthorized use is strictly prohibited. For license details
contact Forward Minds Inc. email@forwardminds.com.

Forward Minds Inc. ©2003,2004 All Rights Reserved.

Author: F. Cesar DeAraujo
************************************************************************/
/******************************** Start lib.Layer.JS ******************************/


Layer = function()
{
    var a=arguments,ln=a.length,i,o=this,l,ol,j;
    o.div = {};
    o.reposition = false;
    o.position = {};
    o.div.visible = false;
    o._html = "";

    for(i=0;i<ln;++i)
    {
        l=a[i];
        if(typeof(l)!='string')
        {
           ol=l.length;
           for(j=0;j<ol;++j) o.addLayer(l[j]);
        }
        else o.addLayer(l);
    }
}

Layer.prototype.writeHtml = function(html,id)
{
    var o=this, _obj;
    if(typeof(id)=='undefined') id = o.id;
    _obj = o.getCSSLayer(id);
    if(typeof(html)=='string')  _obj.innerHTML = html;
    else alert('Layer.writeHtml expects a string for arg 1!');
}

Layer.prototype.flushHtmlBuffer = function(id)
{
    var o=this, _html, _obj;
    if(typeof(id)=='undefined') id = o.id;
    _obj = o.getCSSLayer(id);
    _html = o.getHtmlBuffer();

    if(o.html == "") alert('Html buffer is empty');
    else _obj.innerHTML = _html;

}

Layer.prototype.appendToHtmlBuffer = function(html)
{
    o = this;
    o._html += html;
}

Layer.prototype.getHtmlBuffer = function()
{
    return this._html;
}


Layer.prototype.clearHtmlBuffer = function()
{
    o = this;
    o._html = '';
}

Layer.prototype.addLayer = function(id)
{
	var o=this;
	o.id=id;
	o.div[id]={};
	o.div[id].obj = o.setCSS(id);
}

Layer.prototype.getCSSLayer = function(id)
{
    return this.div[id].obj.layer;
}

Layer.prototype.setCSS = function(id)
{
	var c = new CSS(id);
	return c;
}

Layer.prototype.hideAll = function()
{
	var id,o=this;
	for(id in o.div)
	{
	  if(id != 'visible') o.hide(id);
	}
}

Layer.prototype.showAll = function()
{
	var id,o=this;
	for(id in o.div)
	{
	  if(id != 'hidden') o.show(id);
	}
}

Layer.prototype.show = function(id)
{
	var css = this.div[id].obj.css
	css.visibility = 'visible';
	if(this.reposition==true) this.move(id);
}

Layer.prototype.hide = function(id)
{
	var css = this.div[id].obj.css;
	css.visibility = 'hidden';
}

Layer.prototype.toggle = function(id)
{

	var _id, count=0, o=this;
	for(_id in o.div) ++count; 
	
	if(count==2)
	{
		if(typeof(id)=='undefined') id=this.id;
		var _status = o.div[id].obj.css.visibility;
		(_status=='visible') ? o.hide(id) : o.show(id);
	}
	else
	{
		if(o.div.visible != false && o.div.visible != id)
		{
			o.hide(o.div.visible);
			o.show(id);
			o.div.visible = id;
		}
		else
		{
			o.div.visible = id;
			o.show(id);
		}
	}
}

Layer.prototype.moveTo = function(top,left,id)
{
	var o=this;
	o.setReposition(true);
	
	if(typeof(id)=='undefined') id=this.id;
	
	o.position[id]= {};
	o.position[id].top = top;
	o.position[id].left = left;
	
}

Layer.prototype.move = function(id)
{
	var o=this, adj_w;
	var vpw = 900;
	var cw = parseInt(document.body.clientWidth);
	var css = o.div[id].obj.css;
	
	adj_w = (cw-vpw)/2;
	
	css.top = o.position[id].top + 'px';
	css.left = (parseInt(o.position[id].left) + adj_w) + 'px';

    
}

Layer.prototype.setReposition = function(reposition)
{
	this.reposition = reposition;
}

initMyLayers = function()
{
    var a=arguments,ln=a.length,i,l=[];
    if(ln>0)
    {
        for(i=0;i<ln;++i) l[i]=a[i];

        MyLayer = new Layer(l);
        MyLayer.showAll();

    }
}


/******************************** End lib.Layer.JS ******************************/