 $(document).ready(function() {
	//aOffset = $("#approach").offset();
	//$(".selectionArrow").offset({ top: aOffset.top, left: aOffset.left });
	
	cURL = window.location.href;
	anchorPos = cURL.indexOf('?', 0);
	
	//if we have an anchor,
	//scroll to it
	if (anchorPos > 0) {
		anchorBool = true;
		anchorStr = cURL.substring(anchorPos+1);	
		anchorStrFirst = anchorStr.substring(0, 1);
		anchorStrUpper = anchorStrFirst.toUpperCase() + anchorStr.substring(1);
		
		subNavElement = document.getElementById('sn' + anchorStrUpper);
		if (subNavElement != null) {
			scrollPage(subNavElement, anchorStr);
		}
		else {
			anchorBool = false;
		}
	}
	else {
		anchorBool = false;
	}
	
	//format parts of the social section
	$("#blog ul li:last").addClass("last");
	$("#twitter ul li:last").addClass("last");
	
	//set the selected section of the main nav
	cPath = window.location.pathname;		
	if (cPath.indexOf("about") > -1) {
		$("#nAbout").addClass("selected");
		if (!anchorBool) {
			scrollPage($("#snApproach"), null);
		}
	}
	else if (cPath.indexOf("services") > -1) {
		$("#nServices").addClass("selected");
	}
	else if (cPath.indexOf("whatsNew") > -1) {
		$("#nWhatsNew").addClass("selected");
		if (!anchorBool) {
			scrollPage($("#snNewSpace"), null);
		}			
	}	
	else if (cPath.indexOf("mediamosaic") > -1) {			
		$("#nBlog").addClass("selected");
	}		
	else if (cPath.indexOf("contact") > -1) {
		$("#nContact").addClass("selected");
		if (!anchorBool) {
			scrollPage($("#snLeadership"), null);
		}					
	}
	else {
		$("#nHome").addClass("selected");
	}
 });

function scrollPage(sNav, to) {
	if (to != null) {
		toOff = $("#" + to).offset();
		if (toOff !=null) {
			//scroll the page 
			//offset the height of the fixed navigation
			$.scrollTo(toOff.top - (parseInt($("#page").css("paddingTop"))), "slow", {easing: 'easeOutCirc'});
		}
	}
	
	//move the selection arrow
	snOff = $(sNav).offset();
	snWidth = parseInt($(sNav).css("width"));
	saWidth = parseInt($(".selectionArrow").css("width"));	
	amtLeft =  snOff.left + (snWidth/2) + (saWidth/2);
	
	$(".selectionArrow").offset({ left: amtLeft });
}

function showOverlay(who) {
	$(".overlay").show();
	$("#" + who).fadeIn();
	
	$(".overlay").click(function hideOverlay() {
		$(".overlay").fadeOut("fast");
		$("#" + who).fadeOut("fast");
	});
}

function hideSlideshow() {
	$('.overlay').hide();	
	$('#imageGallery').hide();
}
