// JavaScript Document
$(document).ready(function(){
	$(".click").click(function () {
		// this is the dom element clicked
		var index = $(".click").index(this);
		var text = "#img" + (index + 1);
		var image = ".img" + (index + 1);
		var desc  = ".t" + (index + 1);
		

		//filter the images, hide element not clicked, fadeIn the clicked element
		$(".gallery:visible").css("display", "none").filter(image).css("display","block");
		$(".gallery:hidden").css("display", "none").filter(image).fadeIn("slow");
		
		$(".text:visible").css("display", "none").filter(desc).css("display","block");
		$(".text:hidden").css("display", "none").filter(desc).fadeIn("slow");
		
		//change font color of selected index		
		var cssSelect = {
		color:"#dff65f",
		}
		var cssNormal = {
		color:"#fff",
		}
		var cssP1 = {
		color:"#fff",
		} 
		var cssHover = {
		color:"#dff65f",
		}
		
		var projectSelect = {
		color:"#c35303",
		}
		var projectNormal = {
		color:"#777",
		}
		var projectP1 = {
		color:"#777",
		}
		
		 
		$("#feat > .click").css(cssNormal).filter(text).css(cssSelect);
		$("#feat > .p1").css(cssP1).filter(text).css(cssSelect);
		
		$("#list > .click").css(projectNormal).filter(text).css(projectSelect);
		$("#list > .p1").css(projectP1).filter(text).css(projectSelect);
		
	});

});

setInterval(function(){switchimg();}, 7000);

function switchimg() {
		// Determines the Number of Images to Cycle Through
		var max  = parseInt($(".click").find('li').length);
		// Finds the visible image and records its class number
		var temp = $('.click > li#on').attr('class');
		var num  = parseInt(temp.charAt(3));
		
		// Switches to the next image or jump to the start of the gallery
		if(num < max) {
			$( ".img" + (num + 1) ).trigger('click');
		}
		else if(num == max)
		{
			$( ".img" + (num - (max-1)) ).trigger('click');
		}
}