// JavaScript Document

(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 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 ratio = 2.76; // 1.8	original
		// Get browser window size
		var browserwidth = $(window).width();
		var browserheight = $(window).height();
		// Scale the image
		
		var newWidth = browserwidth ; //* 0.8 original
		var newHeight = newWidth / ratio;
		
		$(this).height(newHeight);
		$(this).width(newWidth);
		/*
		if ((browserheight/browserwidth) > ratio){
		    $(this).height(browserheight*0.7);
		    $(this).width(browserheight*0.7 / ratio);
		} else {
		    $(this).width(browserwidth*0.7);
		    $(this).height(browserwidth*0.7 * ratio);
		}*/
		// Center the image
		//$(this).css('left', (browserwidth - $(this).width())/2);
		//$(this).css('top', (browserheight - $(this).height())/2);
		return this; 		
	};
})(jQuery);
