
jQuery(function() {
	
	// jQuery UI tabs
	jQuery(".tabs").tabs();
	
	// Horizontal Gallery
	jQuery(".gst-gallery-horizontal").gstGalleryHorizontal({
		startPosition: "middle"
	});
	
	// content header slideshow
	jQuery(".gst-slideshow").gstSlideshow({
		zIndexForTopSlide: 700
	});
	
	jQuery(".gst-map-and-locations").gstGoogleMapSimple();
	
	// TODO: apply position fixed to the home sections when the image is tall enough to push them off the bottom of the viewport
	jQuery("#home-wrap").each(function() {
		var offset = jQuery("#home-photo-wrap").offset();
		//alert(offset);
		
		var funcAdjustImageWrap = function() {
			var windowWidth = jQuery(window).width();
			var windowHeight = jQuery(window).height();
			//alert("window = " + windowWidth + "x" + windowHeight);
			
			var sectionsOuterHeight = jQuery("#home-sections").outerHeight(true);
			//alert("sectionsOuterHeight = " + sectionsOuterHeight);
			
			var newPhotoWrapHeight = windowHeight - offset.top - sectionsOuterHeight - 20;
			
			var $homePhotoWraps = jQuery("#home-photo-wrap");
			$homePhotoWraps.css("height", newPhotoWrapHeight + "px");
			
			$homePhotoWraps.find("img").each(function() {
				var $thisImg = jQuery(this);
				var myHeight = $thisImg.height();
				var marginTop = -(myHeight - newPhotoWrapHeight)/2;
				//alert("marginTop = " + marginTop);
				
				// Because Chrome FLIPS OUT on refresh
				marginTop = Math.min(0, marginTop);
				
				//$thisImg.css("margin-top", marginTop + "px");
			});
			
		};
		
		// Do now
		funcAdjustImageWrap();
		//setTimeout(funcAdjustImageWrap, 1);
		
		// Do on resize
		jQuery(window).resize(funcAdjustImageWrap);
	});
});

