/**
* 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', fullview: 1, top: 0, left: 0, bottom: 0 };
		var options = $.extend({}, defaults, options); 
		$(document).ready(function() { $(options.bgID).fullscreenrResizer(options);	});
		$(window).bind("resize", function() { $(options.bgID).fullscreenrResizer(options); });		
		return this; 		
	};	
	$.fn.fullscreenrResizer = function(options) {
		// Set bg size
		var ratio = options.height / options.width;
		var iwidth = false;
		// Get browser window size
		var browserwidth = $(window).width();
		var browserheight = $(window).height() - options.top - options.bottom;
		// Scale the image  Full View mode
	        if (options.fullview > 0) {
		  if ((browserheight/browserwidth) > ratio){
		    $(this).width(browserwidth);
		    $(this).height(browserwidth * ratio);
		  } else {
		    $(this).height(browserheight);
		    $(this).width(browserheight / ratio);
		  }
		} else {
//		if (zoom) {
		  if ((browserheight/browserwidth) > ratio){
		    $(this).height(browserheight);
		    $(this).width(browserheight / ratio);
		  } else {
		    iwidth = true;
		    $(this).width(browserwidth);
		    $(this).height(browserwidth * ratio);
		  }
		//		}
		}

		// Center the image
		$(this).css('left', (browserwidth - $(this).width())/2);
		if (iwidth) {
		  $(this).css('top', options.top);
		} else {
		  $(this).css('top', (browserheight/2 - $(this).height()/2) + options.top);
		}
		return this; 		
	};
})(jQuery);

