// panel.js custom object for panel manipulation
// requires: prototype.js

var Panel = Class.create();

Panel.prototype = {

	initialize:function(o) {

		this.name = o.name;
		this.title = o.title;
	
		if(o.controlSetElement) { this.controlSetElement = $(o.controlSetElement); }
		this.headerElement = $('panelHeader');
		this.titleElement = $('panelTitle');
		this.bodyParentElement = $('panelBody');
		this.bodyElement = $('pan' + this.name);
		
		this.isOpen=false;
		this.hide();		
		this.setTitle(this.title);
		this.register();	
		
		if(o.tabNames) {
			var a = o.tabNames;
			this.tabs=new Object();
			for(i=0;i<a.length;i++)  {
				this.tabs[a[i]] = new Tab({name:a[i],bodyElement:this.name.toLowerCase() + 'Tab' + a[i],buttonElement:'tabButton_' + this.name + '_' + a[i],panelName:this.name});	
			}	
		}	
		return this;
	},

	open:function() {
		if(global.activePanel !== undefined) {global.activePanel.hide()};
		this.setTitle(this.title);		
		this.show();	
		this.isOpen=true;
		global.activePanel=this;
		if(this.tabs !== undefined && this.activeTab.setDeepLink !== undefined) {this.activeTab.setDeepLink();}
	},

	close:function() {
		this.hide();	
		this.isOpen=false;
		delete global.deepLink;
	},
	
	show:function() {
		Element.show(this.bodyElement);
		this.showControls();	
	},	
	
	hide:function() {
		Element.hide(this.bodyElement);
		this.hideControls();
	},

	hideControls:function() {
		if(this.controlSetElement) {Element.hide(this.controlSetElement);}

	},

	showControls:function() {
		if(this.controlSetElement) {Element.show(this.controlSetElement);}
	},

	register:function() {
		global.panels['panel' + this.name] = this;
	},

	setTitle:function(title) {
		Element.update(this.titleElement,title);
	},

	clearTitle:function() {
		Element.update(this.title,"&nbsp;");
	}
}





		