var offset;
var containerWidth;
var animationDuration = 700;

if ($(window).height() > 1000)
	animationDuration = 1000;
else if ($(window).height() > 800)
	animationDuration = 800;
else
	animationDuration = 600;

var init = 0;

contentResize = function () {
	result = true;
	
	if (init == 0) {
		$("#multi_content").css({ opacity: 0 });	
		init = 1;
	}

	$("#multi_content").height($(window).height());
	
	containerWidth = Math.round(($(window).width() - 2) / 3) * 3;
	offset = ((containerWidth /3 / 2) - ($("#multi_content .tri_bg").width() / 2));
	
	$("#multi_content").css({ width: containerWidth + 2 });
		
	// $("#multi_content li").css({ position: "absolute" });
	$("#multi_content li, #multi_content li > a").width(containerWidth / 3);
	
	/*
	$("#multi_content li:eq(0)").css({ left: 0 }).find("img").css({ left: offset });
	$("#multi_content li:eq(1)").css({ left: (containerWidth / 3) }).find("img").css({ left: offset });
	$("#multi_content li:eq(2)").css({ right: 0 }).find("img").css({ right: offset });
	*/

	// Align Images
	$("#multi_content img").each(function() {
		if ($(this).get(0).complete === false)
			result = false;
		else
			$(this).css({ left: ((containerWidth /3 / 2) - ($(this).width() / 2)) });
	});
	
	// Align Category Titles
	//$("#multi_content li").find("h2").each(function() {
	//	$(this).css({ left: "50%", "margin-left": (0 - ($(this).width() / 2)) });
	//});
	
	if ((init == 1) && result) {
		$("#multi_content").animate({ opacity: 1 }, 750);
		init = 2;
	}
	
	return result;
}

$(document).ready(function(){
	jQuery.easing.def = "swing";
});

var starttime = new Date();
var timeout = 60;
var flag = false;
try {
	if ($.type(contentResize) ===  "function")
		flag = true;
}

catch (ex) {}

if (flag)
	var load_timer = window.setInterval(function() {
		var curtime = new Date();
		if (contentResize() || (curtime - starttime > timeout * 1000)) {
			window.clearInterval(load_timer);
			load_timer = null;
		}
	}, 200);

$(document).ready(function() {
	$(".wp-post-image").removeAttr("height").removeAttr("width");
	$(window).resize(function() {
		if (flag)
			contentResize();
	});

	$(window).bind("orientationchange", function(e) {
		if (flag)
			contentResize();
	});
	
	$("#multi_content li").hover(function() {
		$("#multi_content li").not(this).fadeTo('fast', 0.5);
	}, function() {
		$("#multi_content li").fadeTo('fast', 1.0);
	});
});
