/*
 *
 * DOMComplete - Load Event
 *
 * Author: Diego Perini (diego.perini@gmail.com)
 * Updated: 28/06/2007
 * Version: 0.99.8
 *
 */

function onDOMComplete(w, f) {
	var d = w.document, done = false;
	wait();

	if ((/WebKit|KHTML|MSIE/i).test(navigator.userAgent)) {
		poll();
	}

	function load(e) {
		if (!done) {
			done = true; stop(); f(e);
		}
	}

	function has(p) { return typeof d[p] != 'undefined'; }

	function poll() {
		if (d.body !== null && d.getElementsByTagName) {
			// please see http://javascript.nwbox.com/IEContentLoaded/ for the IE improvement part of DOMComplete
			if (has('fileSize')) { try { d.documentElement.doScroll('left'); load('documentready'); } catch (e) { } }
			if (has('readyState') && (/loaded|complete/).test(d.readyState)) { load('readyState'); }
		}
		if (!done) { setTimeout(poll, 10); }
	}

	function stop() {
		if (typeof d.removeEventListener == 'function') {
			d.removeEventListener('DOMContentLoaded', load, false);
		}
	}

	function wait() {
		if (typeof d.addEventListener == 'function') {
			d.addEventListener('DOMContentLoaded', load, false);
		}
		var oldonload = w.onload;
		w.onload = function (e) {
			if (typeof oldonload == 'function') {
				oldonload();
			}
			load(e || this.event);
		};
	}
}

