$(document).ready(function() {
	
	doMainNav();
	
	checkLayout();
	
	if ($("#adPeel").length > 0) {
		// instantiate pagepeel ad
		$("#adPeel").pagepeel({
			imgOpenWidth: 213, 
			imgOpenHeight: 213, 
			imgOpenDuration: 400, 
			imgCloseWidth: 156,
			imgCloseHeight: 156,
			imgCloseDuration: 400, 
			msgOpenWidth: 213, 
			msgOpenHeight: 205, 
			msgOpenDuration: 420, 
			msgCloseWidth: 156,
			msgCloseHeight: 148,
			msgCloseDuration: 390
		});
	}

	// reset page posistion on resize
	$(window).bind("resize", checkLayout);
	
});

// check layout, if viewport smaller than site min-w/min-h set appropriate css...
// this is a workaround to deal with using absolute positioning and the 
// site falling outside of the viewport with no scrollbars...
function checkLayout() {
	var cssObj;
	var wrapper = $("#wrapper");
	var divW = wrapper.width();
	var divH = wrapper.height();
	var winW = $(window).width();
	var winH = $(window).height();
	
	// calculate widths, if viewport less than
	if (winW <= divW) {
		cssObj = {
			"left": "0", 
			"margin-left": "0"
		}
		wrapper.css(cssObj);
	} 
	
	// calculate heights, if viewport less than
	if (winH <= divH) {
		cssObj = {
			"top": "0", 
			"margin-top": "0"
		}
		wrapper.css(cssObj);
	}
	
	// calculate widths/heights, if viewport more than
	if (winW > divW && winH > divH) {
		cssObj = {
			"left": "50%", 
			"top": "50%", 
			"margin-left": "-"+divW/2+"px", 
			"margin-top": "-"+divH/2+"px"
		}
		wrapper.css(cssObj);
	}
}


// transition all content into view
function bringItIn() {
	fadeItIn("#header", "normal");
	fadeItIn("#mainBG", "normal");
	fadeItIn("#fauxBG", "normal");
	fadeItIn("#content", "normal");
	fadeItIn("#galleryBar", "normal");
}


// set init content opacity to 0, setup for transition in
function hideItAll() {
	fadeItOut("#header", 0);
	fadeItOut("#mainBG", 0);
	fadeItOut("#fauxBG", 0);
	fadeItOut("#content", 0);
	fadeItOut("#galleryBar", 0);
}


function fadeItOut(el, speed) {
	if ($(el).length > 0) {
		$(el).fadeOut(speed);
	}
}


function fadeItIn(el, speed) {
	if ($(el).length > 0) {
		$(el).fadeIn(speed);
	}
}

