/* ================================================================ 
This copyright notice must be untouched at all times.

The original version of this script and the associated (x)html
is available at http://www.stunicholls.com/menu/tree_frog_vertical.html
Copyright (c) 2005-2007 Stu Nicholls. All rights reserved.
This script and the associated (x)html may be modified in any 
way to fit your requirements.
=================================================================== */

clickMenu = function(menu) {
  var getEls = document.getElementById(menu).getElementsByTagName("li");
  var getAgn = getEls;

  for (var i = 0; i < getEls.length; i++) { // Assign click, mouseover & mouseout events for each main <li> in menu <ul>

//    if (getEls[i].id != "")
//      alert(getEls[i].id);

    if (getEls[i].id == getCookieValue("selectedMenuItemId")) {
      getEls[i].className += " click";
    }

	getEls[i].onclick = function() {

      for (var x = 0; x < getAgn.length; x++) {
	    getAgn[x].className = getAgn[x].className.replace("unclick", "");
		getAgn[x].className = getAgn[x].className.replace("click", " unclick");
	  }

	  if (this.className.indexOf("unclick") != -1) { // hiding <li>
		this.className = this.className.replace("unclick", "");;
        writeSessionCookie ("selectedMenuItemId", "none");
	  }	else { // showing <li>
	    this.className += " click";
        writeSessionCookie ("selectedMenuItemId", this.id);
	  }

	}

	getEls[i].onmouseover = function() {
	  this.className += " hover";
	}

	getEls[i].onmouseout = function() {
	  this.className = this.className.replace("hover", "");
	}
  }
}
