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

 //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 if (newPopup.getAttribute("className")){
		popClass = newPopup.getAttribute("className");
	} else {
		popClass = "500x500";
	}
	var temp = new Array;
	temp = popClass.split('x');
	var width = "width=" + (parseInt(temp[0]) + 10); //add 10 px to width and height of popup window
	var height = "height=" + (parseInt(temp[1]) + 10);
	var features = width + "," + height + ",scrollbars=no";
	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;
 }
 
function isUndefined(v) {
    var undef;
    return v===undef;
}
