/*
 *
 * DOMComplete - Load Event
 *
 * Author: Diego Perini (diego.perini@gmail.com)
 * Updated: 06/08/2006
 * Version: 0.99.6-mini
 *
 */

/*
	This function is used to cause a function to load after the DOM
	has been loaded, but before binary files load. This will keep
	things like images, ads, etc slowing down the execution of your
	js
*/
function onDOMComplete(w, f) {
	var d = w.document, done = false;
	w.$DOMC = f;
	wait();

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

	function load(e) {
		if (!done) {
			done = true; stop(); w.$DOMC(e);
		}
	}

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

	function poll() {
		if (d.body !== null && d.getElementsByTagName) {
			if (has('fileSize') && typeof d.fileSize != 'unknown') { load('fileSize'); }
			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);
		};
	}
}
