
addLoadEvent(upstart);

function upstart(){
	window.fileLinks?fileLinks():null;
	window.preloadImages?preloadImages():null;
	window.eolasIsATroll?eolasIsATroll():null;
	window.makeMailLinks()?makeMailLinks():null;
	}
	

function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}
	
/* add target="_blank" to pdf links in an unobtrusive way */
var extensions = new Array('pdf','doc','odt','xls','pps','ppt','ods','odp');
function fileLinks() {
    var fileLink;
    if (document.getElementsByTagName('a')) {
        for (var i = 0; (fileLink = document.getElementsByTagName('a')[i]); i++) {
        	for(var j=0;j<extensions.length;j++)
        		{
        		var regexString = new RegExp("(."+extensions[j]+")$");
        		if(regexString.test(fileLink))
        			{
        			fileLink.setAttribute('target', '_blank');
        			addClass(fileLink,extensions[j]);
        			}
				}
        }
    }
}

/* eolasIsATroll(), gets rid of the 'click here to activate this control */
function eolasIsATroll()
	{
	/* doesn't work in Opera yet, for some reason
	 *  */
	if(document.body.outerHTML!=undefined)
		{
		var affectedTags = new Array('object','embed','applet');
			for (var i = 0; i < affectedTags.length; i++) {
				var objects = document.getElementsByTagName(affectedTags[i]);
				for (var j = 0; j < objects.length; j++ ) {
					if(objects[j].id!='slideshow') // slideshowpro has issues with this hack
						{
						var tmp = objects[j].outerHTML;
						objects[j].outerHTML = tmp;
					}
				}
			}
		}
	}
function makeMailLinks()
	{
	if (!document.getElementsByTagName && !document.createElement && !document.createTextNode)
		return;
	var spans = document.getElementsByTagName("span");
	for(var i=0;i<spans.length;i++)
		{
		if (spans[i].className=="email")
			{
			var theNode = spans[i];
			var theAddress = theNode.firstChild.nodeValue;
			theAddress = theAddress.replace(/ \(at\) /, "@");
			theAddressNode = document.createElement('A');
			theAddressNode.setAttribute("href", "mailto:" + theAddress);
			theAddressNode.appendChild(document.createTextNode(theAddress));
			theNode.parentNode.replaceChild(theAddressNode, theNode);
			i--; /*because we implicitly removed a <span> from the spans array by making it an <a>; Otherwise it'll skip the next span*/
			}
		}
	}
function addClass(element, value) {
	if (!element.className) {
		element.className = value;
	} else {
		var newClassName = element.className;
		newClassName += " ";
		newClassName += value;
		element.className = newClassName;
	}
}


