if (!document.trace) {
	this.trace = function(output) {
		//if (console.log && output) console.log(output);
	}
}


window.addEvent('domready', function() {
	var d = new DocumentView();
});

var windowHeightOld = window.getHeight();
var docViewInitialized = false;

var DocumentView = new Class({
	
	
	initialize : function() {
		
		$('top_elements').setStyle('position', 'absolute');
		$('bottom_elements').setStyle('position', 'absolute');
		
		this.windowHeight = window.getHeight();
		
		this.initialized = false;
		
		window.addEvent('resize', this.updateLayout);
		this.updateLayout();
	},
	
	
	// IE was unable to reference this method through window.addEvent('resize', this.updateLayout.bindWithEvent(this))
	// Therefore everything here is scoped local to the method or global to the document vs. instance scope :P
	updateLayout : function(e) {
		
		var height = window.getHeight();
		
		if (height != windowHeightOld || !docViewInitialized) {
			docViewInitialized = true;
			windowHeightOld = height;
		
			var top = $('top_elements');
			var bottom = $('bottom_elements');
			var container = $('container');
		
			container.setStyle('height', height + 'px');
			bottom.setStyle('top', height - bottom.getCoordinates().height + 'px');
		
			var topHeight = top.getCoordinates().height;
		
			if (bottom.getCoordinates().top < topHeight) {
				bottom.setStyle('top', topHeight + 'px');
			}
		}
	},
	
	
	toString : function() {
		return "[DocumentView]";
	}
	
});
