// Dom Scripting, Jeremy Keith, Friends of Ed 2005 / 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() {
      oldonload();
      func();
    }
  }
}


// This is a rough and ready approach to updating navigation based on the URL that, without editing, will work only with the stratacollective site...
$(document).ready(
    function() {
        var path = location.href;
		    
	var tidyPath = path.split("stratacollective.org/")[1];
	    
	var splitTidyPath = tidyPath.split("/");
	var navtopLength = $("#navtop").find("a").length -1;
	    
	$($("#navtop").find("a").get().reverse()).each(
	    function(index){
		if($(this).attr("href") == splitTidyPath[0] || splitTidyPath[0] == "" && $(this).attr("href") == "index.htm"){
			setActiveNavigation(this);
			setActiveNavigation($("#navbottom").find("a").eq(navtopLength-index));
			// break out of the loop
			return false;
		}
		// Check for soundlines or other subfolder...
		else if ($(this).attr("href") == splitTidyPath[1] || splitTidyPath[0] == "soundlines" && $(this).attr("href") == "index.htm") {
			setActiveNavigation(this);

			if($("#soundlinesnav").length != 0){
			    setActiveNavigation($("#soundlinesnav").find("a:eq(0)"));
			    setActiveNavigation($("#navbottom").find("a").eq(navtopLength-index));
			}
			// break out of the loop
			return false;
		}
		else if ($(this).attr("href") == splitTidyPath[2] || splitTidyPath[1] == "playback" && $(this).attr("href") == "index.php") {
			setActiveNavigation(this);
			// break out of the loop
			return false;
		}
	    }
	);
    }
);
    
function setActiveNavigation(thisObject) {
  $(thisObject).parent().addClass("navactive");
  var linkText = $(thisObject).html();
  $(thisObject).parent().html("<span>" + linkText + "</span>");

}