/**
 * jQuery.fullBg
 * Copyright (c) 2010 c.bavota - http://bavotasan.com
 * Dual licensed under MIT and GPL.
 * Date: 02/23/2010
**/

(function($) {
  $.fn.fullBg = function(){
    var bgImg = $(this);		
 
    function resizeImg() {
      var imgwidth = 1024;
      var imgheight = 576;
 
      var winwidth = $(window).width();
      var winheight = $(window).height();
 
      var widthratio = winwidth / imgwidth;
      var heightratio = winheight / imgheight;
 
      var widthdiff = heightratio * imgwidth;
      var heightdiff = widthratio * imgheight;
	  
	  var negativeHMargin = (heightdiff - winheight) / -2;
	  var negativeWMargin = (widthdiff - winwidth) / -2;
 
      if(heightdiff>winheight) {
        bgImg.css({
          width: winwidth+'px',
          height: heightdiff+'px',
		  margin: negativeHMargin + 'px 0 0 0'
        });
      } else {
        bgImg.css({
          width: widthdiff+'px',
          height: winheight+'px',
		  margin: '0 0 0 ' + negativeWMargin + 'px'
        });		
      }
	  
    } 
    resizeImg();
    $(window).resize(function() {
      resizeImg();
    }); 
  };
})(jQuery)
