

	var ImageResizer = {}

	ImageResizer = function(id) {

		this.marginLeft = 0;
		this.windowHeight = 0;
		this.windowWidth = 0;
		this.newWidth = 0;
		this.newHeight = 0;
		this.originalWidth = 0;
		this.originalHeight = 0;
		this.aspectRatio = 0;
		
		this.background = $(id);
	
		$(window).resize($.proxy(function(){
			this.performResize();
		},this));
		
		this.performResize = function(){
		
			this.windowAspectRatio = $(window).width() / $(window).height();
		
			if(!this.originalWidth) {
				this.originalWidth = this.background.width();
				this.originalHeight = this.background.height();
				this.imageAspectRatio = this.originalWidth / this.originalHeight;
			}
			
			if(this.windowAspectRatio > this.imageAspectRatio){
				this.prioritiseWidth();
			} else {
				this.prioritiseHeight();
			}
			
			this.marginLeft = -(this.newWidth / 2);
			
			this.background.css({
				 'marginLeft' : this.marginLeft
				,'height' : this.newHeight
				,'width' : this.newWidth
				,'left' : this.windowWidth/2
				,'z-index': 0
				,'top': 0
				,'position': 'fixed'
			});
			
		}
		
		this.prioritiseHeight = function() {
			this.windowHeight = $(window).height();
			this.windowWidth = $(window).width();
			this.newHeight = this.windowHeight;
			this.newWidth = this.windowHeight * this.imageAspectRatio;
		}
		
		this.prioritiseWidth = function() {
			this.windowHeight = $(window).height();
			this.windowWidth = $(window).width();
			this.newWidth = this.windowWidth;
			this.newHeight = this.windowWidth / this.imageAspectRatio;
		}
	
		this.performResize();
	}
