var JadeDOM = {
	Document: {
		ClientWidth: function() {
				return document.documentElement.clientWidth;
			},
		ClientHeight: function() {
				return document.documentElement.clientHeight;
			},
		Width: function () {
			var D = document;
			return Math.max(D.body.scrollWidth, D.documentElement.scrollWidth,D.body.offsetWidth, D.documentElement.offsetWidth,D.body.clientWidth, D.documentElement.clientWidth);
			},
		Height: function() {
			var body = document.getElementsByTagName('body')[0];
			return Math.max(document.documentElement.scrollHeight,document.documentElement.clientHeight,body.scrollHeight,body.scrollHeight,body.offsetHeight)
			},
		ScrollX: function () {
			return (document.documentElement.scrollLeft!=null) ? document.documentElement.scrollLeft : window.pageXOffset;
			},
		ScrollY: function () { 
			return (document.documentElement.scrollTop!=null) ? document.documentElement.scrollTop : window.pageYOffset;
			}
	},
	TopDocument: {
		Width: function () {
			var D = top.document;
			return Math.max(D.body.scrollWidth, D.documentElement.scrollWidth,D.body.offsetWidth, D.documentElement.offsetWidth,D.body.clientWidth, D.documentElement.clientWidth);
			},
		Height: function() {
			var D = top.document;
			return Math.max(D.body.scrollHeight, D.documentElement.scrollHeight,D.body.offsetHeight, D.documentElement.offsetHeight,D.body.clientHeight, D.documentElement.clientHeight);
			},
		ScrollX: function () {
			return (top.document.documentElement.scrollLeft!=null) ? top.document.documentElement.scrollLeft : window.pageXOffset;
			},
		ScrollY: function () { 
			return (top.document.documentElement.scrollTop!=null) ? top.document.documentElement.scrollTop : window.pageYOffset;
			}
	},	
	GetElementsByClass: function (className,node,tag) {
		var classElements = new Array();
		if ( node == null ) { node = document; }
		if ( tag == null ) { tag = '*'; }
		var elements = node.getElementsByTagName(tag);
		var pattern = new RegExp('(^|\\\\s)'+className+'(\\\\s|$)');
		
		for (var i = 0, j = 0; i < elements.length; i++) 
		{
			if ( pattern.test(elements[i].className) ) 
			{
				classElements[j] = elements[i];
				j++;
			}
		}
		return classElements;
	},
	GetCurrentStyle: function (node,cssRule) {
		var result='';
		if(document.defaultView && document.defaultView.getComputedStyle) {
			result=document.defaultView.getComputedStyle(node, null).getPropertyValue(cssRule);
		}
		else if(node.currentStyle){
			var ar = cssRule.match(/\w[^-]*/g);
			var s = ar[0];
      
			for(var i = 1; i < ar.length; ++i)		   
			{
				s += ar[i].replace(/\w/, ar[i].charAt(0).toUpperCase());
			}
			result=node.currentStyle[s];
		}
		return result;
	},
	GetElementsByName: function(name){
		var arrayElements = document.getElementsByTagName("*");
		var arrayNew = new Array();
		for(i=0;i<arrayElements.length;i++)
		{
			if(arrayElements[i].getAttribute('name') == name) { arrayNew.push(arrayElements[i]); }
		}
		return arrayNew;
	},
	GetElementById: function (id){
		return document.getElementById ? document.getElementById(id):null;
	},
	GetIframeDocument: function(iframe){
		var doc = iframe.contentWindow || iframe.contentDocument;
		if (doc.document) { doc = doc.document; }
		return doc;
	},
	InsertAfter: function (nNew, nRef){
		nRef.parentNode.insertBefore(nNew, nRef.nextSibling);
		
	},
	InsertBefore: function (nNew, nRef){
		nRef.parentNode.insertBefore(nNew, nRef);
	},
	Add: function(parent,tag,className,id,innerHTML) {
		if(!$.isDefined(tag)) { tag='div'; }
		var obj = document.createElement(tag);
		if($.isDefined(className)){ obj.className=className; }
		if($.isDefined(id)){ obj.id=id; }
		if($.isDefined(innerHTML)){ obj.innerHTML=innerHTML; }
		if($.isDefined(parent)){ parent.appendChild(obj); }
		return obj;
	},
	SetCaretPosition: function(element, position){
		if(typeof(element)!="undefined"){
			if(element.createTextRange){
				var range=element.createTextRange();
				range.move('character', position);
				range.select();
			}
			else{
				if(element.selectionStart){
					element.focus();
					element.setSelectionRange(position, position);
				}
				else{
					element.focus(); 
				}
			}
		}
	},
	SetCaretSelection: function(element, start, end){
		if(typeof(element)!="undefined"){
			if(element.createTextRange){
				var range=element.createTextRange();
				range.move('character', end);
				range.select();
			}
			else{
				if(element.selectionStart){
					//element.focus();
					element.setSelectionRange(start, end);
				}
				else{
					//element.focus(); 
				}
			}
		}
	},
	Remove: function(element){
		if($.isDefined(element.parentNode)){ element.parentNode.removeChild(element); }
		else if($.isFunction(element.remove)){ element.remove(); }
	}
}
Jade.LoadLibrary('DOM',JadeDOM);