$(document).ready(function() {
	slidePortfolioIndex(5000, 365); //Set the delay between the autoslide, and the full width of the current items. 
	slidePortfolioCaption();
});
function slidePortfolioIndex($time, $full_image_width) {
	
	$addCustom = $(".index_port_item.current").length;
	if($addCustom == 0) {
		$(".index_port_item:first").addClass("current");
	}
	$totalPortfolio = ($(".index_port_item").length) - 1;
	$widthDivide = 530 - $full_image_width;
	$tileWidth = parseInt($widthDivide / $totalPortfolio);
	$caption_width = $full_image_width - 20;
	$caption_width = $caption_width + 'px';
	$full_image_width = $full_image_width + 'px';
	
	$(".index_port_item").css("width", $tileWidth);
	$(".index_port_item.current").css("width", $full_image_width);
	$(".caption").css({ width: $caption_width, opacity: 0 });
	
	if(typeof(isClicked) == 'undefined') {var isClicked = 0;}
	$(".index_port_item").click(function() {
		isClicked = 1;
		var classClicked = $(this).attr('class');
		if(classClicked !== 'index_port_item current') {
			$(".index_port_item.current").removeClass("current").addClass("prev").stop().animate({ width: $tileWidth }, 300);
			$(this).addClass("current").css("width", $tileWidth).stop().animate({ width: $full_image_width }, 400);
			$(".index_port_item.prev").removeClass("prev"); 
		}
	});
	
	if(typeof(isHovered) == 'undefined') {var isHovered = 0;}
		
	$(".index_port_item").hover(function() {
		isHovered = 1;
	}, function() {
		isHovered = 0;
	});
	
	setInterval(function() {		 
		if(isHovered == 0 && isClicked == 0) {
			nextPortfolioItem('365px', $tileWidth);
		}
	}, $time);
}

function nextPortfolioItem($full_image_width, $tile_width) {
	
	$current = $(".index_port_item.current");
	$next = $(".index_port_item.current").next();
	
	if($next.attr('class') == undefined) {
		$next = $(".index_port_item:first");
	} else {}
		
	$current.removeClass("current").css("width", $full_image_width).stop().animate({ width: $tile_width }, 300);
	$next.addClass("current").css("width", $tile_width).stop().animate({ width: $full_image_width }, 400);
	
}
function slidePortfolioCaption() {
	$(".index_port_item").children('a').hover(function() {
		$(this).parents().children('.caption').stop().animate({ opacity: 1 }, 300);
	}, function() {
		$(this).parents().children('.caption').stop().animate({ opacity: 0 }, 400);
	});
	
}
