/**
 * jQuery.fullBg
 * Version 1.0
 * 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 = bgImg.width();
      var imgheight = bgImg.height();
 
      var winwidth = $(window).width();
      var winheight = $(window).height();
 
      var widthratio = winwidth / imgwidth;
      var heightratio = winheight / imgheight;
      var heightwidth = winheight / winwidth;
      var minheight = 400;
      var minheight2 = 150;
      var widthdiff = heightratio * imgwidth * widthratio;
      var heightdiff = widthratio * imgheight * heightratio;
      
      var bull = winheight + (imgheight -  (winheight / heightratio));
      var shite = winwidth + (imgwidth - (winwidth / widthratio));
      var shark = winheight - (imgheight +  (winheight / heightratio));
 
     
     if ((heightdiff > winheight) && (widthdiff > winwidth) ) {
       
        bgImg.css({
          width: shite+'px',
          height: bull+'px'
        });
       } 
        
        if ((heightdiff > winheight) && (widthdiff <= winwidth)){
      
         bgImg.css ({
	          width: winwidth+'px',
	          height: bull+'px'
        });
       } 
      
       if ((heightdiff <= winheight) && (widthdiff <= winwidth)){
       
         bgImg.css({
                  width: winwidth+'px',
	          height: winheight+'px'
        });
         
      }
      
        if ((heightdiff <= winheight) && (widthdiff > winwidth)){
                     
                      bgImg.css({
                         width: shite+'px',
             	          height: winheight+'px'
               });
             
       }
       
        if ((winheight <= 400) && (heightwidth < .6)){
                    
                      bgImg.css({
                         width: shite+'px',
             	          height: minheight+'px',
             	          bottom: minheight+'px'
               });
               
               }
               
                if (winheight > 400) {
                    $("#signpost").css('margin-top',winheight-333-(.1 * (winheight-400))+'px').addClass("signpost");
	            $("#signpost").css('position','absolute'); 
	             $("#signpost").css('display','block'); 
	            }
       
      }
      
    resizeImg();
    $(window).resize(function() {
      resizeImg();
    }); 
  };
})(jQuery)
