GoldmanSachs.WindowGridManager = new Class({
	options: {
		snapToGrid: false
	},
	presets : {
		CONTAINER_ID: 'gs_doc'
	},
	initialize: function (options) {
		this.setOptions(options);
		window.addEvent ('domready', this.doOnLoad.bind(this));
	},
	doOnLoad : function () {
		this.resizeNode = $(this.presets.CONTAINER_ID);
		this.widthFX = new Fx.Style(this.resizeNode, 'width', {wait: false, duration: 500, transition: Fx.Transitions.Quart.easeOut})
		this.resizeTimer = new GoldmanSachs.Timer(0);
		this.resizeTimer.addEvent('onExpire', this.doGridResize.bind(this));
		window.addEvent ('resize', this.resizeTimer.restart.bind(this.resizeTimer));
		if (window.ie == true) {
			this.doGridResize();
		}
	},
	getGridWidth: function (state) {
		var offset = 0;
		if (state == 'init') {
			offset = (window.webkit == true) ? 15 : 17;	
		}
		var bw = window.getWidth();
		bw = bw - offset;
		var gw = 0;
		if (this.options.snapToGrid == true) {
			if ( bw < 1062){gw = 910; // MIN
			} else if (bw < 1138){gw = 986;
			} else if (bw < 1214){gw = 1062;
			} else {gw = 1138;}	
		} else {
			if ( bw < 987){gw = 987; // MIN
			} else if (bw > 1280){ gw = 1280; // MAX
			} else {
				if (state == 'init')
					gw = null;
				else
					gw = bw;	
			}
		}
		return gw;
	},
	doGridResize : function() {
		var gw = this.getGridWidth('resize');
		this.widthFX.stop();
		if (gw)
			this.widthFX.start(gw);	
	},
	doInitPageLoad : function () {
		document.write('<style type="text/css"> #' + this.presets.CONTAINER_ID + ' { width: ' + this.getGridWidth('init') + 'px;}</style>');
	}
});
GoldmanSachs.WindowGridManager.implement(new Options);