LIB_PATH = document.getElementsByTagName("script")[document.getElementsByTagName("script").length -1].src.replace(/common.js/, "")


function addStyle(style){
  document.write("<style>"+style+"<\/style>")
}



document.getElementsByClassName = function(className){
  var els
  var collection = new Array()
  if (document.all)
  {
    els = document.all
  }
  else if (document.getElementsByTagName)
  {
    els = document.getElementsByTagName("*")
  }

  for (var i=0; i<els.length; i++)
  {
    if (els[i].className == className) collection[collection.length] = els[i]
  }
  return collection
}

//import a js file from the lib
function includelib(src)
{
  return include(LIB_PATH + src)
}

//include (import) another js file if it has not already been loadeded
function include(src)
{
  //this little trick resolves the src url to be relative to the document
  var a = document.createElement("a")
  a.href = src
  src = a.href 
  
  var included = false
  for (var i=0; i<document.getElementsByTagName("script").length; i++){
    if (document.getElementsByTagName("script")[i].src == src){
      included = true
      break
    }
  }
  if (!included){
    //scrap this until it works in safari
    /*
    script = document.createElement("script");
    script.src = src
    document.getElementsByTagName("head")[0].appendChild(script)
    */
    
    //use the hacky method instead 
    document.write("<scr" + "ipt src='" + src + "'></scr" + "ipt>");
  }
  return included
}




//http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function get(variable) {
  //from http://www.activsoftware.com/code_samples/code.cfm/CodeID/59/JavaScript/Get_Query_String_variables_in_JavaScript
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
}

function zap(el){
  if (el && el.style) el.style.display = "none"
}

function unzap(el){
  if (el && el.style) el.style.display = ""
}
