
/*******************************************************************
* Panel - the object that manages the tools and layers divs
*******************************************************************/ 
function Panels() {

	// keep track of the query string 
	var currentTool="";
	var currentToolObj=null;
	var currentPanel="";
	var tools;
	var dataSource;

	// init gets called onload.  it's responsible for setting up first time stuff
	this.init=function() {
		// point our div pointers to the actual div elements
		this.tools=new Array();
	}
	
	this.queryString=function() {
    return "tool="+this.currentTool;
	}
	
	this.getTool=function(tool_id) {
	 var toolObj=null;
	  for (var i=0;i<this.tools.length;++i) {
	    if ((this.tools[i]).id==tool_id) {
	      toolObj=this.tools[i];
	      break;
	    }
	  }
	  return toolObj;
	}
  
	///////////////////////// tool event handlers ///////////////////////////
	this.onToolClick=function(tool) {
		// some tools are actually just buttons so when they're clicked,
		// they don't get "selected".  for those tools don't select the 
		// tool, but for the rest, do.
    
    var toolObj=this.getTool(tool);
    if (!toolObj) {
      alert('unable to find tool '+tool);
      return;
    }
    
		if (toolObj.canBeCurrent) {
			if (this.currentTool==tool) return;
			// first de-activate the old tool
			var tooldiv=document.getElementById("tool_"+this.currentTool);
			tooldiv.className="tool_off";
      tooldiv.style.backgroundColor='#fff';
      
			// activate the newly selected tool
			tooldiv=document.getElementById("tool_"+tool);
			tooldiv.className="tool_on";
			tooldiv.style.backgroundColor='#ddd';

			// synch our pointer to the currentTool
			this.currentTool=tool;
			this.currentToolObj=toolObj;
			
			if (tool!="info_query") {
		    if (closeQueryTab!=null && closeQueryTab!=undefined) {
		      closeQueryTab();
		    } else {
		      alert('closeQueryTab is null');
		    }
			}
		}
	}
  
  this.onPanelClick=function(new_panel) {
    if (this.currentPanel.length>0) {
  		document.getElementById(this.currentPanel+"_panel").style.display="none";
  		document.getElementById(this.currentPanel+"_li").className="off";
  		document.getElementById(this.currentPanel+"_a").className="off";
    }
    
		var panel=document.getElementById(new_panel+"_panel");
		panel.style.display="block";
		document.getElementById(new_panel+"_li").className="on";
		document.getElementById(new_panel+"_a").className="on";

    var windowHeight;
    if (self.innerWidth) {
      windowHeight=self.innerHeight-1;
    } else if (document.documentElement && document.documentElement.clientWidth) {
      windowHeight=document.documentElement.clientHeight-1;
    } else if (document.body.clientHeight) {
      windowHeight=document.body.clientHeight-1;
    } else {
      windowHeight=document.body.offsetHeight-1;
    }

    var headerHeight=headerdiv.offsetHeight;
    var panelsHeight=panelsdiv.offsetHeight
		newHeight=(windowHeight-headerHeight-panelsHeight-15)+"px";
		panel.style.height=newHeight;

		newTop=(headerHeight+panelsHeight)+"px";
		panel.style.top=newTop;

		this.currentPanel=new_panel;
	}
	
	this.onLayerClick=function(layer_id) {
    var layerObj=currentLayerState.getLayer(layer_id);
    if (layerObj.canToggleOnOff) {
      var layer_input=document.getElementById(layer_id+"_input");
      layerObj.isOn=layer_input.checked;
    }
	}
	
	this.onGroupClick=function(group_id) {
    
	}
}
