
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

/*
	getElementsByClassName Written by Jonathan Snook, http://www.snook.ca/jonathan
	getElementsByClassName Add-ons by Robert Nyman, http://www.robertnyman.com
*/

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 prepareBlockquotes() {
	if (!document.getElementsByTagName || !document.createElement || !document.appendChild) return;
	var quotes = document.getElementsByTagName("blockquote");
	for (var i=0; i<quotes.length; i++) {
		var source = quotes[i].getAttribute("cite");
		if (!source) continue;
		var para = document.createElement("p");
		var link = document.createElement("a");
		para.className = "attribution";
		link.setAttribute("href",source);
		link.setAttribute("title","Link to source");
		link.appendChild(document.createTextNode("source"));
		para.appendChild(link);
		quotes[i].appendChild(para);
	}
}


function showHide() {
  if(!document.getElementsByTagName) return false;
  
  var infoDivs = getElementsByClassName(document, "div", "off");
  
  //var divs = document.getElementsByTagName("div");
  for (var i=0; i<infoDivs.length; i++) {
    infoDivs[i].onmouseover = function() {
      this.className = "on";
    }
    infoDivs[i].onmouseout = function() {
      this.className = "off";
    }
  }
}


function initPopups() {

//alert("hello");

	if (!document.getElementById) return
	
	var aLinks = document.getElementsByTagName('a');

	for (var i = 0; i < aLinks.length; i++) {		
		if (aLinks[i].className == 'popup' || aLinks[i].className == 'external') {
			
			if (aLinks[i].className == 'popup') {
				aLinks[i].onclick = function() {
					var url = this.href;
					openPopup(url,1);
					return false;
					}
				}
			else {
				aLinks[i].onclick = function() {
					var url = this.href;
					openPopup(url,0);
					return false;
					}
				}	
		}
	}
}

// popupWindow function
// This is where you set your specific height & width etc... for your popups.
function openPopup(url,popType) {
	if (popType==1)
		window.open(url, 'popupwindow', 'width=550,height=550,scrollbars,resizable'); 
	else
		window.open(url);
	return false;
}




addLoadEvent(prepareBlockquotes);
addLoadEvent(initPopups);
addLoadEvent(showHide);



