var Element = {
	create:function(name, attributes, content, parentNode){
		/* function for creating DOM Element;
			* Attributes:
				- name = the node-name
				- attributes = HashTable of element attributes
				- content = Optional. Text to insert in the new node
			* the function returns the new node
		*/
		var el = document.createElement(name);
		for(var att in attributes){
			if(att=="class"){
				this.classNames(el).add(attributes[att]);
			}else{
				el.setAttribute(att, attributes[att]);
			}
		}
		if(content && content !="") this.insertText(el, content);
		if(parentNode) parentNode.appendChild(el);
		return el;
	},
	replace:function(obj, toObj){
		// Replace an element with other element
		return obj.parentNode.replaceChild(toObj, obj);
	},
	remove:function(el){
		// Remove an element from the DOM chain
		el.parentNode.removeChild(el);
	},
	eraseContent:function(element){
		// remove all child of the element
		if((typeof element)=="string") element = Element.find(element);
		while(element.firstChild) element.removeChild(element.firstChild);
		return element;
	},
	setText:function(element, text){
		// replacing the content of the element with text
		element = this.eraseContent(element);
		return this.insertText(element, text);
	},
	getText:function(element){
		// return the content of the element
		if(element.innerText) return element.innerText;
		else if(element.textContent) return element.textContent;
		else if(element.nodeValue) return element.nodeValue;
		else return null;
	},
	insertText:function(element, text){
		// Insert text as a TextNode in the element
		if((typeof element)=="string") element = Element.find(element);
		var textNode = document.createTextNode(text);
		element.appendChild(textNode);
		return element;
	},
	copy:function(element){
		// return a  deep copy of the element
		if((typeof element)=="string") element = Element.find(element);
		return element.cloneNode(true);
	},
	classNames:function(element){
		return new Element.Classes(element);
	},
	find:function(id){
		// find an element in the DOM tree unless there is the element in the pool
		if(this.Pool[id]) return this.Pool[id];
		this.Pool[id] = document.getElementById(id);
		return this.Pool[id];
	},
	isVisible:function(element){
		return Element.getStyle("display")!="none";
	},
	show:function(element, as){
		if((typeof element)=="string") element = Element.find(element);
		element.style.display = as||"block";
	},
	hide:function(element){
		if((typeof element)=="string") element = Element.find(element);
		element.style.display = "none";
	},
	toggle:function(element){
		if((typeof element)=="string") element = Element.find(element);
		Element[Element.isVisible(element)?"show":"none"](element);
	},
	getStyle:function(element, prop){
		if((typeof element)=="string") element = Element.find(element);
		if (element.style[prop]) {
			// inline style property
			return element.style[prop];
		} else if (element.currentStyle) {
			// external stylesheet for Explorer
			return element.currentStyle[prop];
		} else if (document.defaultView && document.defaultView.getComputedStyle) {
			// external stylesheet for Mozilla and Safari 1.3+
			prop = prop.replace(/([A-Z])/g,"-$1");
			prop = prop.toLowerCase();
			return document.defaultView.getComputedStyle(element,"").getPropertyValue(prop);
		} else {
			// Safari 1.2
			return null;
		}
	},
	Classes:function(element){
		if((typeof element)=="string") element = Element.find(element);
		var oElement = element;
		this.add = function(name){
			var c = oElement.className;
			oElement.className = c.concat(" ", name);
		}
		this.remove = function(name){
			var c = oElement.className;
			c = oElement.className = c.replace(new RegExp("(^|\\b)"+name+"(\\b|$)","g"), "");
		}
	},

	Pool:{} /// Private
}

document.getElementsByClassName = function(searchClass,node,tag) {
	if ( node == null ) node = document;

	if ( tag == null ) tag = '*';

	var classElements = [],
		els = node.getElementsByTagName(tag),
		elsLen = els.length,
		pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");

	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements.push(els[i]);
		}
	}
	return classElements;
}