//  ___________
// | BaseGUI   |____________________________________________________
// |                                                                |
// |  core GUI object and core interfaces to work with EventManager |
// |________________________________________________________________|
//
function BaseGUI(id,theme,html)
{   
    this.id = id;
	this.x=0;this.y=0;
	this.type = 'gui';  //type used sometimes by guiManager
    this.theme = theme;
    this.content = html
    this.layer = new Array();
	this.xOffset=new Array(0,0);
	this.yOffset=new Array(0,0);
    this.show = show;
    this.hide = hide;
	this.visible = false;
    this.close = aGUIclose;
    this.focus = aGUIfocus;
    this.blur = emptyFunction;
    this.parseXY = aGUIparseXY;
    this.setXY = setXY;
    this.makeLayer = makeLayer;
    this.drag=aGUIdrag;
	this.dragType=null;
    this.dragStop = aGUIdragStop;
    this.dragStart = aGUIdragStart;
    this.setBgColor = aGUIsetBgColor;
	this.setFloating = setFloating;
	this.unsetFloating = unsetFloating;
    this.guiManager = guiManager;     
}
function setFloating()
{
	this.type = 'floating';
}
function unsetFloating()
{
	this.type = 'gui';
}
function aGUIparseXY()
{
    this.guiManager.dragObject = this;
	this.dragStart();
}
function aGUIsetBgColor(layerObject,themeReference)
{
    if (ns)
        layerObject.bgColor=this.theme[themeReference];
    else
        layerObject.backgroundColor=this.theme[themeReference];
}
function emptyFunction()
{
}
function aGUIfocus(z)
{
    for(i=0;i<this.layer.length;i++)
    {
        this.layer[i].zIndex=z+i;
    }
	
}
function aGUIdragStart()
{	

	//this.dragType=0;
	if(w3||ie)
	{
		guiManager.dragBox.setSize(this.clipW,this.clipH)
		guiManager.dragBox.setXY(this.x,this.y,1);
		this.dragGUI = guiManager.dragBox;
		this.dragGUI.layer[0].zIndex=guiManager.superZ;
		if(this.theme["dragOpacity"])
		{
			for (this.i=0;this.i<this.layer.length;this.i++){
			this.layer[this.i].MozOpacity=this.theme["dragOpacity"];
			this.layer[this.i].filter="alpha(Opacity="+(this.theme["dragOpacity"]*100)+")";
		    }
		}
		//this.dragGUI.setColor(this.theme['border']);
	}
	else if(ns)
	{	
		if(this.layer.length>2){
			if(this.layer[2].document.forms.length>0){
				this.layer[2].visibility="hidden";
				this.setBgColor(this.layer[0],'bgColor');
			}
		}	
		this.dragGUI = this;
	}


}
function aGUIdragStop()
{
	if((w3||ie) && this.dragType==0)
	{
		this.dragGUI.hide();
		this.setXY();
		this.focus(this.layer[0].zIndex);
	}
	if(ns)
		{
			if(this.layer.length>2){
				if(this.layer[2].document.forms.length>0){
					this.layer[2].visibility="visible";
					this.setBgColor(this.layer[0],'border');
				}
			}	
		}
	//this.dragType=0;
	this.dragGUI = null;
	
}
function aGUIdrag()
{
   this.x += this.guiManager.dx;
   this.y += this.guiManager.dy;
   if(this.x<0)this.x=0;
   if(this.y<0)this.y=0;
   if(w3||ie) guiManager.dragBox.setXY(this.x,this.y);
   else if(ns) this.setXY()
}
function show()
{
	if (this.setDisplay)
		this.setDisplay(true);
    for(i=0;i<this.layer.length;i++){
       // alert(i);
        if (this.scrollFlag==false && (i>2 &&i<7))
          continue;
        
        this.layer[i].visibility="visible";
		
    }    
    guiManager.addObject(this);             
	this.visible = true;
    
}
function hide(nokill)
{  
     for(i=0;i<this.layer.length;i++)
        this.layer[i].visibility="hidden"; 
	 //this.setXY(0,-2500); 
	 this.visible = false;
	 if(!nokill)
	  guiManager.killObject(this,true); 
}

function aGUIclose()
{	
    this.hide(true);
	
	if(w3)
    {
        guiManager.hideGUI(this);
    }
    if(ns)
	{
		guiManager.killObject(this);
	}
	
     
}
function setXY(x,y,visBOOL)
{   
     if (arguments.length==0)
	   {
		    x= this.x;
		    y= this.y;
	   }  
	   else{
		   this.x=x;
		   this.y=y;
	   }
	   for(i=0;i<this.layer.length;i++)
	   {
	   	this.layer[i].left=x+this.xOffset[i];
	   	this.layer[i].top=y+this.yOffset[i];
	   }
	   if (visBOOL)
	   		this.show();
	   

}