/**
 * Global context array
 * contexts are strings with an optional namespace
 * ex: "record:display"  
 */ 
var context = new Array();

/**
 * Adds a context string to the global context array
 */ 
function addContext(lContext){
  var exists = false;
  for(x in context){
    if(context[x] == lContext) {
      exists = true;
      break;
    }
  }
  if(!exists){
    context.push(lContext);
  }
  
}

/**
 * Checks to see if the context string has been added to the global context array
 */ 
function inContext(lContext) {
  var exists = false;
  for(x in context){
    if(context[x] == lContext) {
      exists = true;
      break;
    }
  }
  return exists;
}
/**
 * Gets the global context array
 * @TODO make the context array private
 */  
function getContext(){
  return context;
}

/**
 * Creates a style element referencing the given URL and appends it to the document
 */ 
function addCSS(url){
  var scriptElement = document.createElement("link");
	scriptElement.setAttribute("href", url);
	scriptElement.setAttribute("rel", "stylesheet");
	scriptElement.setAttribute("type", "text/css");
	document.documentElement.firstChild.appendChild(scriptElement);	
}

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

$(document).ready(function() {
   // @TODO add context check here to avoid extra http requests
  addCSS(scriptURL+'common/css/cluetip.css');
   
  $.ajax({ url:scriptURL+'common/js/jquery.cookies.js', dataType: "script", cache: true } );
  
  // @TODO add context check here to avoid extra http requests
  $.ajax({ url:scriptURL+'common/js/jquery.cluetip.js', dataType: "script", cache: true } );
  $.ajax({ url:scriptURL+'offcampus/'+environment+'/offcampus.js', dataType: "script", cache: true } );

 
   /*
   if(environment == 'staging') {
      
   }
   else {
    
   }
   */
   
});
