(function($) {
  $.fn.fullBg = function(){
    var wrapperdiv = $(this);
    var bgImg = $(this).children("img").first();		
 
    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'
        //});		
      //}
      if( winwidth > ( winheight * 1.6 ) ){
        newwidth = winwidth; //"100%";
        newheight = "auto";
      } else {
        newwidth = winheight * 1.6;
        newheight = winheight;
      }
      wrapperdiv.css({
        width: "100%",
        height: "100%"
      })
      bgImg.css({
        width: newwidth,
        height: newheight
      })
    } 
    resizeImg();
    $(window).resize(function() {
      resizeImg();
    }); 
  };
})(jQuery)

