/*
 * pre-init file -> fired *quickly*, not waiting for all the other code to execute (like the init.js file is)
 * Useful for eg the body class 'js-On', which hides elements using css-rules when JS is enabled
 * 
 * this file is -NOT- meant for general scripts, use init.js instead
 * only fast-executed pre-DOM-change-shizzle may be placed here
 */

// add 'js-On'-className to our body
document.body.className += (document.body.className.length > 0) ? " js-On" : "js-On";

// this is a console.log/~.time/~.timeEnd for browser without console.log, like IE
if((document.location.hostname.search(/.local/) != -1) && (typeof(console) == "undefined")) {
	var logel, logWindowExists = false;
	function buildLogWindow() {
		logEl = document.createElement("textarea");
		document.body.appendChild(logEl);
		logEl.style.position = "absolute";
		logEl.style.top = "0";
		logEl.style.right = "0";
		logEl.style.width = "300px";
		logEl.style.height = "250px";
		logEl.style.zIndex = "999";

		logWindowExists = !logWindowExists;
	}

	var console = {
		log : function () {
			if(!logWindowExists) buildLogWindow();
			for (var i = 0; i < arguments.length; i++) {
				logEl.value += arguments[i];
				if(arguments[i+1]) logEl.value += ", ";
			}
			logEl.value += "\n";
		},

		timers : {},
		
		time : function (timerName) {
			this.timers[timerName] = new Date().getTime();
		},

		timeEnd : function (timerName, logMessage) {
			if(typeof(this.timers[timerName]) != "undefined") {
				var then = this.timers[timerName];
				var now = new Date().getTime();
				var diff = now - then;

				var logMessage = (logMessage) ? " -- " + logMessage : "";
				this.log(timerName + " : " + diff + "ms" + logMessage);
			}
		}
	}
}
