if (!itdr) var itdr = new Object();
if (!itdr.classes) itdr.classes = new Object();
if (!itdr.classes.HorizontalBlog) itdr.classes.HorizontalBlog = new function () {

	/* ----  Public Methods ---- */

	this.invalidate = function () {
		reAlignWindow();
	};
	this.getHasScrolled = function () {
		if (!inited) return;
		var content = document.getElementById("content-wrapper");
		return content.offsetLeft!=0;
	};
	this.setupLoader = function (path, color, opacity) {
		loader_uri = path;
		loader_color = color;
		loader_alpha = opacity;
	};

	/* ---- Sizing Properties ---- */

	var _opt_scrollbar_height = 35;
	var _opt_entry_scrollbar_width = 15;
	var _opt_entry_body_width = 300;
	var _opt_entry_body_bottom_margin = 50;
	var _opt_entry_collection_margin = 25;
	var _opt_entry_collection_spacing = 5;

	/* ---- Private Properties ---- */

	var inited = false;
	var iproduct = navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i);
	var viewport = itdr.func.getBrowserDimensions();
	var headerRatio = 600/550;
	var loader_uri = "http://soundtrack2mylife.com/Blog/wp-content/themes/perilla/images/ajax-loader.gif";
	var loader_color = "#fff";
	var loader_alpha = 100;
	var maxheight = 550 + _opt_scrollbar_height + 1;
	var minheight = 300;
	var contentheight = viewport[1];

	/* ---- Singleton Constructor ---- */

	itdr.func.createCSS("#twitter-if-in-content", 'display:block;');
	itdr.func.createCSS(".Post", 'clear:none;');
	itdr.func.createCSS(".EntryContentBodyWrapper", 'position: absolute;margin:0;');
	itdr.func.createCSS("#content-loader", 'position:absolute;top:0;left:0;background: ' + loader_color + ' url("' + loader_uri + '") no-repeat 50%; height: ' + contentheight + 'px; width: 100%; opacity: ' + loader_alpha/100 + '; filter: alpha(opacity=' + loader_alpha + ');');
	itdr.func.createCSS("#content-wrapper", 'display:none;');
	itdr.func.DOMLoad(init);

	/* ---- Private Methods ---- */

	function reAlignWindow () {
		/* always update the viewport info
			*/
		viewport = itdr.func.getBrowserDimensions();
		var contentheight = viewport[1] - 0;
		/* declare important info
			*/
		var navigation = document.getElementById("navigation-inner");
		var footer = document.getElementById("footer");
		var wrapper = document.getElementById("wrapper");
		var content = document.getElementById("content-wrapper");
		var header = document.getElementById("header");
		var entries = itdr.func.getElementsByClassName("Post", "div", content);
		var uri = document.location.href;
		var filename = uri.split("/").pop();
		var showHeader = false;
		/* check minimums/maximums
			*/
		var navigationHeight = navigation.offsetHeight + _opt_scrollbar_height;
		if (navigationHeight>minheight) minheight = navigationHeight;
		if (contentheight>maxheight) contentheight = maxheight;
		if (contentheight<minheight) contentheight = minheight;
		contentheight = contentheight - _opt_scrollbar_height;
		/* vertically center the navigation
			*/
		navigation.style.position = "relative";
		navigation.style.top = Math.round((contentheight-navigation.offsetHeight)/2) + "px";
		/* determine if we should show the header or not
			*/
		if (entries.length>=1) { // a page with multiple entries, possible show header
			if (filename=="") showHeader = true; // this is going to be some default index, show the header
			else if (isNaN(parseInt(filename))) showHeader = true; // this is some other type of page that has entries, and is not a X.html
		}
		if (iproduct) {
		}
		/* the width is another matter.  let's resize everything and
			build up a width tally so we know how wide to set the content
			width.
			*/
		var contentwidth = 0;
		if (showHeader) {
			var headerHeight = contentheight-1;
			var headerWidth = Math.floor((headerRatio*headerHeight));
			header.style.height = headerHeight + 'px';
			header.style.width = headerWidth + 'px';
			/* resize the header image if no flash
				*/
			var headerimage = header.getElementsByTagName("img")[0];
			if (headerimage) {
				headerimage.style.height = headerHeight + 'px';
				headerimage.style.width = headerWidth + 'px';
			}
			contentwidth += headerWidth;
		}
		contentwidth += navigation.offsetWidth;
		/* loop through the entries, and set them up
			*/
		for (var i=0; i<entries.length; ++i) {
			var entry = entries[i];
			var entrycontentbodywrapper = itdr.func.getElementsByClassName("EntryContentBodyWrapper", "div", entry)[0];
			var contentbody = itdr.func.getElementsByClassName("EntryContentBody", "div", entry)[0];
			var titlecategory = itdr.func.getElementsByClassName("TitleCategory", "div", entry)[0];
			var comments = itdr.func.getElementsByClassName("InlineCommentsContainer", "div", entry)[0];
			var commentsblock = itdr.func.getElementsByClassName("PostMetaData", "div", entry)[0];
			var collection = itdr.func.getElementsByClassName("ImageCollection", "div", entry)[0];
			var endblock = titlecategory;
			// basics
			entry.style.height = (contentheight-1) + 'px';
			// move and size the text
			var entry_body_y = titlecategory.offsetTop + titlecategory.offsetHeight;
			var entry_body_height = contentheight - entry_body_y - _opt_entry_body_bottom_margin;
			titlecategory.style.width = _opt_entry_body_width + "px";
			entrycontentbodywrapper.style.top = entry_body_y;
			entrycontentbodywrapper.style.left = titlecategory.offsetLeft + "px";
			itdr.classes.ScrollPane.resize(contentbody, _opt_entry_body_width, entry_body_height);
			// size up all the images/objects in the collection
			if (collection) {
				var medialist = new Array();
				var objects = collection.getElementsByTagName("object");
				for (var j=0; j<objects.length; ++j) medialist.push(objects[j]);
				var embeds = collection.getElementsByTagName("embed");
				for (var j=0; j<embeds.length; ++j) {
					var embed = embeds[j];
					if (embed.parentNode.nodeName.toLowerCase()!="object") {
						medialist.push(embed);
					}
				}
				var images = collection.getElementsByTagName("img");
				for (var j=0; j<images.length; ++j) {
					if (images[j].className == "wp-smiley") continue;
					medialist.push(images[j]);
				}
				var tally = 0;
				var media_height = contentheight - titlecategory.offsetTop - _opt_entry_body_bottom_margin;
				for (var j=0; j<medialist.length; ++j) {
					var media = medialist[j];
					var embed = media.getElementsByTagName("embed")[0];
					var width = media.getAttribute("width");
					var height = media.getAttribute("height");
					var media_width = Math.round((width/height)*media_height);
					if (embed) {
						embed.setAttribute("height", media_height);
						embed.setAttribute("width", media_width);
					}
					media.setAttribute("height", media_height);
					media.setAttribute("width", media_width);
					media.style.left = tally + "px";
					tally += media_width + (j==medialist.length-1?0:_opt_entry_collection_spacing);
				}
				collection.style.top = endblock.offsetTop + "px";
				collection.style.left = endblock.offsetLeft + endblock.offsetWidth + _opt_entry_collection_margin + "px";
				collection.style.width = tally + "px";
				collection.style.height = media_height + "px";
				endblock = collection;
			}
			// comments
			if (commentsblock&&comments) {
				var commentsactions = itdr.func.getElementsByClassName("CommentsActions", "div", commentsblock)[0];
				commentsblock.style.overflow = "hidden";
				commentsblock.style.position = "absolute";
				commentsblock.style.top = endblock.offsetTop + "px";
				commentsblock.style.left = (endblock.offsetLeft + endblock.offsetWidth + _opt_entry_collection_margin) + "px";
				commentsblock.style.width = _opt_entry_body_width + "px";
				commentsblock.style.height = media_height + "px";
				var entry_comments_height = media_height - commentsactions.offsetTop - commentsactions.offsetHeight;
				itdr.classes.ScrollPane.resize(comments, _opt_entry_body_width, entry_comments_height);
				endblock = commentsblock;
			}
			/* add it up
				*/
			entry.style.width = (endblock.offsetLeft + endblock.offsetWidth) + "px";
			contentwidth += endblock.offsetLeft + endblock.offsetWidth + 61;
		}
		/* add the footer
			*/
		footer.style.width = _opt_entry_body_width + "px";
		footer.style.height = contentheight + "px";
		contentwidth += _opt_entry_body_width;
		/* we're done
			*/
		content.style.width = contentwidth + "px";
		content.style.height = contentheight + "px";
		if (!iproduct) itdr.classes.ScrollPane.resize(content, viewport[0], contentheight + _opt_scrollbar_height);
		else wrapper.style.width = contentwidth + "px";
	};

	function doPostJump () {
		var content = document.getElementById("content-wrapper");
		var scrollto;
		if (this.index==-1) {
			scrollto = 0;
		} else {
			var entries = itdr.func.getElementsByClassName("Post", "div", content);
			var entry = entries[this.index];
			scrollto = entry.offsetLeft * -1;
		}
		itdr.classes.ScrollPane.scrollTo(content, scrollto, true);
	};

	function init () {
		/* only run the init command once
			*/
		if (inited==true) return;
		inited = true;
		/* setup variables
			*/
		var showHeader = false;
		/* declare important info
			*/
		var footer = document.getElementById("footer");
		var wrapper = document.getElementById("wrapper");
		var content = document.getElementById("content-wrapper");
		var contentLoader = document.getElementById("content-loader");
		var entries = itdr.func.getElementsByClassName("Post", "div", content);
		var navigationContainer = document.getElementById("navigation-container");
		var uri = document.location.href;
		var filename = uri.split("/").pop();
		/* assign an event to window so we can listen for resize events
			*/
		window.onresize = reAlignWindow;
		/* determine if we should show the header or not
			*/
		if (entries.length>=1) { // a page with multiple entries, possible show header
			if (filename=="") showHeader = true; // this is going to be some default index, show the header
			else if (isNaN(parseInt(filename))) showHeader = true; // this is some other type of page that has entries, and is not a X.html
		}
		/* if it's an iproduct, no scrollbar needed, as they can just pan back and forth by dragging
			otherwise, setup the main scrollbar
			*/
		if (!iproduct) {
			itdr.classes.ScrollPane.initialize(content, {
				horizontal: true,
				thickness: _opt_scrollbar_height,
				minimum: 200,
				maximum: 300,
				id: "main-site-scroll"
			});
		}
		/* no one will ever use these, but add some nifty
			keyboard shortcuts
			*/
		document.onkeydown = function (e) {
			var evt = e || window.event;
			var code = evt.keyCode;
			var scrollto = content.offsetLeft;
			if (code==33) scrollto += viewport[0] - 100; // pageup
			else if (code==34) scrollto -= viewport[0] - 100; // pagedown
			else if (code==36) scrollto = 0; // home
			else if (code==35) scrollto = content.offsetWidth * -1; // end
			itdr.classes.ScrollPane.scrollTo(content, scrollto, true);
		};
		/* ok, turn the content back on, and turn off the loader
			*/
		content.style.display = "block";
		contentLoader.style.display = "none";
		/* if the header is not shown, turn that puppy off now
			*/
		if (showHeader==false) {
			var header = document.getElementById("header-container");
			header.style.display = "none";
		}
		/* now loop through all the entires, and set them up accordingly
			*/
		for (var i=0; i<entries.length; ++i) {
			var entry = entries[i];
			var entrycontentbodywrapper = itdr.func.getElementsByClassName("EntryContentBodyWrapper", "div", entry)[0];
			var entryid = entry.id.split("-").pop();
			var contentbody = itdr.func.getElementsByClassName("EntryContentBody", "div", entry)[0];
			var links = itdr.func.getElementsByClassName("Link", "a", entry);
			var comments = itdr.func.getElementsByClassName("InlineCommentsContainer", "div", entry)[0];
			var parent = contentbody.parentNode.parentNode;
			var collection = document.createElement('div');
			/* make sure an hide any overflow
				*/
			entry.style.borderRight = "1px #222222 solid";
			entry.style.borderBottom = "1px #222222 solid";
			entry.style.position = "relative";
			entry.style.overflow = "hidden";
			entrycontentbodywrapper.style.position = "absolute";
			for (var j=0; j<links.length; ++j) {
				var obj = links[j];
				obj.removeAttribute("href");
				obj.style.visibility = "visible";
			}
			/* create a container that we can stuff all our images + swfs, etc into
				*/
			collection.className = "ImageCollection";
			collection.style.overflow = "hidden";
			collection.style.position = "absolute";
			parent.appendChild(collection);
			/* move all images and objects into the collection
				*/
			var medialist = new Array();
			var objects = contentbody.getElementsByTagName("object");
			for (var j=0; j<objects.length; ++j) {
				var object = objects[j];
				var embed = object.getElementsByTagName("embed")[0];
				var params = object.getElementsByTagName("param");
				var haswmode = false;
				for (var k=0; k<params.length; ++k) {
					var param = params[k];
					var name = param.getAttribute("name");
					var value = param.getAttribute("value");
					if (name.toLowerCase()=="wmode") {
						haswmode = true;
						if (value=="window") param.setAttribute("value", "opaque");
					}
				}
				if (!haswmode) {
					var param = document.createElement('param');
					param.setAttribute("name", "wmode");
					param.setAttribute("value", "opaque");
					object.appendChild(param);
				}
				if (embed) {
					embed.setAttribute("wmode", "opaque");
				}
				medialist.push(object);
			}
			var embeds = contentbody.getElementsByTagName("embed");
			for (var j=0; j<embeds.length; ++j) {
				var embed = embeds[j];
				embed.setAttribute("wmode", "opaque");
				if (embed.parentNode.nodeName.toLowerCase()!="object") {
					medialist.push(embed);
				}
			}
			var images = contentbody.getElementsByTagName("img");
			for (var j=0; j<images.length; ++j) {
				if (images[j].className == "wp-smiley") continue;
				medialist.push(images[j]);
			}
			for (var j=0; j<medialist.length; ++j) {
				var media = medialist[j];
				media.style.display = "block";
				media.style.position = "absolute";
				media.style.top = "0px";
				collection.appendChild(media);
			}
			itdr.classes.ScrollPane.initialize(contentbody, {
				minimum: 30,
				thickness: _opt_entry_scrollbar_width,
				autohide: true
			});
			itdr.classes.ScrollPane.initialize(comments, {
				minimum: 30,
				thickness: _opt_entry_scrollbar_width,
				autohide: true
			});
		}
		/* some global styles
			*/
		content.style.overflow = "hidden";
		footer.style.overflow = "hidden";
		footer.style.clear = "none";
		wrapper.style.overflow = "hidden";
		wrapper.style.margin = "auto";
		wrapper.style.width = "auto";
		/* realign now, and do a 100 ms delay, just to ensure we get everything
			*/
		setTimeout(reAlignWindow, 300);
		reAlignWindow();
	};

};

function showComments(id){
	var entry = document.getElementById("Post-" + id);
	var inlinecomments = itdr.func.getElementsByClassName("InlineComments", "div", entry)[0];
	var inlinecommentform = itdr.func.getElementsByClassName("InlineCommentForm", "div", entry)[0];
	inlinecomments.style.display = "block";
	inlinecommentform.style.display = "none";
	itdr.classes.HorizontalBlog.invalidate();
}

function showCommentForm(id){
	var entry = document.getElementById("Post-" + id);
	var inlinecomments = itdr.func.getElementsByClassName("InlineComments", "div", entry)[0];
	var inlinecommentform = itdr.func.getElementsByClassName("InlineCommentForm", "div", entry)[0];
	inlinecomments.style.display = "none";
	inlinecommentform.style.display = "block";
	itdr.classes.HorizontalBlog.invalidate();
}
