// ==================================================================================================== ]]


// ==================================================================================================== ]]
// hide address bar in mobile browsers
(function( win ){
	var doc = win.document;

	// If there's a hash, or addEventListener is undefined, stop here
	if( !location.hash && win.addEventListener ){

		//scroll to 1
		window.scrollTo( 0, 1 );
		var scrollTop = 1,
			getScrollTop = function(){
				return win.pageYOffset || doc.compatMode === "CSS1Compat" && doc.documentElement.scrollTop || doc.body.scrollTop || 0;
			},

			//reset to 0 on bodyready, if needed
			bodycheck = setInterval(function(){
				if( doc.body ){
					clearInterval( bodycheck );
					scrollTop = getScrollTop();
					win.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
				}	
			}, 15 );

		win.addEventListener( "load", function(){
			setTimeout(function(){
				//at load, if user hasn't scrolled more than 20 or so...
				if( getScrollTop() < 20 ){
					//reset to hide addr bar at onload
					win.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
				}
			}, 0);
		} );
	}
})( this );


// ==================================================================================================== ]]
// determine size of viewport, then set content area height in order to position footer accordingly

	$(document).ready(function(){
		function printViewportDimensions() {
			var viewportwidth = $(window).width();
			var viewportheight = window.innerHeight ? window.innerHeight : $(window).height();  
			var footerheight = $('.footer').outerHeight(true);
		

	$('#page').css('min-height', ( viewportheight - footerheight ) + 'px');

	var itemWidth = 280;
	var columns = Math.floor($('.galleries .the-grid').width()/itemWidth);	
	$('#gallery-index').css('max-width', itemWidth * columns + 'px');






		}
		printViewportDimensions();
		$(function() {
			printViewportDimensions();
			$(window).resize(function() {
				printViewportDimensions();
			});
		});
	});


// ==================================================================================================== ]]
// scroll to top

	$(function() {
		$('#back-to-top').click(function () {
			$('body,html').animate({
				scrollTop: 0
			}, 500);
			return false;
		});
    });


// ==================================================================================================== ]]
