(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();
        });
    };

    
})(jQuery)


/*
jQuery(function ($) {
    $("#background").load(function () {        
        $("#background").fullBg();
        $("#background").show();
    });
});
*/

// when the DOM is ready
jQuery(function () {
  jQuery("#background")
    // once the image has loaded, execute this code
    .load(function () {
            // fade our image in to create a nice effect      
      jQuery(this).fullBg();
      jQuery(this).show();
    })
    // *finally*, set the src attribute of the new image to our image
    .attr('src', 'http://www.cavendersranch.com/wp-content/themes/TESIGNER/images/background.jpg');
});

