if (typeof HumanCopy === 'undefined')
	HumanCopy = {};

HumanCopy.ContentResize = {
	element: null,
	options: {},
	init: function(element, options) {
		HumanCopy.ContentResize.options = Object.extend({
			extraHeight: 0, // define any extra height that need to be considered (such as a footer)
			getContentHeight: HumanCopy.ContentResize.getContentHeight, // can pass a function for calculating content height
			setContentHeight: HumanCopy.ContentResize.setContentHeight, // can pass a function for customizing content height setting
			resizeOnLoad: true
		}, options || {});
		HumanCopy.ContentResize.element = $(element);
		if (HumanCopy.ContentResize.options.resizeOnLoad) HumanCopy.ContentResize.resize();
	},

	getContentHeight: function() {
		return HumanCopy.ContentResize.element.getHeight()+HumanCopy.ContentResize.options.extraHeight;
	},

	setContentHeight: function(new_height) {
		var style = new_height ? new_height + 'px' : false;
		if (new_height) {
			document.body.style.height = style;
			HumanCopy.ContentResize.element.setStyle({
				height: style,
				minHeight: style
			});
		}
		return style;
	},

	resize: function(new_height) {
		new_height = (new_height || document.viewport.getDimensions().height)-HumanCopy.ContentResize.options.extraHeight;

		var content_height = HumanCopy.ContentResize.options.getContentHeight();
		if (new_height <= content_height) {
			new_height = content_height; // +HumanCopy.ContentResize.options.extraHeight;
		}

		HumanCopy.ContentResize.options.setContentHeight(new_height);
	}
};

window.onresize = function() {
	HumanCopy.ContentResize.resize();
};

