/**
* Fullscreenr - lightweight full screen background jquery plugin
* By Jan Schneiders
* Version 1.0
* www.nanotux.com
**/
(function($j){	
	$j.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 #bgimg will now be used.');
		var defaults = { width: 1280,  height: 1024, bgID: 'bgimg' };
		var options = $j.extend({}, defaults, options); 
		$j(document).ready(function() { $j(options.bgID).fullscreenrResizer(options);	});
		$j(window).bind("resize", function() { $j(options.bgID).fullscreenrResizer(options); });		
		return this; 		
	};	
	$j.fn.fullscreenrResizer = function(options) {
		// Set bg size
		var ratio = options.height / options.width;	
		// Get browser window size
		var browserwidth = $j(window).width();
		var browserheight = $j(window).height();
		// Scale the image
		if ((browserheight/browserwidth) > ratio){
		    $j(this).height(browserheight);
		    $j(this).width(browserheight / ratio);
		} else {
		    $j(this).width(browserwidth);
		    $j(this).height(browserwidth * ratio);
		}
		// Center the image
		$j(this).css('left', (browserwidth - $j(this).width())/2);
		$j(this).css('top', (browserheight - $j(this).height())/2);
		return this; 		
	};
})(jQuery);
