function init( f ) {
	// If the DOM is already loaded, execute the function right away
	if ( init.done ) return f();
	// If we've already added a function
	if ( init.timer ) {
	// Add it to the list of functions to execute
	init.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
	init.ready = [ f ];
	// Check to see if the DOM is ready as quickly as possible
	init.timer = setInterval( isDOMReady, 13 );
	}
}

// Checks to see if the DOM is ready for navigation
function isDOMReady() {
	// If we already figured out that the page is ready, ignore
	if ( init.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( init.timer );
		init.timer = null;

		// Execute all the functions that were waiting
		for ( var i = 0; i < init.ready.length; i++ )
			init.ready[i]();
			// Remember that we're now done
			init.ready = null;
			init.done = true;
		}
}

function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    obj.attachEvent( 'on'+type, obj[type+fn] );
  } else
    obj.addEventListener( type, fn, false );
}

function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, obj[type+fn] );
    obj[type+fn] = null;
  } else
    obj.removeEventListener( type, fn, false );
}

function stopBubble(e) {
	// If an event object is provided, then this is a non-IE browser
	if ( e && e.stopPropagation )
	// and therefore it supports the W3C stopPropagation() method
	e.stopPropagation();
	else
	// Otherwise, we need to use the Internet Explorer
	// way of cancelling event bubbling
	window.event.cancelBubble = true;
}

function stopDefault( e ) {
	// Prevent the default browser action (W3C)
	if ( e && e.preventDefault )
	e.preventDefault();
	// A shortcut for stoping the browser action in IE
	else
	window.event.returnValue = false;
	return false;
}


function hasClass(name,type) {
	var r = [];
	// Locate the class name (allows for multiple class names)
	var re = new RegExp("(^|\\s)" + name + "(\\s|$)");
	// Limit search by type, or look through all elements
	var e = document.getElementsByTagName(type || "*");
	for ( var j = 0; j < e.length; j++ )
	// If the element has the class, add it for return
	if ( re.test(e[j]) ) r.push( e[j] );
	// Return the list of matched elements
	return r;
}


function tag(name, elem) {
	// If the context element is not provided, search the whole document
	return (elem || document).getElementsByTagName(name);
}




