function change_link_class(link_href, new_class_name)
{
  if (!document.getElementsByTagName) return null;
  
  var anchors = document.getElementsByTagName("a");
  for(var i=0; i < anchors.length; i++)
  {
    var a = anchors[i];
    var href = a.href;
	if (a.className == new_class_name) 
	{ 
      a.className = "";
    } 
    if (href.indexOf(link_href) != -1)
	{ 
      a.className = new_class_name;
	  a.blur();
    } 
  }
}
/*
function get_default_div()
{
	var anchors = document.getElementsByTagName("a");
	for(var i=0; i < anchors.length; i++)
	{
		var a = anchors[i];
		if (a.className == "current" && (a.href.indexOf("item") != -1)) 
		{ 
			var index = a.href.indexOf("#") + 1;
			return a.href.substring(index);
		} 
	}
}*/

function extract_anchor_requested_from_location_bar()
{
	var anchor_requested;
	if( window.location.href.indexOf( "#" ) + 1 )
		anchor_requested = window.location.href.substr(window.location.href.indexOf("#") + 1);
	else
		anchor_requested = "";
	return anchor_requested
}


//========================================================================
// DHTML SUB NAVIGATION FUNCTIONS
// from http://www.alistapart.com/articles/eatcake/
//========================================================================
function fixLinks()
{
  if (!document.getElementsByTagName) return null;
  var server = document.location.hostname;
  var anchors = document.getElementsByTagName("a");
  for(var i=0; i < anchors.length; i++)
  {
    var a = anchors[i];
    var href = a.href;
    var id = a.id;
    var title = a.title;
    if (href.indexOf("#header") != -1) // back to top
	{ 
      a.className = "alt";
    } 
	else if ((href.indexOf("#") != -1) && (href.indexOf("header") == -1)) // jump ref
	{ 
      var index = href.indexOf("#") + 1;
      href = "javascript:show('" + href.substring(index) + "');";
      a.setAttribute("href",href);
    }
  }
}

function hideDivs(exempt) // hides all divs except the default one
{
  if (!document.getElementsByTagName) return null;
  
  /*var exempt = get_default_div();*/
  var divs = document.getElementsByTagName("div");
  for(var i=0; i < divs.length; i++)
  {
    var div = divs[i];
    var id = div.id;
	if (id.indexOf("item_") != -1 && id != exempt)
    {
		div.style.display = "none";
    }
  }
}

function show(what)
{
  if (!document.getElementById) return null;
  
  hideDivs();
  change_link_class(what,"current");
  showWhat = document.getElementById(what);
  showWhat.style.display = "block";
}

window.onload = function()
{
	var anchor_requested = extract_anchor_requested_from_location_bar();
	if(anchor_requested == "")
		anchor_requested = "item_1";
		
	hideDivs(anchor_requested);
	scrollTo(0,0);
	fixLinks();
	change_link_class(anchor_requested, "current")
	
}