$(document).ready(function(){

	$("a[rel=external]").each(function(){ $(this).attr("target", "_blank"); });

	//setup the slideshow vars
	$(".lg_img img:first").css("display", "block");
	$active_index = 0;
	$ss_paused = false;
	$num_images = $(".lg_img img").size();
	$timer = setTimeout("portSlideShow()", 8000);
	
	//setup pause btn
	$("#pause").click(function(e){
		e.preventDefault();
		
		if($ss_paused == false)
		{
			$("#pause").text("PLAY");
			$ss_paused = true;
		}
		else
		{
			$("#pause").text("PAUSE");
			$ss_paused = false;
		}
	});
	
	//setup the page number clicks
	$(".pages a").click(function(e){
		e.preventDefault();
		
		clearTimeout($timer);
		
		$(".pages a.active").removeClass("active");
		$(".pages a").each(function(){ $(this).css("color", "#fff"); });
		
		$(this).addClass("active");
		$url = $(this).attr("href");
		$fade_out = $active_index;
		$fade_in = Number($url.substring($url.length - 1, $url.length)) - 1;
		doTransition($fade_out, $fade_in, true);
	});
	
}); //end ready


//slideshow animation function
function portSlideShow(){

	if($ss_paused){
		$timer = setTimeout("portSlideShow()", 8000);
		return;
	}
	
	$fade_out = $active_index;
	$fade_in = (($fade_out == ($num_images - 1))? 0 : ($fade_out + 1));

	doTransition($fade_out, $fade_in);

}//end featuredSlideShow



function doTransition(fade_out, fade_in, to_pause)
{

	$(".lg_img img").eq(fade_out).fadeOut(1000, function(){
		$(".lg_img img").eq(fade_in).fadeIn(1000, function(){
			$active_index = fade_in;
			$timer = setTimeout("portSlideShow()", 8000);
			if(to_pause == true)
			{
				$("#pause").text("PLAY");
				$ss_paused = true;
			}
		});
	});
	
	$(".pages a.active").animate({color: "#fff"}, 1000, 'linear', function(){
		$(".pages a").removeClass("active");
		$(".pages a").eq(fade_in).animate({color: "#d3ff24"}, 1000, 'linear', function(){
			$(this).addClass("active");
		});
	});
	
}//end function doTransition