// Chaining Library - http://devnet.mageuk.com/
var gE = function(element) { return wrap(document.getElementById(element)); };
var cE = function(element) { return wrap(document.createElement(element)); };
var tN = function(text) { return document.createTextNode(text); };

function wrap(node)
{
	if (typeof node == 'string') { node = document.getElementById(node); }
	for (var key in __DOMShortcuts) { if (typeof node[key] == 'undefined') { node[key] = __DOMShortcuts[key]; } }
	return node;
}
var __DOMShortcuts = {
	// Methods to allow function chaining (Emulate changing properties)
		// Methods
			aC /* appendChild */ : function(node) { return this.appendChild(node); },
			tC /* tryCatch */ : function(toTry, toCatch) {
				/* Arguments as functions please
				 * Both receive 'this' (ie. the object) as the first argument
				 * Function returns 'this' for chaining
				 * toCatch receives error
				 */ try { toTry(this); } catch (e) { toCatch(this, e); }; return this; },
			iE /* inputElement */ : function(name, type, value, onclick, keydown, keyup, lock) {
					try {
						// Microsoft Uncompliant Scripting Engine .NET3.5 (tm)
						
						if(onclick) {
							var inputElement = this.aC(cE('<input type="'+type+'" name="'+name+'" value="'+value+'" onkeyup="'+aon(keyup)+'" onkeydown="'+aon(keydown)+'"'+(lock==true?"disabled='true'":"")+' />')).onclick = onclick;
						} else {
							var inputElement = this.aC(cE('<input type="'+type+'" name="'+name+'" value="'+value+'" onkeyup="'+aon(keyup)+'" onkeydown="'+aon(keydown)+'"'+(lock==true?"disabled='true'":"")+' />'));
						}
					} catch(e) {
						var inputElement = this.aC(cE('input'));
						inputElement.type = type;
						inputElement.value = value;
						inputElement.name = name;
						inputElement.onkeyup = keyup;
						inputElement.onkeydown = keydown;
						inputElement.disabled = lock;
						if(onclick) {
							inputElement.onclick = onclick;
						}
					}
					return this;
				},
		// Styles
			sW /* setWidth */ : function(newWidth) { this.style.width = newWidth; return this; },
			sH /* setHeight */ : function(newHeight) { this.style.height = newHeight; return this; },
			sD /* setDisplay */ : function(newDisp) { this.style.display = newDisp; return this; },
			sC /* setColo(u)r */ : function(newCol) { this.style.color = newCol; return this; },
			sBC /* setBackgroundColour */ : function(newCol) { this.style.backgroundColor = newCol; return this; },
			sFS /* setFontSize */ : function(newFS) { this.style.fontSize = newFS; return this; },
			cN /* className */ : function(className) { this.className = className; return this; },
			tA /* textAlign */ : function(textAlign) { this.style.textAlign = textAlign; return this; },
			sP /* setPadding */ : function(padding) { this.style.padding = padding; return this; },
		// Attributes
			sN /* setName */ : function(newName) { this.name = newName; return this; },
			sV /* setValue */ : function(newValue) { this.value = newValue; return this; },
			sA /* setValue */ : function(att, val) { this.setAttribute(att, val); return this; },
			sID /* setID */ : function(newID) { this.id = newID; return this; },
			oC /* onClick */ : function(oCfunc) { this.onclick = oCfunc; return this; },
			oMO /* onMouseOver */ : function(oMOfunc) { this.onmouseover = oMOfunc; return this; },
			oMOu /* onMouseOut */ : function(oMOfunc) { this.onmouseout = oMOfunc; return this; },
			iT /* innerText */ : function(newiT) { this.innerText = newiT; return this; },
			iH /* innerHTML */ : function(newiH, ret) { if(newiH == null && ret == true) { return this.innerHTML }
				else { this.innerHTML = newiH; if(ret == true) { return this.innerHTML; } else { return this; } } }
};
function rN(node) {
	return gE(node).parentNode.removeChild(gE(node));
}
function dN(node) {
	return (gE(node).iH(""));
}
function cN(node) {
	return gE(node).iH("");
}
function gN(node, clean) {
	return gE(node).iH(null, true);
}
function rC(str, char) {
	var outstr = ((str.charAt(str.length-1, 1) == char) ? str.substring(0,str.length-1) : str);
	return outstr;
}

// Hacky click-off thingy for the drop down box in IE
var IEDROP = false;
var clicks = 0;
