dom = function(){

}

dom.prototype.Get = function(val, getBy, el){
	var newEl = false;
	
	if(getBy && typeof(getBy) == "string"){
		getBy = getBy.toLowerCase();
	}
	
	if(el && typeof(el) == 'object'){
		var lookIn = el;
	} else {
		var lookIn = document;
	}
	
	if(!getBy || getBy == 'id'){
		if(typeof(val) == "string"){
			newEl = document.getElementById(val);
		}
	}
	else if(getBy == 'tagname' || getBy == 'tag'){
		newEl = lookIn.getElementsByTagName(val);
	}
	else if(getBy == 'name'){
		newEl =document.getElementsByName(val);
	}
	else if(getBy == 'class'){
		var children = lookIn.childNodes;
		var ct = children.length;
		if(ct > 0){
			newEl = [];
			for(var i = 0; i < ct; i++){
				if(children[i].className && children[i].className == val){
					newEl.push(children[i]);
				}
			}
		}
	}
	else if(getBy == "parent"){
		var parent = el.parentNode;
		val = val.toUpperCase();
		var count = 0;
		while(parent.tagName != val && count < 1000){
			parent = parent.parentNode;
			count++;
		}
		
		newEl = parent;
	}
	
	return newEl;
}

dom.prototype.Create = function(tag, attributes, relatives){
	var el = false;
	
	el = document.createElement(tag);
	
	if(attributes){
		for(var attribute in attributes){
			if(attribute == 'className' || attribute == 'class'){
				el.className = attributes[attribute];
			}
			else if(attribute == 'style'){
					this.SetStyles(el, attributes[attribute]);
			}
			else{
				el.setAttribute(attribute, attributes[attribute]);
			}
		}
	}
	
	if(relatives){
		if(relatives.child){
			if(typeof(relatives.child) == "string"){
				el.appendChild(document.createTextNode(relatives.child));
			}
			else{
				el.appendChild(relatives.child);
			}
		}
		
		if(relatives.parent){
			relatives.parent.appendChild(el);
		}
	}
	
	return el;
}

dom.prototype.SetStyles = function(el, styles){
	if(el && styles){
		if(styles.indexOf(';') > -1){
			styles = styles.split(';');
		} else {
			styles = [styles];
		}
		
		var style;
			
		for(var i = 0; i < styles.length; i++){
			style = styles[i].split(':');
			
			if(style[0].indexOf('-') > -1){
				var styleName = style[0].split('-');
				styleName[1][0].toUpperCase();
				styleName = styleName[0] + styleName[1];
				el.style[styleName] = style[1];
			} else {
				el.style.style[0] = style[1];
			}
		}
	}
}

dom.prototype.RemoveChildNodes = function(el){
	if(typeof(el) == "object"){
		if(el.hasChildNodes()){
			while(el.hasChildNodes()){
				el.removeChild(el.lastChild);
			}
		}
	}
}

var Dom = new dom();
var dom = Dom;