(function ($) {
    $.fn.fullBg = function () {
        var bgImg = $(this);
        bgImg.addClass('fullBg');

        function resizeImg() {
            var imgwidth = bgImg.width(); // 897
            var imgheight = bgImg.height(); // 601
            var winwidth = $(window).width(); // 1920
            var winheight = $(window).height(); // 601
            var widthratio = winwidth / imgwidth; // 2.1404
            var heightratio = winheight / imgheight; // 1
            var widthdiff = heightratio * imgwidth; //897
            var heightdiff = widthratio * imgheight; //1279.959
           /* if (heightdiff > winheight) {  // 1279.959 > 601
                bgImg.css({
                    width: winwidth + 'px', // sets to 1920
                    height: heightdiff + 'px' // 1279.959
                });
            } else {
                bgImg.css({
                    width: widthdiff + 'px', // 897
                    height: winheight + 'px' // 601
                });
            } */

            if(heightdiff < winheight){
				var newwidth=heightratio * imgwidth;
				var newheight=heightratio * imgheight;
            }
            else
            {
				var newwidth= widthratio * imgwidth;
				var newheight=widthratio * imgheight;
            }

            bgImg.css({
            	width: newwidth + 'px',
            	height: newheight + 'px'
            });
        }

        resizeImg();
        $(window).resize(function () {
            resizeImg();
        });
    };
})(jQuery)
