document.getElementsByTagName('html')[0].className += 'js-active';
(function($){	  

jQuery(function(){
	templateInit();
});

function templateInit(){
	$('#header, #footer', 'posterwall-grid' ,'posterwall-grid2').css({ position: 'fixed' });
	bindWindowResize();
	bindWindowScroll();
	posterwallInit();
}

function bindWindowResize(){
	// Window resize used to contact info position. When the window gets too
	// small, to prevent an overlap their position is adjusted.
	var footer = $('#footer');
	$(window).bind('resize', function(e){
		var winHeight = $(this).height();
		if( winHeight < 655 ){
			footer.css({ top: 600, bottom: 'auto' });
		} else {
			footer.css({ top: 'auto', bottom: 20 });
		}
		$(window).trigger('scroll');
	});
	// Trigger resize at load, in case the default window size it too small
	$(window).trigger('resize');
}

function bindWindowScroll(){
	var hd = $('#header');
    var ft = $('#footer');
	var ps = $('#posterwall-grid');
	var ps2 = $('#posterwall-grid2');
	$(window).bind('scroll', function(e){
		var winLeft = $(this).scrollLeft();
		hd.css({ left: (winLeft * -1) + 0 });
		ft.css({ left: (winLeft * -1) + 0 });
		ps.css({ left: (winLeft * -1) + 0 });
		ps2.css({ left: (winLeft * -1) + 0 });
	});
}

function posterwallInit(){
	$('#posterwall').posterwall({
		vertical_center: 0,
		ratio: [1200, 900],
		min_size: [1200, 900]
	});
}

function preloadImages(images){
	$.each(images, function(i, image){
		var img = $('<img>').attr('src', image);		
	});
}

})(jQuery);
