/**
* Fullscreenr - lightweight full screen background jquery plugin
* By Jan Schneiders
* Version 1.0
* www.nanotux.com
**/
(function(jQuery){	
	jQuery.fn.fullscreenr = function(options) {
		if(options.height === undefined) alert('Please supply the background image height, default values will now be used. These may be very inaccurate.');
		if(options.width === undefined) alert('Please supply the background image width, default values will now be used. These may be very inaccurate.');
		if(options.bgID === undefined) alert('Please supply the background image ID, default #bg will now be used.');
		var defaults = { width: 1600,  height: 900, bgID: 'bg' };
		var options = jQuery.extend({}, defaults, options); 
		jQuery(document).ready(function() { jQuery(options.bgID).fullscreenrResizer(options);	});
		jQuery(window).bind("resize", function() { jQuery(options.bgID).fullscreenrResizer(options); });		
		return this; 		
	};	
	jQuery.fn.fullscreenrResizer = function(options) {
		// Set bg size
		var ratio = options.height / options.width;	
		// Get browser window size
		var browserwidth = jQuery(window).width();
		var browserheight = jQuery(window).height();
		// Scale the image
		if ((browserheight/browserwidth) > ratio){
		    jQuery(this).height(browserheight);
		    jQuery(this).width(browserheight / ratio);
		} else {
		    jQuery(this).width(browserwidth);
		    jQuery(this).height(browserwidth * ratio);
		}
		// Center the image
		jQuery(this).css('left', (browserwidth - jQuery(this).width())/2);
		jQuery(this).css('top', (browserheight - jQuery(this).height())/2);
		return this; 		
	};
})(jQuery);