$(document).ready(function(){
	createSwitchers();
	insertPhoto();
	zebraStripe();
});

function createSwitchers(){
	// loop over any unordered lists with a class of 'switch'
	$("ul.switch").each(function(){
		var theSwitchId = this.getAttribute("id");
		// loop over any list items without a class of 'exclude'
		$("li", this).not(".exclude").each(function(i){
			// mark the first anchor as current and hide any elements not associated with it
			var theElementId = $("a", this).get(0).getAttribute("href").replace(/^.*\#/, "\#");
			if (i==0){$(this).addClass("current");}
			else {$(theElementId).hide();}
			// add an onclick function to the appropriate anchors
			$("a", this).click(function(){
				// stop execution if the clicked anchor is already the current anchor
				if (this.parentNode.className.match(/current/)){return false;}
				// mark the current anchor as un-current and hide the associated element
				$("li.current", document.getElementById(theSwitchId)).each(function(){
					var theElementId = $("a", this).get(0).getAttribute("href").replace(/^.*\#/, "\#");
					$(theElementId).hide();
					$(this).removeClass("current");
				});
				// mark the clicked anchor as current and fade in the associated element
				$(this.parentNode).addClass("current");
				$(theElementId).fadeIn("slow");
				return false;
			});
		});
	});
}

function insertPhoto(){
	var theSpans = 2;
	// code fork to get the browser window width
	if ((window.innerWidth && window.innerWidth >= 904) || (document.body.clientWidth && document.body.clientWidth >= 904)){
		theSpans++;
	}
	// create and nest the appropriate number of spans
	var thePhoto = document.createElement("span");
	for (var i=0; i<theSpans--; i++){
		var theTempPhoto = document.createElement("span");
		theTempPhoto.appendChild(thePhoto);
		thePhoto = theTempPhoto;
	}
	// set the element's id and append it to the header
	thePhoto.setAttribute("id", "photo");
	$("#header").append(thePhoto);
}

function zebraStripe(){
	$("table.striped tr:nth-child(even)").addClass("even");
}