var flexiBackground = function(){
	
	/**
		CONFIGURATION:
		Declare and define variables
		Define the size of our background image
	*/
	var bgImageSize = {
		width : 1440,
		height : 900
	};

	var imgAR;
		
	/**
		Are we dealing with ie6?
	*/
	var ie6 = ($.browser.msie && parseInt($.browser.version, 10) <= 6);
	
	/**
		Set up the action that happens on resize
	*/
	var resizeAction = function() {
		var win = {
			height : $(window).height(),
			width : $(window).width()
		};

		// The current aspect ratio of the window
		var winAR = win.width / win.height;

		// Determine if we need to show the image and whether it needs to stretch tall or wide
		if (winAR < imgAR) {
/*
			CENTER IMAGE HOR.
			var newMargin = bgImageSize.width-win.width;
			document.title = "org: " + newMargin;
			newMargin = newMargin/2;
			newMargin = newMargin*-1;
			document.title += ", new: " + newMargin;
			document.title += ", left: " + $("#wallpaper").css("left");
			$("#wallpaper").css("left", newMargin);
*/			$("#wallpaper").width("auto");
			$("#wallpaper").height("100%");
		} else {
			$("#wallpaper").width("100%");
			$("#wallpaper").height("auto");
		}
	};
	
	return {
		
		/*
			Sets up the basic functionality
		*/
		initialize : function() {
			// Get the aspect ratio of the image
			imgAR = bgImageSize.width / bgImageSize.height;
			
			// Set up a resize listener to add/remove classes from the body 
			$(window).bind('resize', resizeAction);

			// Set it up by triggering a resize
			$(window).trigger('resize');
		}
	};
}();

$(document).ready(flexiBackground.initialize);