(function(){

/*
	Class: SbDom 
	The class to customize DOM functions 
*/
function SbDom(num)
{
	/* 
	 * private member
	 */
	var count = num; 

	/*
	 * private method
	 */
	function getCount() {
		if ( ++count < Number.MAX_VALUE) {
			return count;
		} else {
			return 0;
		}
	}
	
/*
	Function: generateUniqueId()
	returns <string> unique ID;	

	this is a privelege method which accesses private 
	member(s) and method(s) and is available to other 
	objects and methods.
*/
	this.getUniqueId = function () {
		return "sb_" + getCount();
	};

}

SbDom.prototype.toString = function() { return "[SB.util.SbDom]"; }

/*
	Function: cloneNode()
	A simple method to clone a DOM node and set the node with unique ID 
	@elm <Object or String> element to clone;
	@deep <bool> If evaluates to true, the whole subtree is copied,
		          otherwise none of the child nodes are cloned;
	return <object> if success or -1 if failed;
*/
SbDom.prototype.cloneNode = function( elm, deep )
{
	var obj = null;
	var cloneObj = null;
	var all = null;
	
	if (typeof(elm) == "object" ) {
		obj = elm;
	} else if (typeof(elm) == "string" ) {
		obj = document.getElementById(elm);
	} else {
		return -1;
	}
	
	cloneObj = obj.cloneNode(deep);
	if (cloneObj) {
		cloneObj.id = this.getUniqueId();
		if (deep) {
			all = cloneObj.getElementsByTagName("*");
			for (var ix=0; ix<all.length; ix++ ) {
				all[ix].id = this.getUniqueId();
			}
		} 
		return cloneObj;
	} else {
		return -1;
	}
	
};	

window['SB']['util']['SbDom'] = new SbDom(1);

})();
