// JavaScript Document
var currentSet = 1;
var currentTriptych = 1;
var totalSets = 12;

 $(document).ready(function(){
  	$(".triptychThumbnailContainer, .triptychImageContainer").click(function(event){
						
		var newTriptych;
		newTriptych = parseInt(($(this).attr("id").substr($(this).attr("id").length-1)));
	
		showTriptych(newTriptych);
	});
	
	
  
	$("#nextTriptychSet").click(function(event){
		//hide the current set
		
		//show the new set
		
		if (currentSet != totalSets){
			$("#triptychSetThumbnailContainer_" + currentSet.toString()).hide();
			$("#triptychImagesContainer_"  + currentSet.toString()).hide();
			
			currentSet++;
			
			$("#triptychSetThumbnailContainer_"  + (currentSet).toString()).show();
			$("#triptychImagesContainer_"  + (currentSet).toString()).show();
		
			currentTriptych = 1;
			newLeft = 60 - ((currentTriptych-1) * 600);
		
			$("#triptychImagesContainer_" + currentSet.toString()).animate({ left: newLeft}, 500 );
			$(".triptychThumbnailContainer").find(".thumbnail").removeClass("selected");
			$("#triptychThumbnail_"  + currentSet.toString() + "_" + currentTriptych.toString()).find(".thumbnail").addClass("selected");
		
			$("#currentSet").html(currentSet.toString());
			disablePreviousNext();
		}


   }); 
 
   $("#previousTriptychSet").click(function(event){
		//hide the current set
		
		//show the new set
		if (currentSet != 1)
		{
			
			$("#triptychSetThumbnailContainer_" + currentSet.toString()).hide();
			$("#triptychImagesContainer_"  + currentSet.toString()).hide();
			
			currentSet--;
			
			$("#triptychSetThumbnailContainer_"  + (currentSet).toString()).show();
			$("#triptychImagesContainer_"  + (currentSet).toString()).show();
		
			currentTriptych = 1;
			newLeft = 60 - ((currentTriptych-1) * 600);
		
			$("#triptychImagesContainer_" + currentSet.toString()).animate({ left: newLeft}, 500 );
			$(".triptychThumbnailContainer").find(".thumbnail").removeClass("selected");
			$("#triptychThumbnail_"  + currentSet.toString() + "_" + currentTriptych.toString()).find(".thumbnail").addClass("selected");
		
			$("#currentSet").html(currentSet.toString());
			disablePreviousNext();
		}
   }); 
   
   
   
 });
 
 function showTriptych(newTriptych)
 {
		$("#triptychThumbnail_" + currentSet.toString() + "_" + currentTriptych.toString()).find(".thumbnail").removeClass("selected");
		$("#triptychImageContainer_" + currentSet.toString() + "_" + currentTriptych.toString()).removeClass("selected");
		
		
		currentTriptych = newTriptych;
		$("#triptychThumbnail_" + currentSet.toString() + "_" + currentTriptych.toString()).find(".thumbnail").addClass("selected");
		$("#triptychImageContainer_" + currentSet.toString() + "_" + currentTriptych.toString()).addClass("selected");
		
		newLeft = 60 - ((currentTriptych-1) * 600);
		//$("#triptychImagesContainer_1").animate({ left: newLeft}, 500 );
		$("#triptychImagesContainer_" + currentSet.toString()).animate({ left: newLeft}, 500 );
	 
 }
 
 function disablePreviousNext()
 {
 	if (currentSet == 1)
	{
		$("#previousTriptychSet").addClass("disabled");
	}
	else{
		$("#previousTriptychSet").removeClass("disabled");
	}
	
 	if (currentSet == totalSets)
	{
		$("#nextTriptychSet").addClass("disabled");
	}
	else{
		$("#nextTriptychSet").removeClass("disabled");
	}
}
