var Mortice = {}

Mortice.Component = Class.create({
	initialize: function(element) {
		this.element = $(element);
		this.children = [];
		this.parent   = null;
	},
	
	getSize: function() {
		return {"width": this.element.getWidth(), "height": this.element.getHeight()};
	},
	
	setSize: function(size) {
		this.element.style.width = size.width + "px";
		this.element.style.height = size.height + "px";
	},
	
	getParent: function() {
		return this.parent;
	},
	
	setParent: function(parent) {
		this.parent = parent;
	},
	
	add: function(component) {
		this.children.push(component);
		component.setParent(this);
	},
	
	remove: function(component) {
		component.setParent(null);
		this.children = this.children.without(component);
	},
	
	getChildren: function() {
		return this.children;
	}
});

window.xpath = !!(document.evaluate);
if (window.ActiveXObject) window.ie = window[window.XMLHttpRequest ? 'ie7' : 'ie6'] = true;
else if (document.childNodes && !document.all && !navigator.taintEnabled) window.webkit = window[window.xpath ? 'webkit420' : 'webkit419'] = true;
else if (document.getBoxObjectFor != null) window.gecko = true;
window.khtml = window.webkit;

window.getWidth = function(){
	if (this.webkit419) return this.innerWidth;
	if (this.opera) return document.body.clientWidth;
	return document.documentElement.clientWidth;
}

window.getHeight = function(){
	if (this.webkit419) return this.innerHeight;
	if (this.opera) return document.body.clientHeight;
	return document.documentElement.clientHeight;
}

window.getScrollWidth = function(){
	if (this.ie) return Math.max(document.documentElement.offsetWidth, document.documentElement.scrollWidth);
	if (this.webkit) return document.body.scrollWidth;
	return document.documentElement.scrollWidth;
}

window.getScrollHeight = function(){
	if (this.ie) return Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight);
	if (this.webkit) return document.body.scrollHeight;
	return document.documentElement.scrollHeight;
}

window.getScrollLeft = function(){
	return this.pageXOffset || document.documentElement.scrollLeft;
}

window.getScrollTop = function(){
	return this.pageYOffset || document.documentElement.scrollTop;
}

