/*
 * portions combined from the following by Brian Moelk:
 *
 * onDOMReady: http://ryanmorr.com/archives/ondomready-no-browser-sniffing
 * Copyright (c) 2009 Ryan Morr (ryanmorr.com)
 * Licensed under the MIT license.
 *
 * FastInit: http://tetlaw.id.au/view/javascript/fastinit
 * Copyright (c) 2007 Andrew Tetlaw
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 */

var onDomReady = {
	add: function() {
		var a = arguments;
		for(var x = 0, al = a.length; x < al; x++) {
			if(typeof a[x] === 'function') {
				if (onDomReady.done ) {
					a[x]();
				} else {
					onDomReady.f.push(a[x]);
				}
			}
		}
	},
	fire: function() {
		if(!onDomReady.done){
			onDomReady.done = true;
			for(var x = 0, al = onDomReady.f.length; x < al; x++) {
				onDomReady.f[x]();
			}
			//Clean up after the DOM is ready
			if(document.removeEventListener)
				document.removeEventListener("DOMContentLoaded", onDomReady.respond, false);
			document.onreadystatechange = null;
			window.onload = null;
			clearInterval(onDomReady.timer);
			onDomReady.timer = null;
		}
	},
	respond: function(e) {
		//Mozilla & Opera
		if(e && e.type == "DOMContentLoaded"){
			onDomReady.fire();
		//Legacy	
		}else if(e && e.type == "load"){
			onDomReady.fire();
		//Safari & IE
		}else if(document.readyState){
			if((/loaded|complete/).test(document.readyState)){
				onDomReady.fire();
			//IE, courtesy of Diego Perini (http://javascript.nwbox.com/IEContentLoaded/)
			}else if(!!document.documentElement.doScroll){
				try{
					onDomReady.done || document.documentElement.doScroll('left');
				}catch(e){
					return;
				}
				onDomReady.fire();
			}
		}
	},
	init: function() {
		//Mozilla & Opera
		if(document.addEventListener)
			document.addEventListener("DOMContentLoaded", onDomReady.respond, false);
		//IE
		document.onreadystatechange = onDomReady.respond;
		//Safari & IE
		onDomReady.timer = setInterval(onDomReady.respond, 5);
		//Legacy
		window.onload = onDomReady.respond;
	},
	f:[],done:false,timer:null
};
onDomReady.init();
