if(!$chk(slvr)) {
	var slvr = {};
}

/**
 * slvr.PageDimensionController
 *
 * @classDescription slvr.PageDimensionController
 */
slvr.PageDimensionController = new Class({

	options: {
		minHeight: 460,
		maxHeight: 2000,
		minWidth: 940,
		maxWidth: 2500,
		marginLeft: 25,
		marginRight: 25,
		marginBottom: 70,
		width:false,
		height:true
	},
	
	target: null,
	
	initialize: function(target, options) {
		this.setOptions(options);
		this.target = $(target);


		window.addEvent('resize', this.resizeHandler.bindWithEvent(this));
		// slvr.SharedNotificationCenter().postNotification('PageDimensionDidResize');
		this.resizeHandler();
	},
	
	resizeHandler: function() {
		if($chk(this.target)) {
			if(this.options.height) {
				this.target.setStyle('height', this.getTargetHeight());
			}
			if(this.options.width) {
				this.target.setStyle('width', this.getTargetWidth());
			}
		}
		slvr.SharedNotificationCenter().postNotification('PageDimensionDidResize');
	},
	
	getTargetWidth: function() {
		var tMinWidth = $chk(this.target.getStyle('min-width')) ? this.target.getStyle('min-width').toInt() : this.options.minWidth;
		var tMaxWidth = $chk(this.target.getStyle('max-width')) ? this.target.getStyle('max-width').toInt() : this.options.maxWidth;
		var windowWidth = window.getSize().x - (this.options.marginLeft + this.options.marginRight);
		
		if(windowWidth < tMinWidth) {
			return tMinWidth;
		} else if(windowWidth > tMaxWidth) {
			return tMaxWidth;
		} 
		return windowWidth;
	},
	
	getTargetHeight: function() {
		var tMarginTop = this.target.getPosition().y;
		
		var tMinHeight = $chk(this.target.getStyle('minHeight')) ? this.target.getStyle('minHeight').toInt() : this.options.minHeight;
		var tMaxHeight = $chk(this.target.getStyle('maxHeight')) ? this.target.getStyle('maxHeight').toInt() : this.options.maxHeight;
		var windowHeight = window.getSize().y - (tMarginTop + this.options.marginBottom);

		if(windowHeight < tMinHeight) {
			return tMinHeight;
		} else if(windowHeight > tMaxHeight) {
			return tMaxHeight;
		} 
		return windowHeight;
	}

});
slvr.PageDimensionController.implement(new Options);
slvr.PageDimensionController.implement(new Events);


// var headerController;
// window.addEvent('domready', function(){
// 	headerController = new slvr.PageDimensionController('.topNavigationContainer', {width:true, height:false});
// })
