/**
* Fullscreenr - lightweight full screen background jquery plugin
* By Jan Schneiders
* Version 1.0
* www.nanotux.com
**/

(function($){	

	$.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 options2 = $.extend({}, defaults, options); 
		$(document).ready(function() { $(options2.bgID).fullscreenrResizer(options2);	});
		$(window).bind("resize", function() { $(options2.bgID).fullscreenrResizer(options2); });		
		return this; 		
	};	
	$.fn.fullscreenrResizer = function(options) {
		var ratio = options.height / options.width;	
		var browserwidth = $(window).width();
		var browserheight = $(window).height();
		if ((browserheight/browserwidth) > ratio){
		    $(this).height(browserheight);
		    $(this).width(browserheight / ratio);
		} else {
		    $(this).width(browserwidth);
		    $(this).height(browserwidth * ratio);
		}
		$(this).css('left', (browserwidth - $(this).width())/2);
		
		if(options.top !== undefined) {
			 $(this).css('top', options.top);
		} else {
				$(this).css('top', (browserheight - $(this).height())/2);	
		}
		//$(this).css('top', (browserheight - $(this).height())/2);
		return this; 		
	};
})(jQuery);

$(function() {   
	$.fn.fullscreenr({  width: 1200, height: 1000, bgID: '#background-img', top : 0 });	
});
