/**
* Call to prepare external links
* Place here so you don't forget to add it!
*/
addLoadEvent(breakOut);
addLoadEvent(prepareExternalLinks);
addLoadEvent(prepareDailyLinks);

/**
* addLoadEvent
* @author Simon Willison - http://simon.incutio.com/
*
* Accepts a function name and stacks the "window.onload" even
*/
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

/**
* prepareDailyLinks
* @author Peter McWilliams - http://www.augustash.com/
*
* Checks the document for all link nodes with a class name "external"
* and opens them in a new window
*/
function prepareDailyLinks() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	var links = document.getElementsByTagName('a');
	for (var i=0; i<links.length; i++) {
		if (links[i].className == "dailyPopup") {
		//if (links[i].getAttribute("class") == "external") {
			links[i].onclick = function() {
				popUp(this.getAttribute("href"), "dailyPopup", "width=410,height=350,toolbar=no,scrollbars=no,resizeable=no,menubar=no,status=no");
				return false;
			}
		}
	}
}

/**
* prepareExternalLinks
* @author Peter McWilliams - http://www.augustash.com/
*
* Checks the document for all link nodes with a class name "external"
* and opens them in a new window
*/
function prepareExternalLinks() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	var links = document.getElementsByTagName('a');
	for (var i=0; i<links.length; i++) {
		if (links[i].className == "external") {
		//if (links[i].getAttribute("class") == "external") {
			links[i].onclick = function() {
				popUp(this.getAttribute("href"), "external", "");
				return false;
			}
		}
	}
}

/**
* popUp
*
* The same old popup function that is always used!
*/
function popUp(url, name, features) {
	window.open(url, name, features);
	return false;
}

function breakOut() {
	if (top.frames.length!=0) {
		if (window.location.href.replace)
			top.location.replace(self.location.href);
		else
			top.location.href=self.document.href;
	}
}