function loadNav(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	} 
	else
	{
		window.onload = function() { oldonload(); func(); }
	}
}

loadNav (
	function() {
		_cmdBar = new ClientCommandBar("navigation");

		// Force iFrame to setParent on first page load
		var frm=xGetElementById('iframemap');
		if (frm == null) return;

		if (typeof xGetElementById('iframemap').setParent == 'function')
		//if (typeof frames['iframemap'].setParent == 'function')
		{	xGetElementById('iframemap').setParent();
		}
	}
);

function ClientCommandBar(targetID)
{ this.aCommandArray = xGetElementsByTagName("img",  xGetElementById(targetID));
  this.aCheckGroup   = new Array();

  this.in_array = function(item, arr) { n=arr.length; for (var i=0; i<n; i++) {if (arr[i] == item) return true;} return false; }
  this.button = { name  : null, group : null }

  var o=this;
  var j=0;
  for ( var i=0; i<this.aCommandArray.length; i++ ) 
  {
    var oCmd = this.aCommandArray[i];
    if ( !oCmd.getAttribute("onclick") ) { oCmd.onclick = function() {o.onCommandMouseClick(this)}; }

    oCmd.onmouseover = function() { this.src = this.src.replace(/_off/, '_over'); };
    oCmd.onmouseout  = function() { this.src = this.src.replace(/_over/, '_off'); };

    var id = oCmd.getAttribute("id");
    if (id != null)
    { if (id == 'PAN' || id == 'ZOOM_IN' || id == 'ZOOM_OUT')
      {	this.aCheckGroup[j] = oCmd;
      	j++;
      }
    }
  }
}

var pcb = ClientCommandBar.prototype;
pcb.onCommandMouseClick = function(sender) 
{
  var id = sender.getAttribute("id");
  
  if ( this.in_array(sender, this.aCheckGroup) )
  {	// Turn off group
    for (var i=0; i<this.aCheckGroup.length; i++)
    {	this.aCheckGroup[i].src = this.aCheckGroup[i].src.replace(/_on|_over/, '_off');
    }
    sender.src = sender.src.replace(/_off|_over/, '_on');
  }

  var oTarget = xGetElementById('iframemap')._mapclient;
  //var oTarget = frames['iframemap']._mapclient;
  if (typeof oTarget == 'object') {
    oTarget.setCurrentTool(id, sender);
  }
}

pcb.restoreCurrentTool = function(oClient)
{
  if (typeof oClient != 'object') return;

	n=this.aCommandArray.length;
  for ( var i=0; i<n; i++ ) 
  {	var oCmd = this.aCommandArray[i];
    if (oCmd.src.search(/_on/g) != -1)
    {	var id = oCmd.getAttribute("id");

      if (id == 'PAN' || id == 'ZOOM_IN' || id == 'ZOOM_OUT')
      {	oClient.setCurrentTool(id, null);
      }
    }
  }
}

