var current = 0;
var buttons = new Array();

$(document).ready(function(){
	
	$("#featuredImage .feature").each(function(){
		var img = $(this).find("img:first");
		var con = $(this).find("div:first");
		var toLeft = 528 - ($(con).width() + 60);
		toLeft = 528 - 168;
		$(con).css("display","block");
		$(this).css("background-image", "url("+$(img).attr("src")+")");
		$(this).hover(
			function(){
				$(img).fadeOut("normal");
			},
			function(){
				$(img).fadeIn("normal");
			}
		);
	});
	
	
	
	$("a[rel='external']").each(function(){
		$(this).attr("target","_blank");
	});
	
	$("#featuredNav a.featuredItem").each(function(x){
		buttons.push(this);
		$(this).attr("num",x);
		
		$(this).click(function(){
			showNew(this);
			return false;
		});
		
	});
	
	$("#featureBack").click(function(){
		var new_num = current - 1;
		if(new_num < 0) new_num = buttons.length - 1;
		$(buttons[new_num]).click();
		return false;
	});
	$("#featureNext").click(function(){
		var new_num = current + 1;
		if(new_num >= buttons.length) new_num = 0;
		$(buttons[new_num]).click();
		return false;
	});
	
	setTimeout("showNew(buttons[0])", 1000);
	
	$("#fancy").hover(
		function(){
			$("#sharp").animate({
				backgroundPosition: "(0 15px)"
			},"normal");
			$("#blur").animate({
				backgroundPosition: "(0 -16px)"
			},"normal");
		},
		function(){
			$("#sharp").animate({
				backgroundPosition: "(0 0)"
			},"normal");
			$("#blur").animate({
				backgroundPosition: "(0 -31px)"
			},"normal");
		}
	);
	
	$("#fancys").hover(
		function(){
			$("#sharp").animate({
				backgroundPosition: "(0 16px)",
				height: "15px"
			},"normal");
			$("#blur").animate({
				backgroundPosition: "(0 0)",
				marginTop: "16px"
			},"normal");
			$("#line").animate({
				marginTop: "7px"
			},"normal");
		},
		function(){
			$("#sharp").animate({
				backgroundPosition: "(0 0)",
				height: "31px"
			},"normal");
			$("#blur").animate({
				backgroundPosition: "(0 -31px)",
				marginTop: "31px"
			},"normal");
			$("#line").animate({
				marginTop: "22px"
			},"normal");
		}
	);
	
});


function showNew(clicked) {
	
	$("#featuredNav a.active").removeClass("active");
	
	$(clicked).addClass("active");
	
	$("#featuredImage .feature").each(function(x){
		if(x.toString() == $(clicked).attr("num")) {
			//$(this).addClass("active");
			$(this).find("img:first").hide();
			$(this).fadeIn(500);
			$(this).find("img:first").delay(500).fadeIn("slow");
		} else {
			//$(this).removeClass("active");
			$(this).fadeOut(500);
		}
		
	});
	current = Number($(clicked).attr("num"));
	
}