var CSS,View,Common,DOM;

CSS={
	Add:function (oEl,sClass) {
		if (oEl) return !this.Contains(oEl,sClass) ? oEl.className+=" "+sClass : oEl.className;
	},
	Remove:function (oEl,sClass) {
		if (oEl) return oEl.className=oEl.className.replace(new RegExp("(\\b|\\s)"+sClass+"(\\b|\\s)"),"");
	},
	Contains:function (oEl,sClass) {
	    //alert(oEl.className)
		if (oEl) return new RegExp("\\b"+sClass+"\\b").test(oEl.className);
	},
	CurrentStyle:function (oEl,sProp) {
		if (document.defaultView && document.defaultView.getComputedStyle) return document.defaultView.getComputedStyle(oEl,"").getPropertyValue(sProp);
		if (oEl.currentStyle) return oEl.currentStyle[sProp];
	},
	Rule:function (oEl,sProp,sValue,sUnit) {
		oEl.style[sProp]=sValue+(sUnit || "");
	}
}

View={
	Width:function () {
		return DOM.Doc.body.clientWidth;
	},
	Height:function () {
		return DOM.Doc.body.clientHeight;
	},
	ScrollWidth:function () {
		return DOM.Doc.body.scrollWidth;
	},
	ScrollHeight:function () {
		return DOM.Doc.body.scrollHeight;
	},
	ScrollX:function () {
		return DOM.Doc.body.scrollLeft;
	},
	ScrollY:function () {
		return DOM.Doc.body.scrollTop;
	},
	Left:function (oEl) {
		return oEl.getClientRects()[0].left-2;
	},
	Top:function (oEl) {
		return oEl.getClientRects()[0].top-2;
	},
	OffsetLeft:function (oEl) {
		for (var iX=0;oEl;iX+=oEl.offsetLeft,oEl=oEl.offsetParent);

		return iX;
	},
	OffsetTop:function (oEl) {
		for (var iY=0;oEl;iY+=oEl.offsetTop,oEl=oEl.offsetParent);

		return iY;
	}
}

Common={
	False:function () {
		return false;
	},
	LastZIndex:10000,
	GetLastZIndex:function () {
		return ++Common.LastZIndex;
	}
}

DOM={
	Doc:document,
	Element:function (Tag,Attributes) {
		var Base=this,
			oAttribute,
			References={};

		this.Node=typeof Tag=="string" ? DOM.Doc.createElement(Tag) : Tag;

		this.Insert=function (Container) {
			(Container.Node || Container).appendChild(this.Node);

			return this;
		}

		this.InsertBefore=function (Container,Child) {
			Container.insertBefore(this.Node,Child);

			return this;
		}

		this.Html=function (Html) {
			if (typeof Html=="object") this.Node.appendChild(Html);
			else this.Node.innerHTML=Html;

			return this;
		}

		this.Text=function (Text) {
			this.Node.innerText=Text;

			return this;
		}

		this.Attributes={
			Add:function (Attribute,Value) {
				Base.Node.setAttribute(Attribute,Value);

				return Base;
			},
			Remove:function (Attribute) {
				Base.Node.removeAttribute(Attribute);

				return Base;
			}
		}

		this.CSS={
			Add:function (sClass) {
				window.CSS.Add(Base.Node,sClass);

				return Base;
			},
			Remove:function (sClass) {
				window.CSS.Remove(Base.Node,sClass);

				return Base;
			},
			Contains:function (sClass) {
				return window.CSS.Contains(Base.Node,sClass);
			},
			CurrentStyle:function (sProp) {
				window.CSS.CurrentStyle(Base.Node,sProp);

				return Base;
			},
			Rule:function (sProp,sValue,sUnit) {
				sProp=sProp.replace(/\-(.)/,function (a,b) { return b.toUpperCase(); });

				window.CSS.Rule(Base.Node,sProp,sValue,sUnit);

				return Base;
			}
		}

		this.Event={
			Add:function (Event,Func) {
				Base.Node.attachEvent(Event,Func);

				return Base;
			},
			Remove:function (Event,Func) {
				Base.Node.detachEvent(Event,Func);

				return Base;
			}
		}
	},
	Parent:function (El,Tag,Attribue) {
		var bParent=false;

		while (El.nodeName.toLowerCase()!=Tag.toLowerCase() || !bParent) {
			El=El.parentNode;
			if (!Attribue || (Attribue && El.getAttribute(Attribue))) bParent=true;
		}

		return El;
	},
	$:function (ID) {
		return DOM.Doc.getElementById(ID);
	},
	$$:function (Tag,Container) {
		Container=Container || DOM.Doc;
		return Container.getElementsByTagName(Tag);
	},
	$$$:function (Name,Container) {
		Container=Container || DOM.Doc;
		return Container.getElementsByName(Name); 
	}
}

Object.prototype.Length=function () {
	var oProp,
		iLen=0;

	for (oProp in this) if (typeof(this[oProp])!="function") iLen++;

	return iLen;
}

Object.prototype.First=function () {
	var oProp;

	for (oProp in this) if (typeof(this[oProp])!="function") return this[oProp]
}

Object.prototype.Last=function () {
	var oProp,oTemp;

	for (oProp in this) if (typeof(this[oProp])!="function") oTemp=this[oProp];

	return oTemp;
}

Object.prototype.Empty=function () {
	var oProp;

	for (oProp in this) if (typeof(this[oProp])!="function") delete this[oProp];

	return this;
}