$(document).ready(function(){
	ItemEdges();
	pictureLinks();
	//setupSwitcher();
});

function ItemEdges() {
	$(".edge-slant li").hover(
		function() {
			$(this).prev().addClass("hover-right");
			$(this).next().addClass("hover-left");
		},
		function() {
			$(this).prev().removeClass("hover-right");
			$(this).next().removeClass("hover-left");
			$(this).prev().removeClass("active-right");
			$(this).next().removeClass("active-left");
		}
	);
	$(".edge-slant li").mousedown(function() {
		$(this).prev().removeClass("hover-right");
		$(this).next().removeClass("hover-left");
		$(this).prev().addClass("active-right");
		$(this).next().addClass("active-left");
	});
	$(".edge-slant li").mouseup(function() {
		$(this).prev().removeClass("active-right");
		$(this).next().removeClass("active-left");
		$(this).prev().addClass("hover-right");
		$(this).next().addClass("hover-left");
	});
}

function pictureLinks() {
	$("p a img").parent().addClass("picture-link");
}

var switcher_timer;
var switcher_timeout = 5000;
var activeClass = "active";

function setupSwitcher() {
	var buttons = $("#featuredPosts .switcher li");
	buttons.each(function(){
		var ref = $(this).find("a").attr("href");
		$(ref).hide();
		$(this).find("a").click(function(){
			var next = $(this);
			if (!next.hasClass(activeClass)) {
				ref = $(this).attr("href");
				$(".featuredPost.active").find("img").fadeOut(function(){
					$(ref).find("img").fadeIn();
					$(".featuredPost.active").hide().removeClass(activeClass);
					buttons.find("a.active").removeClass(activeClass);
					$(ref).show().addClass(activeClass);
					next.addClass(activeClass);
				});
			}
			clearTimeout(switcher_timer);
			return false;
		});
	});
	buttons.first().find("a").addClass(activeClass);
	ref = buttons.first().find("a").attr("href");
	$(ref).find("img").fadeIn();
	$(ref).show().addClass(activeClass);
	switcher_timer = setTimeout("nextSwitcher()", switcher_timeout);
}

function nextSwitcher() {
	var is_last = $("#featuredPosts .switcher li:last a").hasClass(activeClass);
	if(is_last){
		$("#featuredPosts .switcher li:first").find("a").click();
	} else {
		$("#featuredPosts .switcher li:has(a.active)").next().find("a").click();
	}
	switcher_timer = setTimeout("nextSwitcher()", switcher_timeout);
}

