//Objeto panel
//-----------
//	Encapsula métodos e propriedades para trabalhar com layers
//------------------
//  layerID: id do layer no documento
//  parentLayer(opcional para netscape): layer pai do panel
//------------
function panel(layerID,parentLayer){
	//panel_errormessage
	//para exibir uma mensagem de erro do panel
	function panel_errormessage(errmsg){
		//alert(errmsg);
		return false
	}
	//panel_moveIt
	//move o panel para coordenada (x,y) absoluta
	function panel_moveIt(x,y){
	        this.x=x;this.y=y
	        this.css.left=x;this.css.top=y
	}
	//panel_moveBy
	//move o panel para coordenada (x,y) relativa
	function panel_moveBy(x,y){
	        this.moveIt(this.x+x,this.y+y)
	}
	//panel_showIt
	//Exibe o panel
	function panel_showIt(){
	        this.css.visibility="visible"
	}
	//panel_hideIt
	//Esconde o panel
	function panel_hideIt(){
	        this.css.visibility="hidden"
	}
	//panel_bg
	//altera a cor de fundo do panel
	function panel_bg(color){
	        if(browser.dom || browser.ie4) this.css.backgroundColor=color
	        else if(browser.ns4) this.css.bgColor=color  
	}
	//panel_writeIt
	//escreve texto no conteudo do panel
	function panel_writeIt(text,startHTML,endHTML){
	        if(browser.ns4){
	                if(!startHTML){startHTML=""; endHTML=""}
	                this.ref.open("text/html"); this.ref.write(startHTML+text+endHTML); this.ref.close();
	        }else this.evnt.innerHTML=text; //só funciona em Explorer4+5 e Gecko M16+
	}
	//panel_clipTo
	//altera as propriedades do panel absolutamente
	//t:top,r:right,b:bottom,l:left, setwidth:largura
	function panel_clipTo(t,r,b,l,setwidth){
		this.ct=t; this.cr=r; this.cb=b; this.cl=l
		if(browser.ns4){
			this.css.clip.top=t;this.css.clip.right=r
			this.css.clip.bottom=b;this.css.clip.left=l
		}else{
			if(t<0)t=0;if(r<0)r=0;if(b<0)b=0;if(b<0)b=0
			this.css.clip="rect("+t+","+r+","+b+","+l+")";
			if(setwidth){this.css.width=r; this.css.height=b}
		}
	}
	//panel_clipBy
	//altera as propriedades do panel relativamente
	//t:top,r:right,b:bottom,l:left, setwidth:largura
	function panel_clipBy(t,r,b,l,setwidth){
		this.clipTo(this.ct+t,this.cr+r,this.cb+b,this.cl+l,setwidth)
	}
	
	//metodo para exibicao de erro
	this.panel_errormessage=panel_errormessage;
	if(!browser.anyBrowser) return this.panel_errormessage('Este Browser não possui os recursos necessários para a correta exibição.')
	this.evnt=browser.dom && document.getElementById(layerID)||browser.ie4 && document.all[layerID]|| (parentLayer?browser.ns4 && document[parentLayer].document.layers[layerID]:browser.ns4 && document.layers[layerID]);
	if(!this.evnt) return this.panel_errormessage('O Layer referenciado não existe ('+layerID+') - cancelando Script\n\nSe você está utilizando Netscape verifique o aninhamento das tags!')
	this.css=browser.dom||browser.ie4?this.evnt.style:this.evnt;
	this.ref=browser.dom||browser.ie4?document:this.css.document;
	this.x=this.css.left||this.css.pixelLeft||this.evnt.offsetLeft||0
	this.y=this.css.top||this.css.pixelTop||this.evnt.offsetTop||0
	this.w=this.ref.width||this.evnt.offsetWidth||this.css.pixelWidth||0
	this.h=this.ref.height||this.evnt.offsetHeight||this.css.pixelHeight||0
	this.moveIt=panel_moveIt; this.moveBy=panel_moveBy; 
	this.showIt=panel_showIt; this.hideIt=panel_hideIt;
	this.writeIt=panel_writeIt; this.bg=panel_bg;	
	//Propriedades do panel
	this.c=0
	if((browser.dom || browser.ie4) && this.css.clip) {
		this.c=this.css.clip; this.c=this.c.slice(5,this.c.length-1); 
		this.c=this.c.split(' '); 
		for(var i=0;i<4;i++){this.c[i]=parseInt(this.c[i])}
	}
	this.ct=this.css.clip.top||this.c[0]||0; 
	this.cr=this.css.clip.right||this.c[1]||this.w||0
	this.cb=this.css.clip.bottom||this.c[2]||this.h||0; 
	this.cl=this.css.clip.left||this.c[3]||0
	this.clipTo=panel_clipTo;	this.clipBy=panel_clipBy;
	this.layerObj = layerID + "Object"; 
	eval(this.layerID + "=this");
	return this
}

//Exemplo de uso
/*
<HEAD>
	<SCRIPT language="Javascript" src="panel.js" type="text/javascript">
	<SCRIPT languge="Javascript">
	<!--
	var panel1
	function Init(){
		panel1=new panel('panel1');
	}

	//-->
	</SCRIPT>
</HEAD>

<body background="/institucional/images/bggeral.gif"  onLoad="Init();">

	<A href="javascript:panel1.showIt();">showIt</A>

	<DIV ID="panel1" style="visibility:hidden; position:relative; left:100; top:100;">
		"conteudo do Panel"
		<A href="javascript:panel1.hideIt();">hideIt</A>
	</DIV>
<body background="/institucional/images/bggeral.gif" >
*/
