/*
   Simple JQuery Collapsing nav_524891.
   HTML structure to use:

   <ul id="nav_524891">
     <li><a href="#">Sub nav_524891 heading</a>
     <ul>
       <li><a href="http://site.com/">Link</a></li>
       <li><a href="http://site.com/">Link</a></li>
       <li><a href="http://site.com/">Link</a></li>
       ...
       ...
     </ul>
     <li><a href="#">Sub nav_524891 heading</a>
     <ul>
       <li><a href="http://site.com/">Link</a></li>
       <li><a href="http://site.com/">Link</a></li>
       <li><a href="http://site.com/">Link</a></li>
       ...
       ...
     </ul>
     ...
     ...
   </ul>

Copyright 2007 by Marco van Hylckama Vlieg

web: http://www.i-marco.nl/weblog/
email: marco@i-marco.nl

Free for non-commercial use
*/

function initnav_524891() {
  $('#nav_524891 ul').hide(); 
  $('#nav_524891 li.selected ul').show();
  $('#nav_524891 li a').click(
    function() {
        $(this).next().slideToggle('normal');	
      }
    );
  }
$(document).ready(function() {
SetSelectedCSSItem("nav_524891");
     initnav_524891();
});
function SetSelectedCSSItem(menuid) {
    var _host = document.location.host;
	var _url = encodeURI(document.location.href.substring(document.location.href.indexOf(_host)+_host.length).toLowerCase());
	var _anchor;
    var _parent;
    var _class;
    var _image;
    var _anchors = document.getElementById(menuid).getElementsByTagName('a');
	var ie = false;
	var detect = navigator.userAgent.toLowerCase();	
	if (detect.indexOf('msie') > 0) ie = true;
	    
	if (_url.indexOf('?') != -1) _url = _url.substring(0,_url.indexOf('?')); // must remove query variables
    for (var i=0;i<_anchors.length;i++) {
	    _anchor = _anchors[i].href.substring(document.location.href.indexOf(_host)+_host.length).toLowerCase();
	    if (_anchor == _url) {
            _image = _anchors[i].getAttribute('selimg'); // sel img is on anchor
			if (_image)
			    _anchors[i].style.background = "url("+_image+")";					
		    _parent = _anchors[i].parentNode; // get li node
		    while (_parent) {
			    if (_parent.id == menuid) break; // don't go up infinitely
			    if (_parent.tagName == "LI") {
				    _class = _parent.getAttribute('selcss'); // sel css is on li
				    if (_class)				
					    _parent.className = _class; 
				    else { // logic below as per partner req't
				        if (ie)
				            _class = _parent.getAttribute('className'); 
				        else
				            _class = _parent.getAttribute('class'); 
				        if (_class)
					        _parent.className = _class+" selected";	
				        else {
					        _parent.className = "selected";	
                                         }
					}
			    }
			    _parent = _parent.parentNode;
		    }
		    break;
	    }
	}
}