$(document).ready(function() {


	$(".folio_block").each(function() {
	
		//Set Default State of each portfolio piece
		$(this).find(".main_view").show(450);
		$(this).find(".paging").show(700);
		$(this).find(".desc").show(700);
		$(this).find(".paging a:first").addClass("active");
		$("div.desc_txt").find(".txt1").css("display","block");
	
	});	

	//Pagin events
	$(".paging a").click(function() {
	
		var triggerID = $(this).attr("rel") - 1;
		var imgHeight = $("div.window > .image_reel").find("img").height();
		var image_reelPosition = triggerID * imgHeight;
		var triggerID1 = triggerID + 1;
		
		//Ignore if Active
		if ( $(this).hasClass("active")) { 
			//Do Nothing
		}
		else {
			$("div.desc_txt").find(".txt1").css("display","none");
			$("div.desc_txt").find(".txt2").css("display","none");
			$("div.desc_txt").find(".txt3").css("display","none");
			$("div.desc_txt").find(".txt4").css("display","none");
			$("div.desc_txt").find(".txt5").css("display","none");
			$("div.desc_txt").find(".txt6").css("display","none");
			$("div.desc_txt").find(".txt7").css("display","none");
			$("div.desc_txt").find(".txt8").css("display","none");
			$("div.desc_txt").find(".txt9").css("display","none");
			$("div.desc_txt").find(".txt"+triggerID1).css("display","block");
			//Set active paging
			$("div.window").find(".paging a").removeClass("active");
			$(this).addClass("active");

			//image_reel Image
			$("div.window > .image_reel").animate({
				top: -image_reelPosition
			}, 350 );
		}
		return false;
	});
	
	var timer = setInterval( showDiv, 5000);
	function showDiv() {
   		var triggerID = $(".paging a.active").attr("rel");
		
		if(triggerID==9) triggerID=0;
		var imgHeight = $("div.window > .image_reel").find("img").height();
		var image_reelPosition = triggerID * imgHeight;

			$("div.desc_txt").find(".txt1").css("display","none");
			$("div.desc_txt").find(".txt2").css("display","none");
			$("div.desc_txt").find(".txt3").css("display","none");
			$("div.desc_txt").find(".txt4").css("display","none");
			$("div.desc_txt").find(".txt5").css("display","none");
			$("div.desc_txt").find(".txt6").css("display","none");
			$("div.desc_txt").find(".txt7").css("display","none");
			$("div.desc_txt").find(".txt8").css("display","none");
			$("div.desc_txt").find(".txt9").css("display","none");
			var a = parseInt(triggerID);
			a=a+1;
			$("div.desc_txt").find(".txt"+a).css("display","block");
			//Set active paging
			$("div.window").find(".paging a").removeClass("active");
			if(a==1) $("#n1").addClass("active");
			if(a==2) $("#n2").addClass("active");
			if(a==3) $("#n3").addClass("active");
			if(a==4) $("#n4").addClass("active");
			if(a==5) $("#n5").addClass("active");
			if(a==6) $("#n6").addClass("active");
			if(a==7) $("#n7").addClass("active");
			if(a==8) $("#n8").addClass("active");
			if(a==9) $("#n9").addClass("active");
			//image_reel Image
			$("div.window > .image_reel").animate({
				top: -image_reelPosition
			}, 350 );
		

  }

});
