/* 
	thanks to Dean Edwards, Simon Willison, and countless others.
	http://dean.edwards.name/weblog/2006/06/again/
	http://simon.incutio.com/archive/2004/05/26/addLoadEvent
*/
// allows multiple functions attached to the DOMContentLoaded event
// runs when the DOM is ready
// use this if your script does not require external objects such as images, flash, etc. to be loaded
if ( typeof( addInitEvent ) == "undefined" ) {
	function addInitEvent ( func ) {
		var oldInitHandler = window.initHandler;
		if( typeof window.initHandler != "function" ){
			window.initHandler = func;
		} else {
			window.initHandler = function() {
				oldInitHandler();
				func();
			}
		}
	}
}

// allows multiple functions attached to the window.onload event
// runs when the entire document and all external resources are loaded
// only use this if your scrript requires that the entire document, including external objects are loaded
if ( typeof( addLoadEvent ) == "undefined" ) {
	function addLoadEvent (func) {
		var oldonload = window.onload;
		if(typeof window.onload != "function"){
			window.onload = func;
		} else {
			window.onload = function() {
				oldonload();
				func();
			};
		}
	}
}

// runs scripting when the DOM is ready, instead of when the page is ready
function DOMContentLoadedHandler() {
    // quit if this function has already been called
    if (arguments.callee.done) return;

    // flag this function so we don't do the same thing twice
    arguments.callee.done = true;

    // kill the timer
    if (_timer) {
        clearInterval(_timer);
        _timer = null;
    }
	
	if ( window.initHandler ) {
		window.initHandler();
	}
};

/* for Mozilla/Opera9 */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", DOMContentLoadedHandler, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
	document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") {
			DOMContentLoadedHandler(); // call the onload handler
		}
	};
/*@end @*/

/* for Safari */
if ( navigator.appVersion.match( /Konqueror|Safari|KHTML/i ) ) { // sniff
//if (/WebKit/i.test(navigator.userAgent)) { 
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			init(); // call the onload handler
		}
	}, 10);
}

// for other browsers
addLoadEvent( DOMContentLoadedHandler );

