var strTarget;
/*

START jQUERY

*/
$(document).ready(function(){
	/*
	
	PAGING NAVIGATION FOR IMAGES
	
	*/
	
	// set width of header container, we'll need this to find it's left position since it sits in the middle of X axis of browser
	$("#header").css("width","912px");

	// prepare pages container for scrolling page divs (collections of images)
	prepPages();

	// Scroll Nav
	$(".gallery a").click(function(){
		// grab the target page
		strTarget = $(this).attr("href");
		setTimeout("centerGallery()", 5);
		return false;
	});
	
	var theURL = location.href;
	if (theURL.indexOf("#") >= 0) {
		strTarget = "#" + theURL.split("#",2)[1];
		centerGallery();
	}
	
	/*
	
	FANCY BOX MODAL
	
	*/
	$(".page a").fancybox();
	
	$(".page .iframe").fancybox({
		"frameWidth": 740,
		"frameHeight": 500,
		"callbackOnClose": clearIFrame
	});
});

function centerGallery() {
	// calculate top and left offset
	var offsetTop = (document.getElementById("header").offsetHeight)*-1;
	var offsetLeft = getPageOffset();
	// set animation duration and scroll to taget page
	var animDuration = 900;
	$.scrollTo($(strTarget), animDuration, {offset: {top:offsetTop, left:offsetLeft}});
	
	// maintain nav state
	$("#nav-local a").removeClass("on");
	$("#" + strTarget.replace("#", "nav-")).addClass("on");
}

function clearIFrame() {
	$("#fancy_content").empty();
}

/*

HELPERS: BEGIN PAGING NAVIGATION FOR IMAGES

*/

// Call prepPages on window resize
window.onresize=function(){
	prepPages();
}

// prepPages: adds left and right padding to pages container so scrolling pages line up with left edge of header
function prepPages() {
	$("#pages").css("padding-left",((getPageOffset())*-1) + "px");
	$("#pages").css("padding-right",((getPageOffset())*-1) + "px");
}

// the offset we return is based on the width of the header, which we set at the top of this file
function getPageOffset(){
	return ((document.body.offsetWidth - 912)/2)*-1;
}
