	$(document).ready(function(){	
	//run function on each "a" element in "#navigation"
	//pass the event to the function...
	services();
	locationHash()
	$("#navigation a").click(function(event) {
			//prevent the default click event
			analytics(event);
			if(event.preventDefault){
				event.preventDefault();
			}
			else {
				alert("Your browser is out-dated");
			}
			//get the parent (the <li> in this case), to use later
			var parent;
			parent = $(this).parent();
						
			//run this function, passing the event on...
			getUrl(event, parent);
			navchange($(parent));
		});
    });
//END DOCUMENT READY
function analytics(event) {
	url = event.target;
	currentpage = window.location;
	_gaq.push(['_trackEvent', 'navigation', currentpage, url]);	
};
function locationHash(){
	currentHash = location.hash;
	//console.log("current Hash: " + currentHash);
	if(currentHash !== '') {
		//console.log("current hash was not blank: " + currentHash);
		//currentLocation = window.location.href.substr(0, window.location.href.indexOf('#'))
		//currentLocation = location.hostname;
		currentHash = currentHash.toString().replace("\#", "\/");
		currentHash = (currentHash + ".html");
		//console.log("new var currentHash: " + currentHash);
		//newLocation = currentLocation + currentHash;
		newLocation = currentHash;
		//console.log("new location to attempt to load: " + newLocation);
		url = newLocation;
		loader(url);
	}
	else if (currentHash == ''){
		//console.info("current hash was blank");
	}
}

//Function to add alt text on all images with "image" class
function alttext(){	
	//get images in the #content
	$(".image img").each(function() {
        image = $(this);
		//image.wrap('<div class="image">');
		altText = image.attr("alt");
		image.after('<span class="alttext"><p>' + altText + '</p></span>');
		/*disabling click */ // image.click(openbox);
    });
}

function services() {
		
	if (document.getElementById("jumplist")){
	
	$("#jumplist a").click(function(event){
		event.preventDefault();
		thetarget = $(this);
		$('.highlight').removeClass('highlight');
		scrollhere(thetarget);
	});
	
	}
}

function scrollhere(){
	iD = thetarget.attr('href');
	position = $(iD).offset();
	position = position.top
	$("html, body").animate({
		scrollTop: position - 10
	}, 400, function(){
		$(iD).addClass('highlight');
		});
}

function getUrl(event, parent) {
		//takes the event, sets the target of the event to "url"
		url = event.target;
		//console.log("event.target ('url'): " + url);
		hash = url.hash;
		//console.log("url hash: " + hash);
		location.hash = hash;
		//run each of these functions, taking the URL variable with them
		loader(url);
		//navchange(parent);
	}
	
function loader(url){
		//console.log("in loader function");
		//add "#ajax" to the url string, so that it can be used in the Ajax function on the next line
		url = url + " #ajax";
		//console.log("url to load is: " + url);
		//load the url of the link that was clicked on, and run the animation function
		$("#content").load(url, animation);
	}
function animation(){
		services();
		//get the height of the ajax element on the newly loaded page
		var height = $("#ajax").height();
		//hide the new loaded page the instant its loaded
		$("#ajax").hide();
		//an animation that grows the content box to the height of the hidden ajax element, then fades the new page in
		$("#content").animate({
			height: height
		}, 400, function(){
					$("#ajax").fadeIn(400);	
				});
		alttext();
		
	}
function navchange(parent){
	//first remove previous set "selected" class
	$("#navigation li").removeClass("selected");
	
	//then add "selected" class to the link that was clicked on
	parent.addClass("selected");
}
