(function($){	
    $.fn.fullscreen = function() {
        var defaults = {
            width: 1024,  
            height: 768, 
            bgID: '#bgimg'
        };
        $(document).ready(function() {
            $(defaults.bgID).fullscreenResizer(defaults);
        });
        $(window).bind("resize", function() {
            $(defaults.bgID).fullscreenResizer(defaults);
        });		
        return this; 		
    };	
    $.fn.fullscreenResizer = function(options) {
        // Set bg size
        var ratio = options.height / options.width;	
        // Get browser window size
        var browserwidth = $(window).width();
        var browserheight = $(window).height();
        // Scale the image
        if ((browserheight/browserwidth) > ratio){
            $(this).height(browserheight);
            $(this).width(browserheight / ratio);
        } else {
            $(this).width(browserwidth);
            $(this).height(browserwidth * ratio);
        }
        // Center the image
        $(this).css('left', (browserwidth - $(this).width())/2);
        $(this).css('top', (browserheight - $(this).height())/2);
        return this; 		
    };
})(jQuery);

