/* JS Layout, Prototype 1.X required */
var manualWindowSize = 450;

var Layout = {
	registeredElements: $A([]),
	windowWidth: 0,
	windowHeight: 0,
	
	doLayout: function(force) {
		if (!this._updateWindowDimensions() && !force) { return; }
		
		this.registeredElements.each(function(e) {
			$$(e.selector).each(function(element) {
				element.setStyle({ height: e.func(element) + "px" });
			});
		})
	},
	
	
	registerElement: function(selector, func) {
		this.registeredElements.push({ selector: selector, func: func });	
	},
	
	_updateWindowDimensions: function() {
		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
		
		if (this.windowWidth != myWidth || this.windowHeight != myHeight) {
			this.windowWidth = myWidth;
			this.windowHeight = myHeight;
			
			if (this.windowHeight < manualWindowSize)
			{
			    this.windowHeight = manualWindowSize
			}
			
			return true;
		} else {
			return false;	
		}
	},
	
	bindEventListeners: function() {
		Event.observe(window, "load", function() {
			Layout.doLayout();
			
//			Event.observe(window, "focus", function() {
//				Layout.doLayout();
//			});
			
			Event.observe(window, "resize", function() {
				Layout.doLayout();
			});
		});
	}
};



