(function($) {

  $.fn.fullBg = function(){
    var bgImg = $(this);

    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) {
	  
		//console.log('Height > Width', parseInt( (winheight - imgheight) / 2 ));
        bgImg.css({
          width: winwidth+'px',
          height: heightdiff+'px',
		  top: parseInt( (winheight - imgheight) / 2 )
        });
      } else {
	  //console.log('Width > Height', parseInt( (winheight - imgheight) / 2 ));	
        bgImg.css({
          width: widthdiff+'px',
          height: winheight+'px',
		  top: 0
        });		
      }
    } 
    resizeImg();
    $(window).resize(function() {
      resizeImg();
    }); 
  };
})($j);

$j(function(){
	$j('.full_bg').show().fullBg();
})

