function stopBubble(e) {
	if(e&&e.stopPropagation)
		e.stopPropagation();
	else
		window.event.cancelBubble=true;
}

function cleanWhitespace( element ) {
	// If no element is provided, do the whole HTML document
	element = element || document;

	// Use the first child as a starting point
	var cur = element.firstChild;

	// Go until there are no more child nodes
	while ( cur != null ) {
		// If the node is a text node, and it contains nothing but whitespace
		if ( cur.nodeType == 3 && ! /\S/.test(cur.nodeValue) ) {
			// Remove the text node
			element.removeChild( cur );
		// Otherwise, if it's an element
		} else if ( cur.nodeType == 1 ) {
			// Recurse down through the document
			cleanWhitespace( cur );
		}
		cur = cur.nextSibling; // Move through the child nodes
	}
}

function domReady( f ) {
	// If the DOM is already loaded, execute the function right away
	if ( domReady.done ) return f();

	// If we've already added a function
	if ( domReady.timer ) {
		// Add it to the listof functions to execute
		domReady.ready.push( f  );
	} else {
		// Attach an event for when the page finishes loading,
		// just in case it finishes first. Uses addEvent.
		addEvent( window, "load", isDOMReady );
		// Initialize the array of functions to execute
		domReady.ready = [ f ];
		//  Check to see if the DOM is ready as quickly as possible
		domReady.timer = setInterval( isDOMReady, 13 );
	}
}

// Checks to see if the DOM isready for navigation
function isDOMReady() {
	// If we already figured out that the page is ready, ignore
	if(domReady.done)
		return false;

	// Check to see if a number of functions and elements are
	// able to be accessed
	if( document && document.getElementsByTagName && document.getElementById && document.body) {
		// If they're ready, we can stop checking
		clearInterval( domReady.timer );
		domReady.timer = null;

		// Execute all the functionsthat were waiting
		for ( var i = 0; i < domReady.ready.length; i++ )
			domReady.ready[i]();

		// Remember that we're now done
		domReady.ready = null;
		domReady.done = true;
	}
}

function addEvent(element, type, handler) {
	// assign each event handler a unique ID
	if (!handler.$$guid) handler.$$guid = addEvent.guid++;

	// create a hash table of event types for the element
	if(!element.events)element.events={};

	//createahashtableofeventhandlersforeachelement/eventpair
	var handlers = element.events[type];

	if(!handlers){
		handlers = element.events[type] = {};
		//storetheexistingevent handler (if there is one)
		if (element["on" + type]) {
			handlers[0]=element["on"+type];
		}
	}

	//storetheeventhandlerinthehashtable
	handlers[handler.$$guid] = handler;

	//assignaglobaleventhandlertodoallthework
	element["on" + type] = handleEvent;
};

// a counter used tocreateuniqueIDs
addEvent.guid = 1;

function removeEvent(element, type, handler) {
	//deletetheeventhandlerfromthehashtable
	if(element.events&&element.events[type]){
		deleteelement.events[type][handler.$$guid];
	}
};

function handleEvent(event) {
	var returnValue = true;

	//grabtheeventobject(IEusesaglobal event object)
	event = event || fixEvent(window.event);

	//getareferencetothehash table of event handlers
	var handlers = this.events[event.type];

	//executeeacheventhandler
	for (var i in handlers) {
		this.$$handleEvent=handlers[i];
		if(this.$$handleEvent(event)===false) {
			returnValue = false;
		}
	}
	return returnValue;
};

//Addsome"missing"methodsto IE's event object
function fixEvent(event) {
	// add W3C standardevent methods
	event.preventDefault = fixEvent.preventDefault;
	event.stopPropagation = fixEvent.stopPropagation;
	return event;
};

fixEvent.preventDefault = function() {
	this.returnValue = false;
};

fixEvent.stopPropagation = function() {
	this.cancelBubble = true;
};