/****************************************************************************************/
/**The original source was taken from - Supersized - Fullscreen Slideshow jQuery Plugin**/
/**By Sam Dunn (http://www.buildinternet.com/project/supersized/)************************/
/**Thanks to Aen for centering.**********************************************************/
/**This is a modified and simplified version of the original pligin.*************/
/****************************************************************************************/
(function($){
	//Resize image on ready or resize
	$.fn.bg = function() {
		$.inAnimation = false;
		var options = $.extend($.fn.bg.options);
		$(document).ready(function() {
			$('#bg').resize(); 
		});
		$(window).bind("resize", function(){
    		$('#bg').resize(); 
		});
	};
	//Adjust image size
	$.fn.resize = function() {
		var options = $.extend($.fn.bg.options);
	  	return this.each(function() {
			//Define image ratio
			var ratio = options.startheight/options.startwidth;
			//Gather browser and current image size
			var imagewidth = $(this).width();
			var imageheight = $(this).height();
			var browserwidth = $(window).width();
			var browserheight = $(window).height();
			var offset;
			//Resize image to proper ratio
			if ((browserheight/browserwidth) > ratio){
			    $(this).height(browserheight);
			    $(this).width(browserheight / ratio);
			    $(this).children().height(browserheight);
			    $(this).children().width(browserheight / ratio);
			} else {
			    $(this).width(browserwidth);
			    $(this).height(browserwidth * ratio);
			    $(this).children().width(browserwidth);
			    $(this).children().height(browserwidth * ratio);
			}
			if (options.center == 1){
				//$(this).children().css('left', (browserwidth - $(this).width())/2);
				$(this).children().css('top', (browserheight - $(this).height())/2);
			}
			return false;
		});
	};
})(jQuery);