//--------------Panel-----------------------------

axe.panel = function(inits){
	
	
	this.desktop = inits["desktop"];
	this.url = inits["url"];
	this.loc = document.getElementById("panelSpace");	
	this.id = YAHOO.util.Dom.generateId(this,"panel");
	this.desktop = desktop;
	desktop.objects[""+this.id] = this;
	this.HTML = document.createElement("div");
	this.HTML.className="panel";
	this.HTML.id = this.id;
	this.selection = null;
	this.header = new axe.panelHeader(this);

	this.content = new axe.panelContent(this,inits);
	this.footer = new axe.panelFooter(this);
	this.closeButton = new axe.panelButton("images/icon_close.png","close",this);	
	
	this.header.HTML.appendChild(this.closeButton.HTML);
		this.loc.appendChild(this.HTML);

	YAHOO.util.Event.addListener(this.closeButton.HTML, "click", this.close,this);
	YAHOO.util.Event.addListener(this.HTML,"click",this.handleClick,this);			
	YAHOO.util.Event.onAvailable(this.HTML.id, this.handleOnAvailable, this); 
}
axe.panelClicked = new YAHOO.util.CustomEvent("panelClicked");
axe.tagClicked = new YAHOO.util.CustomEvent("tagClicked");
axe.tagCreated = new YAHOO.util.CustomEvent("tagCreated");


axe.panel.prototype.handleClick = function(e,obj){
	panel = obj;
	//thisId = obj.HTML.id;
	desktop = obj.desktop;
	
	axe.panelClicked.fire({panel: panel, workspace: desktop});
	
}
axe.panel.prototype.close = function(e,obj){
	if (obj.sidePanel) {
		obj.sidePanel.close();
	}
	obj.HTML.parentNode.removeChild(obj.HTML);
	YAHOO.util.Event.stopEvent(e);
}

axe.panel.prototype.clearContents= function(){
	contents = this.content.HTML.childNodes;

	for (i=0;i<contents.length;i++){
		
		contents[i].parentNode.removeChild(contents[i]);
	}
	
}


axe.panel.prototype.setContent = function(contentObj){
	
	//this.clearContents();

	
	
}



axe.panel.prototype.handleOnAvailable = function(panel){
	
	draggable = new YAHOO.util.DD(this.id);
	
	draggable.setHandleElId(this.id+"_handle");
	
// Yahoo code for making a resizable panel

	this.yResize = new YAHOO.util.Resize(this.id, {
                handles: ['br'],
				
                autoRatio: false,
                minWidth: 300,
                minHeight: 100
               
            });

            // Setup resize handler to update the size of the Panel's body element
            // whenever the size of the 'resizablepanel' DIV changes
      this.yResize.on('resize', function(args) {
			
                var panelHeight = args.height;
				var panelWidth = args.width;       	
                var headerHeight = this.firstChild.offsetHeight;	 // Content + Padding + Border

				if (this.childNodes[2]){
                	var footerHeight = this.childNodes[2].offsetHeight; // Content + Padding + Border
				
				}
				else
				{
					footertHeight=0;
				}
				//document.getElementById("debug").innerHTML=footerHeight;
				
                var bodyHeight = (panelHeight - headerHeight - footerHeight);
				
              //  var bodyContentHeight = (IE_QUIRKS) ? bodyHeight : bodyHeight - PANEL_BODY_PADDING;
 var bodyContentHeight =  bodyHeight;
				
                YAHOO.util.Dom.setStyle(this.childNodes[1], 'height', bodyContentHeight + 'px');
				YAHOO.util.Dom.setStyle(this.childNodes[1].firstChild, 'height', bodyContentHeight + 'px');
				YAHOO.util.Dom.setStyle(this.childNodes[1].firstChild, 'width', (.85*panelWidth) + 'px');
		

            }, this, true);
			axe.panelClicked.fire({panel: panel, workspace: panel.desktop});
}

				


//----------END PANEL-------------------------

//------PanelHeader--------------
axe.panelHeader = function(panel){
	this.panel = panel;
	
	this.HTML = document.createElement("div");
	this.HTML.className = "hd";
	this.HTML.id = this.panel.id+"_handle";
	this.panel.HTML.appendChild(this.HTML);
	//YAHOO.util.Event.addListener(this.HTML, "mouseup", showX);
	//  Add panelHeader contents here
}


//-------PanelBody----------------
axe.panelContent = function(panel){
	this.panel = panel;
	this.HTML = document.createElement("div");
	this.HTML.className = "bd";
	this.panel.HTML.appendChild(this.HTML);
}

//--------PanelFooter----------------
axe.panelFooter = function(panel){	
	this.panel = panel;
	this.HTML = document.createElement("div");
	this.HTML.className = "ft";

	
	this.panel.HTML.appendChild(this.HTML);
}
//---------Panel Button---------------
axe.panelButton = function(img,type,panel){
		this.id = YAHOO.util.Dom.generateId(this,"panelButton");
	//desktop.objects[this.id] = this;
	
	this.image = document.createElement("img");
	this.image.src = img;
	this.type=type;
	this.panel=panel;

	this.HTML = document.createElement("span");
	if (type == "close") {
		this.HTML.className = "closeButton";
	}
	else {
		this.HTML.className = "panelButton";
	}
	this.HTML.appendChild(this.image);
	this.HTML.style.cursor = "default";
	this.HTML.id = this.id;
	this.panel.desktop.objects[this.id] = this;

}

axe.panelButton.prototype.changeImage= function(imgsrc){

	this.HTML.firstChild.src=imgsrc;
}
