(function($) {
	$.fn.fullBg = function(){
		var bgImg = $(this);
		
		bgImg.addClass('fullBg');
		
		function resizeImg() {
			var imgwidth = bgImg.width();
			var imgheight = bgImg.height();
			
			var winwidth = $(window).width();
			var winheight = $(window).height();
			
			var widthratio = winwidth / imgwidth;
			var heightratio = winheight / imgheight;
			
			var widthdiff = heightratio * imgwidth;
			var heightdiff = widthratio * imgheight;
		
			if(heightdiff>winheight) {
				bgImg.css({
					width: winwidth+'px',
					height: heightdiff+'px'
				});
			} else {
				bgImg.css({
					width: widthdiff+'px',
					height: winheight+'px'
				});		
			}
		} 
		resizeImg();
		$(window).resize(function() {
			resizeImg();
		}); 
	};
	
	$.fn.gridBg = function(){
		var bgImg = $(this);
				
		function resizeImg() {
			
			var winheight = $(window).height();
		
			var imgheight = $("img.bg").height();
		
		
			if(winheight < imgheight){
				winheight = imgheight;
			}
		
		
			bgImg.css({
				height: winheight+'px'
			});
/*			
			$("#myBackground").css({
				height: $(window).height()+'px'
			});
*/			
		} 
		resizeImg();
		$(window).resize(function() {
			resizeImg();
		});
		
		$(window).scroll(function () { 
			resizeImg();
		});
	};
	
	
	
})(jQuery)


jQuery(function($) {
	$("#grid").gridBg();
});
