/*
	Sitemap Styler v0.1
	written by Alen Grakalic, provided by Css Globe (cssglobe.com)
	visit http://cssglobe.com/lab/sitemap_styler/
	visit http://grakalic.com


        Javascript modified *sligtly* by Thomas Schulz
        for use with A1 Sitemap Generator
*/
this.sitemapstyler = function() {

  var sitemap_ul = document.getElementById("sitemap")
  var sitemap_li = document.getElementById("sitemap_first_li")

  if ( (sitemap_ul) && (sitemap_li) ) {

    this.listItem = function(li) {

      if 
      (
        (li.getElementsByTagName("ul").length > 0)
        &&
        //(li.getElementsByTagName("span").length > 0)
        (true)
      )
      {

        var ul = li.getElementsByTagName("ul")[0];
        //var span = li.getElementsByTagName("span")[0];
	var span = document.createElement("span");

        if (li == sitemap_li) {
          ul.style.display = "block";
          span.className = "expanded";
        }
        else {
          ul.style.display = "none";
          span.className = "collapsed";
        }

	span.onclick = function() {
          if (ul.style.display == "none") {
            ul.style.display = "block";
            this.className = "expanded";
          }
          else {
            ul.style.display = "none";
            this.className = "collapsed";
          }
	}

        li.appendChild(span);
      }
    }


    var items = sitemap.getElementsByTagName("li");

    for(var i=0; i<items.length; i++) {
      listItem(items[i]);
    }

  }

}

window.onload = sitemapstyler;