/************************ Old ITDR Functions **********************/

if (!itdr) var itdr = new Object();
if (!itdr.func) itdr.func = {
	DOMLoad: function (func) {
		var readyStatus = { loaded: 1, complete: 1 };
		if (document.addEventListener) {// Gecko, Opera, WebKit r26101+
			document.addEventListener('DOMContentLoaded', func, false);
		} else if (!window.opera && document.readyState) { // Old WebKit, Internet Explorer
			(function() {
				readyStatus[document.readyState] ? func() : setTimeout(arguments.callee, 10);
			})();
		} else if (document.readyState && document.createStyleSheet) { // Internet Explorer
			(function() {
				try {
					document.body.doScroll('left');
					func();
				}
				catch (e) {
					setTimeout(arguments.callee, 1);
				}
			})();
		} else { // Fallback
			itdr.func.addEvent(window, 'load', func);
		}
	},
	/**
	 *
	 * createCSS
	 * this function is totally ripped from bobby vander sluis's UFO.  i *wanted* to use UFO, but
	 * there were issues with it, so i had to revert to SO unfortunatly, but needed this bit of code
	 * thanks bobby!
	 *
	 */
	createExternalLinks: function () {
		var links = document.getElementsByTagName('a');
		var mydomain = location.hostname.substr(0, 3)=="www" ? location.hostname.substr(4) : location.hostname;
		for (var i=0; i<links.length; ++i) {
			var link = links[i];
			var href = link.href;
			var absolute = /(http(.)*:\/\/)/;
			if (href!=null&&(href.match(mydomain)==null)&&href.match(absolute)!=null) link.target = "_blank";
		}
	}
};

// a little backwards compatibility
if (!thetainteractive) var thetainteractive = itdr;
if (!intothedarkroom) var intothedarkroom = itdr;

/************************ Cookie Functions **********************/

/**
 * Cookie singleton
 * comes in three flavors: set, get and kill -- pretty simple
 * i ripped most of the logic from www.quirksmode.org -- love that guy.
 */
if (!itdr.classes) itdr.classes = new Object();
if (!itdr.classes.Cookie) itdr.classes.Cookie = new function () {
	/**
	 *
	 * Cookie.set
	 * set a session cookie
	 *
	 * @param name		String -- the name of the cookie name-value pair
	 * @param value		String -- the value of the cookie name-value pair
	 * @param days		Number -- the value of the cookie name-value pair
	 *
	 */
	this.set = function(name, value, days) {
		var expires = "";
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			expires = "; expires="+date.toGMTString();
		}
		document.cookie = name+"="+value+expires+"; path=/";
	};
	/**
	 *
	 * Cookie.get
	 * get a previously saved session cookie
	 *
	 * @param name		String -- the name of the cookie name-value pair
	 * @return			String -- the value of the name-pair in the form a of a string
	 *						or empty string if no value present
	 *
	 */
	this.get = function(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0; i< ca.length; i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1, c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
		}
		return "";
	};
	/**
	 *
	 * Cookie.kill
	 * delete a previously saved session cookie
	 *
	 * @param name		String -- the name of the cookie name-value pair to delete
	 *
	 */
	this.kill = function(name) {
		this.set(name,"",-1)
	};
};

/************************ IE6Fail **********************/

if (!itdr.classes.IE6Fail) itdr.classes.IE6Fail = new function () {
	// private members
	var declined = itdr.classes.Cookie.get("ie6_notification_declined");
	var ie6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
	var inited = false;
	// private functions
	function init () {
		if (inited) return;
		inited = true;
		if (ie6&&declined=="") {
			var insert = "";
			insert += '<div style="filter:alpha(opacity=75);z-index:999999999;position:absolute;top:0px;left:0px;width:100%;background:#fff;">';
			insert += '<div style="border:3px #660000 solid;padding:15px;text-align:center;">';
			insert += '<span style="font-size:16px;color:#cc0000">You are not seeing this website as it should be seen because of your deprecated browser.</span>';
			insert += '<span><a style="font-size:16px;margin:0 10px 0 10px;font-weight:bold;color:#000000" href="http://blog.christinemarie-photography.com/wp-content/themes/epizote/IE6Fail/"">Learn More</a></span>';
			insert += '<span><a style="font-size:16px;color:#666666" href="javascript:itdr.classes.IE6Fail.cancel();">Don\'t show this message</a></span>';
			insert += '</div>';
			insert += '</div>';
			var message = document.createElement("div");
			message.id = "ie6_fail_message";
			message.innerHTML = insert;
			document.body.appendChild(message);
		}
	};
	// do everything on dom load
	itdr.func.DOMLoad(init);
	// public methods
	this.cancel = function (entry_id) {
		itdr.classes.Cookie.set("ie6_notification_declined", "1");
		var message = document.getElementById("ie6_fail_message");
		message.style.display = "none";
	};
};
