/**
 * @namespace Methods for DOM element manipulation, DOM event handling
 */
var $dom = {
	
	/** 
	 * nodeType value associated with elements
	 * @constant 
	 */
	ELEMENT_NODE: 1,
	/**
	 * nodeType value associated with attributes
	 * @constant 
	 */
	ATTRIBUTE_NODE: 2,
	/**
	 * nodeType value associated with text
	 * @constant 
	 */
	TEXT_NODE: 3,
	/**
	 * nodeType value associated with CDATA
	 * @constant 
	 */
	CDATA_SECTION_NODE: 4,
	
	offScreenCtr: null,
	
		// DOM querys
		// Dependency: jQuery

	querySelector: function(selector, asJQuery) {
		if (asJQuery) return $(selector);
		return $(selector)[0];
	},
	
	querySelectorAll: function (selector, asJQuery) {
		if (asJQuery) return $(selector);
		return $(selector).get();
	},
	
	
	// no dependency
	byId: function(id) {
		return document.getElementById(id);
	},

	/**
	 * Creates/retrieves an offscreen container 
	 * @return DIV Element
	 */
	getOffscreenDiv: function(){
		this.offScreenCtr = this.offScreenCtr || this.byId("__offscr__");
		if (!this.offScreenCtr) {
			this.offScreenCtr = document.createElement("div");
			this.offScreenCtr.id = "__offscr__";
			this.offScreenCtr.style.position = "absolute";
			this.offScreenCtr.style.left = "-5000px";
			this.offScreenCtr.style.top = "0";
			document.body.appendChild(this.offScreenCtr);
		}
		return this.offScreenCtr;
	},
	
	
	// element creation wrappers
	/**
	 * Create a DIV element (optionally) with id and class attributes, plus innerHTML if desired 
	 * @param {String} id (optional) Value of the id attribute
	 * @param {String} clas (optional) Class name 
	 * @param {String} ihtml (optional) innerHTML for the created DIV
	 * @return {HTMLElement} DIV element
	 */
	createDiv: function(id, clas, ihtml){
		return this.createTag("div", id, clas, ihtml);
	},
	
	/**
	 * Create any element (optionally) with id and class attributes, plus innerHTML if desired 
	 * @param {String} tagName Value of the id attribute
	 * @param {String} id (optional) Value of the id attribute
	 * @param {String} clas (optional) Class name 
	 * @param {String} ihtml (optional) innerHTML for the created DIV
	 * @return {HTMLElement} the created element
	 */
	createTag: function(tagName, id, clas, ihtml){
		var d = document.createElement(tagName);
		if (id) d.setAttribute("id", id);
		if (clas) d.className = clas;
		if (ihtml) d.innerHTML = ihtml;
		return d;
	},
	
	
	/**
	 * Create an Iframe to prevent bleed-thru artifacts in IE (can occur with layered divs over certain form controls)
	 * @param {Object} rectangle object with left, top, width, and height properties (as Numbers) to describe size/location of iframe
	 * @param {Number} z  zIndex value
	 * @return {HTMLElement} an iframe element
	 */
	createHiddenIFrame: function(rectangle,z) {
		var px = "px";
		var bf = this.createTag("iframe", "bf-" + $util.getUid());
		bf.src = "javascript:false;";
		bf.style.opacity = 0;
		bf.style.filter = "alpha(opacity=0)";
		bf.style.background = "#ff00ff";
		bf.style.position = "absolute";
		var stylobj = {display:"block"};
		for (var q in rectangle) {
			var p = q == "x" ? "left" : q == "y" ? "top" : q;
			stylobj[p] = rectangle[q] + px;
		}
		if (z) {stylobj.zIndex = z;}
		for (var q in stylobj) {
			if (stylobj[q]) {
				elem.style[q] = stylobj[q];
			}
		}
		return bf;
	}

};

