// Add event handler to body when window loads
function addLoadEvent(func) {
	var oldonload = window.onload;
	
	if (typeof window.onload != "function") {
		window.onload = func;
	} else {
		window.onload = function () {
			oldonload();
			func();
		}
	}
}

addLoadEvent(function () {
	// Code to run on page load
	GoogleLinkTracker.init();
});


/*-----------------------------------------------------------------------------------------+
 | GoogleLinkTracker - Add click tracking for Google Analytics to files and outgoing links |
 +-----------------------------------------------------------------------------------------*/
var GoogleLinkTracker = {
	init : function() {
		var links = document.getElementsByTagName("a");
		
		for (var i = 0; i < links.length; i++) {
			var theLink = links[i];
			var theURL = theLink.href.toLowerCase();
			
			if (typeof(pageTracker) != "undefined")
			{
				if (/\.(bmp|doc|docx|gif|jpg|pdf|png|xls|xlsx|ppt|pptx|zip)/.test(theURL)) {
					var func = function () { if (pageTracker) pageTracker._trackPageview("/files/" + this.href); };
					
					if (typeof(jQuery) != "undefined")
						jQuery(theLink).click(func);
					else
						theLink.onclick = func;
				}
					
				if (theURL.indexOf("eljohnson.com") == -1) {
					var func = function () { if (pageTracker) pageTracker._trackPageview("/outbound/" + this.href); };
					
					if (typeof(jQuery) != "undefined")
						jQuery(theLink).click(func);
					else
						theLink.onlick = func;
				}
			}
		}
	}
};


/*--------------------------------------------------+
 | Tog - Toggle visibility of two opposing elements |
 +--------------------------------------------------*/
var Tog = {
	swap : function (a, b) {
		a = document.getElementById(a);
		b = document.getElementById(b);
		
		if (!a || !b) return false;
		
		if (a.className.indexOf("closed") != -1) {
			oldClass = a.className;
			newClass = oldClass.replace(/closed/g, "");
			a.className = newClass;
			
			b.className += " closed";
		} else {
			oldClass = b.className;
			newClass = oldClass.replace(/closed/g, "");
			b.className = newClass;
			
			a.className += " closed";
		}
	},
	toggle : function (a) {
		a = document.getElementById(a);
		
		if (!a) return false;
		
		if (a.className.indexOf("closed") != -1) {
			oldClass = a.className;
			newClass = oldClass.replace(/closed/g, "");
			a.className = newClass;
		} else {
			a.className += " closed";
		}
	},
	togglePropertyValue : function (a, prop, value1, value2) {
		a = document.getElementById(a);
		
		if (!a) return false;
		
		if (a[prop].indexOf(value1) != -1) {
			a[prop] = value2;
		} else {
			a[prop] = value1;
		}
	},
	setPropertyValue : function (a, prop, value) {
		var a = document.getElementById(a);
		
		if (!a) return false;
		
		a[prop] = value;		
	},
	setStylePropertyValue : function (a, prop, value) {
		var a = document.getElementById(a);
		
		if (!a) return false;
		
		a.style[prop] = value;		
	}
};