/* LOADER */

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(popups);

/* ==========================================================================================
	 FIX MAILTO
*/

function fillEmail (locations, addrs) {
	for (var i = 0; i < locations.length; i++) {
		value = addrs[locations[i]][0] + addrs[locations[i]][1] + addrs[locations[i]][2] +
		addrs[locations[i]][3] + addrs[locations[i]][4];
		if (document.getElementById(locations[i])) {
		  document.getElementById(locations[i]).href = 'mailto:' + value;
		  document.getElementById(locations[i]).innerHTML = value;
		}
	}
}


/* ==========================================================================================
	 Suckerfish dropdowns with jquery goodness
*/

$(document).ready(function(){
    $("#primaryNav ul li ul li").hover(
        function(){ $("ul", this).fadeIn("fast"); },
        function() { }
    );
    if (document.all) {
        $("#primaryNav ul li ul li").hoverClass("sfHover");
    }
});

$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover(
            function() { $(this).addClass(c);  },
            function() { $(this).removeClass(c); }
        );
    });
};


/* ==========================================================================================
	 POPUPS
*/

function popups() {

  if (!document.getElementsByTagName) return false;
  var links = document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) {
    if (links[i].className.match("popup")) {

     x = links[i].getAttribute("rel");
     var rel = new Array();
     rel = x.split(" ");
     if (rel[2]) {
      //with controls
      links[i].onclick = function() { window.open(this.getAttribute("href"), "popup1","width="+rel[0]+",height="+rel[1]+",toolbar=yes, directories=yes, location=yes, status=yes, menubar=yes, resizable=yes, scrollbars=yes"); return false; };
     } else {
       //no controls
       links[i].onclick = function() { window.open(this.getAttribute("href"), "popup1","width="+rel[0]+",height="+rel[1]+",resizable=yes, status=yes"); return false; };
     }//end control check
    } else if (links[i].className.match("video")) {
      links[i].onclick = function() { window.open("popup-video.html?file="+this.getAttribute("href")+"&caption="+this.getAttribute("caption"), "popup1","width=500, height=450, toolbar=yes, directories=yes, location=yes, status=yes, menubar=yes, resizable=yes, scrollbars=yes"); return false; };
    }
  }

}//END