$(document).ready(function(){
	
	//add outerHTML() to jquery
	jQuery.fn.outerHTML = function() {
		return $('<div>').append( this.eq(0).clone() ).html();
	};
	
	//setup menu behaviors
	$("#nav li a").each(function(){
		var speed = 150;
		$(this).mouseover(function(){
			$(this).animate({width: "+=100px"}, speed);
		});
		$(this).mouseout(function(){
			$(this).animate({width: "-=100px"}, speed);
		});
	});
	
	//external windows
	$("a[rel=prelaunch]").each(function(){
		$(this).click(function(e){
			e.preventDefault();
			preLaunch();
		});
	});
	
	//1-page blog
	$("a.blog_link").click(function(e){
		e.preventDefault();
		$url = $(this).attr("href");
		$id = $url.substring($url.lastIndexOf("/")+1, $url.indexOf("-"));
		window.location.href = "/blog?id=" + $id;
	});
	
	//setup the slideshow vars
	$(".proj:first").css("display", "block");
	$(".ss_more").children("a").attr("href", $(".proj:first").children("a").attr("href"));
	$active_proj = 0;
	$ss_paused = false;
	$proj_size = $(".proj").size();
	$timer = setTimeout("featuredSlideShow()", 10000);
	
	//setup pause btn
	$(".pause_btn").mouseover(function(){
		$(this).prev(".pause").children(".pause_r").animate({width: "70px"}, 100);
	});
	$(".pause_btn").mouseout(function(){
		$(this).prev(".pause").children(".pause_r").animate({width: "3px"}, 100);
	});
	$(".pause_btn").click(function(){
		if($ss_paused == false)
		{
			$(".pause").addClass("paused");
			$ss_paused = true;
		}
		else
		{
			$(".pause").removeClass("paused");
			$ss_paused = false;
		}
	});
	
}); //end ready


//slideshow animation function
function featuredSlideShow(){

	if($ss_paused){
		$timer = setTimeout("featuredSlideShow()", 10000);
		return;
	}
	
	$fade_out = $active_proj;
	$fade_in = (($fade_out == ($proj_size - 1))? 0 : ($fade_out + 1));
	
	$(".proj").eq($fade_out).fadeOut(1000, function(){
		$(".proj").eq($fade_in).fadeIn(1000, function(){
			$(".ss_more").children("a").attr("href", $(this).children("a").attr("href"));
			$active_proj = $fade_in;
			$timer = setTimeout("featuredSlideShow()", 10000);
		});
	});
	
}//end featuredSlideShow

function preLaunch(){
	alert("This project will be launching soon\nbut isn't publicly viewable yet");
}//end function preLaunch
