function addLoadListener(fn) {
	if (typeof window.addEventListener != 'undefined') {
		window.addEventListener('load', fn, false);
	}
	else if (typeof document.addEventListener != 'undefined') {
		document.addEventListener('load', fn, false);
	}
	else if (typeof window.attachEvent != 'undefined') {
		window.attachEvent('onload', fn);
	}
	else {
		return false;
	}
	return true;
}

function getElementsByAttribute(attribute, attributeValue) {
	var elementArray = new Array();
	var matchedArray = new Array();

	if (document.all) {
		elementArray = document.all;
	}
	else {
		elementArray = document.getElementsByTagName("*");
	}

	for (var i = 0; i < elementArray.length; i++) {
		if (attribute == "class") {
			var pattern = new RegExp("(^| )" + attributeValue + "( |$)");

			if (pattern.test(elementArray[i].className)) {
				matchedArray[matchedArray.length] = elementArray[i];
			}
		}
		else if (attribute == "for") {
			if (elementArray[i].getAttribute("htmlFor") || elementArray[i].getAttribute("for")) {
				if (elementArray[i].htmlFor == attributeValue) {
					matchedArray[matchedArray.length] = elementArray[i];
				}
			}
		}
		else if (elementArray[i].getAttribute(attribute) == attributeValue) {
			matchedArray[matchedArray.length] = elementArray[i];
		}
	}

	return matchedArray;
}

function makePopup(url, width, height, overflow)
{
  // if (width > 640) { width = 640; }
 //  if (height > 480) { height = 480; }

  if (overflow == '' || !/^(scroll|resize|both)$/.test(overflow))
  {
    overflow = 'both';
  }

  var win = window.open(url, '',
      'width=' + width + ',height=' + height
      + ',scrollbars=' + (/^(scroll|both)$/.test(overflow) ? 'yes' : 'no')
      + ',resizable=' + (/^(resize|both)$/.test(overflow) ? 'yes' : 'no')
      + ',status=yes,toolbar=no,menubar=no,location=no'
  );

  return win;
}


// Begin popup window function.
function popUps() {
	var pSmall = getElementsByAttribute("rel","popup-small");
	var pMedium = getElementsByAttribute("rel","popup-medium");
	var pLarge = getElementsByAttribute("rel","popup-large");


	
	for (var i=0; i<pSmall.length; i++) {
		popupSmall = pSmall[i];
		popupSmall.onclick = function() {
			var popup = makePopup(this.href, 325, 260, 'resize');
			return popup.closed;
		}  
	}	
	for (var i=0; i<pMedium.length; i++) {
		popupMedium = pMedium[i];
		popupMedium.onclick = function() {
			var popup = makePopup(this.href, 430, 650, 'scroll');
			return popup.closed;
		}  
	}
	for (var i=0; i<pLarge.length; i++) {
		popupLarge = pLarge[i];
		popupLarge.onclick = function() {
			var popup = makePopup(this.href, 600, 400, 'scroll');
			return popup.closed;
		}  
	}

}

addLoadListener(popUps);