/******************************************************************************

* navbar.js                                                                   *

*                                                                             *

* Copyright 2005 by Mark Weaver.                                                *

* Web address: http://www.motosapiens.net.com                                        *

* Last update: 9/14/2005.                                             *

*                                                                             *

*        *

******************************************************************************/

var ActiveButton = null;

function Browser() {



  var ua, s, i;



  this.isIE    = false;  // Internet Explorer

  this.isOP    = false;  // Opera

  this.isNS    = false;  // Netscape

  this.version = null;



  ua = navigator.userAgent;



  s = "Opera";

  if ((i = ua.indexOf(s)) >= 0) {

    this.isOP = true;

    this.version = parseFloat(ua.substr(i + s.length));

    return;

  }



  s = "Netscape6/";

  if ((i = ua.indexOf(s)) >= 0) {

    this.isNS = true;

    this.version = parseFloat(ua.substr(i + s.length));

    return;

  }



  // Treat any other "Gecko" browser as Netscape 6.1.



  s = "Gecko";

  if ((i = ua.indexOf(s)) >= 0) {

    this.isNS = true;

    this.version = 6.1;

    return;

  }



  s = "MSIE";

  if ((i = ua.indexOf(s))) {

    this.isIE = true;

    this.version = parseFloat(ua.substr(i + s.length));

    return;

  }

}



var browser = new Browser();





function buttonMouseover(event, id)

{

  var menu;

  var button;

  var x, y;

  if (browser.isIE)

    button = window.event.srcElement;

  else

    button = event.currentTarget;



  ActiveButton = button;

	//make the submenu visible

	

  // Position the associated drop down menu under the button and

  // show it.



  x = getPageOffsetLeft(button);

  y = getPageOffsetTop(button) + button.offsetHeight;



  // For IE, adjust position.



  if (browser.isIE) {

    x += button.offsetParent.clientLeft;

    y += button.offsetParent.clientTop;

  }

  



	if(id != null)

	{

	menu =	document.getElementById(id);

	button.menu = menu;

	menu.style.left=x + "px";

	menu.style.top=y + "px";

	menu.style.visibility="visible";

	menu.onmouseout=onMouseOutHandler;

	



	//set onmouseouthandler



  if (button.onmouseout == null)

	button.onmouseout = onMouseOutHandler;

	}



    	

}



function onMouseOutHandler(event)

{

	if (ActiveButton == null)

    	return;

	if (browser.isIE)

		el = window.event.toElement;

	else if (event.relatedTarget != null)

	  	el = (event.relatedTarget.tagName ? event.relatedTarget : event.relatedTarget.parentNode);



  // If the element is not part of a menu, reset the active button.



	if (getContainerWith(el, "DIV", "menu") == null) 

	{   	

		ActiveButton.menu.style.visibility="hidden";

		ActiveButton = null;

	}

  

}



function getContainerWith(node, tagName, className) {



  // Starting with the given node, find the nearest containing element

  // with the specified tag name and style class.



  while (node != null) {

    if (node.tagName != null && node.tagName == tagName &&

        hasClassName(node, className))

        {

        	return node;

        

        }

    node = node.parentNode;

  }



  return node;

}

function hasClassName(el, name) {



  var i, list;



  // Return true if the given element currently has the given class

  // name.



  list = el.className.split(" ");

  for (i = 0; i < list.length; i++)

    if (list[i] == name)

      return true;



  return false;

}



function getPageOffsetLeft(el) {



  var x;



  // Return the x coordinate of an element relative to the page.



  x = el.offsetLeft;

  if (el.offsetParent != null)

    x += getPageOffsetLeft(el.offsetParent);



  return x;

}



function getPageOffsetTop(el) {



  var y;



  // Return the x coordinate of an element relative to the page.



  y = el.offsetTop;

  if (el.offsetParent != null)

    y += getPageOffsetTop(el.offsetParent);



  return y;

}





var windowArray = new Array();



//*****************************************************************************

// used to open a picture in a separate small window

//*****************************************************************************





function popupPicture(mylink, windowname, width, height)

{

if (! window.focus)return true;

var href;

if (typeof(mylink) == 'string')

   href=mylink;

else

   href=mylink.href;

awindow = window.open(href, windowname, 'scrollbars=no,menubar=no,toolbar=no,width=' + width + ' ,height=' + height);

windowArray[windowArray.length] = awindow;

return false;

}

function popupPictureSize(mylink, windowname, width, height)

{

if (! window.focus)return true;

var href;

if (typeof(mylink) == 'string')

   href=mylink;

else

   href=mylink.href;

awindow = window.open(href, windowname, 'scrollbars=no,menubar=no,toolbar=no,width=' + width + ' ,height=' + height);

windowArray[windowArray.length] = awindow;

return false;

}




//*****************************************************************************

// older code used to open a picture in a separate small window at a default width and height

//*****************************************************************************





function popupPicture(mylink, windowname)

{

if (! window.focus)return true;

var href;

if (typeof(mylink) == 'string')

   href=mylink;

else

   href=mylink.href;

awindow = window.open(href, windowname, 'scrollbars=no,menubar=no,toolbar=no,width=800, height=600');

windowArray[windowArray.length] = awindow;

return false;

}





//since the parent window of the picture is already a popup, let's clean up any stray child picture windows when we close.

//only closes one right now. could be modified to close an array full.

function closeWindows()

{

	var theWindow;

	for(var i=0; i<windowArray.length; i++)

	{

		theWindow = windowArray[i];

		if(theWindow)

			theWindow.close();

	}



}	