
  // Javascript expandable/collapsible menu by Sam Rutley


  // see if one string (haystack) contains another (needle)
  function strstr( haystack, needle ) {
    var pos = 0;
     pos = haystack.indexOf( needle );
    if( pos == -1 ){
        return false;
    }
    return true;
  }
  // initialise the menu tree
  function setupTree( treeID ) {
    var currPage = 0;
    var el = document.getElementById( "tUL" );
    var ul = el.getElementsByTagName( "ul" );
    var curr = window.location.pathname;
    var curr = curr.substring( curr.lastIndexOf( '/' ) + 1 );
    for ( var i=0; i < ul.length; i++ ) {
      var li = ul[i].getElementsByTagName("li");
      for ( var j=0; j < li.length; j++ ) {
        // Hide all categories
        li[j].style.display = "none";
        if( strstr( li[j].innerHTML, curr ) && "http://www.sherwoods-photo.com/" != window.location ) {
          // Highlight if current page = link
          //li[j].style.fontWeight = "bold";
          currPage = 1;
        }
      }
      if( currPage == 1 ) {
        // Expand category if current exists in category
        for ( var j=0; j < li.length; j++ ) {
          li[j].style.display = "block";
        }
        currPage = 0;
      }
    }
	checkPage();
  }
  // Expand/collapse the menu tree branch
  function branch( t ) {
    var li = t.getElementsByTagName( "li" );
    for ( var j=0; j < li.length; j++ ) {
      if( li[j].style.display == "none" ) { 
        li[j].style.display = "block";
      } else {
        li[j].style.display = "none";
      }
    }
  }
  
  function checkPage( ) {
	var a = document.getElementsByTagName( "a" );
	var name;
	var currPage = 0;
	var curr = window.location.pathname;
    var curr = curr.substring( curr.lastIndexOf( '/' ) + 1 );
	for ( var i=0; i < a.length; i++ ) {
		name = a[ i ].getAttribute( 'name' );
		if( name != null ) {
          if ( strstr( a[ i ].getAttribute( 'href' ), curr )  && "http://www.sherwoods-photo.com/" != window.location ) {
			  branch ( a[ i ].parentNode );
		  }
		}
	}
  }
  
