var Deepend = {
	_current: null,
	getCurrent: function() {
		if (this._current == null) this._current = new Deepend.website();
		
		return this._current;
	}
};

(function($) {
	Deepend.website = function() {
		this._bgImgCont = $("#BackgroundImage");
		this._bgImg = $("#BackgroundImage").find("img");
		this._minWidth = 1000;
		this._minHeight = 600;
		this._imgWidth = 1680;
		this._imgHeight = 1050;
		this._window = $(window);
	}
	
	Deepend.website.prototype.handleResize = function() {
		var ww = this._window.width();
		var wh = this._window.height();
		
		var nw = ww;
		var nh = wh;
		
		if (nw < this._minWidth) nw = this._minWidth;
		if (nh < this._minHeight) nh = this._minHeight;
		
		this._bgImgCont.width(nw);
		this._bgImgCont.height(nh);
		
		nw = ww;
		if (nw < this._imgWidth) nw = this._imgWidth;
		nh = Math.round(nw * this._imgHeight / this._imgWidth);
		
		if (nh < wh) {
			nh = wh;
			if (nh < this._imgHeight) nh = this._imgHeight;
			nw = Math.round(nh * this._imgWidth / this._imgHeight);
		}

		var nx = Math.round((ww - nw) / 2);
		var ny = Math.round((wh - nh) / 2);

		this._bgImg.css({left:nx,top:ny});
		this._bgImg.width(nw);
		this._bgImg.height(nh);
	}
	
	Deepend.getCurrent().handleResize();
	$(window).resize(function() {
		Deepend.getCurrent().handleResize();
	});
})(jQuery);
