// JavaScript Document
//Based on 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("#bonustext") != -1) { // back to top
      a.className = "alt";
    } else if ((href.indexOf("#") != -1) && (href.indexOf("bonustext") == -1)) { // jump ref
      var index = href.indexOf("#") + 1;
      href = "javascript:show('" + href.substring(index) + "');";
      a.setAttribute("href",href);
    }
  }
}

function hideDds(exempt)
{
  if (!document.getElementsByTagName) return null;
  if (!exempt) exempt = "";
  var dds = document.getElementsByTagName("dd");
  for(var i=0; i < dds.length; i++)
  {
    var dd = dds[i];
    var id = dd.id;
    if ((id != "header") && (id != "footer") && (id != exempt))
    {
		dd.className = "hidden";
    }
  }
}

function show(what)
{
  if (!document.getElementById) return null;
  showWhat = document.getElementById(what);
	if (showWhat.className == "") {
			showWhat.className = "hidden";
		}
		else { 
  showWhat.className = "";
		}
  hideDds(what);
}

function popUp(myurl) 
{
	window.open(myurl, "inventio", "width=800,height=600,scrollbars=yes,resizable=yes,location=yes,toolbar=yes");
}


function preparePopups() 
{
	if (!document.getElementsByTagName) return null;
	var lnks = document.getElementsByTagName("a");
	for (var i=0; i<lnks.length; i++) {
		if (lnks[i].className == "standalone") {
			lnks[i].onclick = function() {
				popUp(this.getAttribute("href"));
				return false;
			}
		}
	}
}
	



/*
Simon Willson's addLoadEvent function.
See http://simonwillison.net/2004/May/26/addLoadEvent/
*/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

/*window.onload = function()
{
  fixLinks();
  hideDds();
}*/
addLoadEvent(fixLinks);
addLoadEvent(hideDds);
addLoadEvent(preparePopups);