// JavaScript Document//
addEvent(window, 'load', prepPopups);
addEvent(window, 'load', externalLinks);

 //addEvent() by John Resig
	function addEvent( obj, type, fn ){
	   if (obj.addEventListener){ 
	      obj.addEventListener( type, fn, false );
	   }
	   else if (obj.attachEvent){ 
	      obj["e"+type+fn] = fn; 
	      obj[type+fn] = function(){ obj["e"+type+fn]( window.event ); } 
	      obj.attachEvent( "on"+type, obj[type+fn] ); 
	   } 
	} 
	
function prepPopups(){
	if (!document.getElementsByTagName) return false;
	var anchors = document.getElementsByTagName("a");
 	for (var i=0; i<anchors.length; i++){
    	if (anchors[i].getAttribute("rel") == "popup"){
			anchors[i].onclick = function(){
				return createPopup(this);
			}
 		}
	}
}

function createPopup(newPopup){
	var url = newPopup.getAttribute("href");
	if (newPopup.getAttribute("class")){
		popClass = newPopup.getAttribute("class");
	}else{
		popClass = newPopup.getAttribute("className");
	}
	//take only the first class if multiple classes
	var temp0 = new Array;
	temp0 = popClass.split(' ');
	var temp1 = new Array;
	//split into width and height values
	temp1 = temp0[0].split('x');
	var width = "width=" + temp1[0];
	var height = "height=" + temp1[1];
	var features = width + "," + height;
	return popThis(url,'_blank',features);
}

function popThis(url, target, features) {
    if (isUndefined(features)) features = 'width=500,height=500';
    if (isUndefined(target  )) target   = '_blank';
    var theWindow = window.open(url, target, features);
    theWindow.focus();
    return false;
 }
 
  // MISC CLEANING-AFTER-MICROSOFT STUFF
function isUndefined(v) {
    var undef;
    return v===undef;
}

function externalLinks() { 
	 if (!document.getElementsByTagName) return;
	 var anchors = document.getElementsByTagName("a"); 
	 for (var i=0; i<anchors.length; i++) { 
	 	if (anchors[i].getAttribute("href") && (anchors[i].getAttribute("rel") == "external")) {
      		anchors[i].target = "_blank"; 
	 	}
  	} 
 } 