/* Sets up jCarouselLight and provides helper functions to handle clicked images, as well as buttons Next and Previous */
var img_index = 0;
var array_of_images;
	
function setupCarousel() {
	img_index = 0;
	array_of_images = $("#jCarouselLite ul li img");
	
	// Setup carousel
	$("#divImages #jCarouselLite").jCarouselLite({
            btnNext: "#divNext", btnPrev: "#divPrev", speed: 800, visible: 4, scroll: 4, easing: "backout" //easeinout, backout
	});
        
	// Handle thumbnail clicks
	$("#jCarouselLite img").click(function() {
		var parent = $(this); // the thumbnail image
		// fade out
		$('#myimg').animate({opacity: 0.10}, 400, function() {		
			//$("#divImages .mid img").attr("src", parent.attr("src")); // change image                        
                        var img_path = $("#"+parent.attr("name")).attr("value"); // change image  
                        $("#divImages .mid img").attr("src", img_path); // change image
			$('#myimg').animate({opacity: 1}, 600, function() {}); // fade in
			setImageIndexToCurrentImage(parent);
		});
	});
	// Handle Next clicks 
        /*
	$("#divNext").click(function() {
            
		$('#myimg').animate({opacity: 0.10}, 400, function() {	
			incrementImageIndex();
			$("#divImages .mid img").attr("src", getNextImage()); // change image
			$('#myimg').animate({opacity: 1}, 600, function() {}); // fade in		
		});
	});

	// Handle Previous clicks
	$("#divPrev").click(function() {
		$('#myimg').animate({opacity: 0.10}, 400, function() {	
			decrementImageIndex();
			$("#divImages .mid img").attr("src", getNextImage()); // change image
			$('#myimg').animate({opacity: 1}, 600, function() {}); // fade in		
		});
	});
        */
}

function getNextImage() {
	return array_of_images.get(img_index).src;
}
function incrementImageIndex() {
	if (img_index >= array_of_images.size() - 1) img_index = 0;
	else img_index++;
}
function decrementImageIndex() {
	if (img_index <= 0) img_index = array_of_images.size() - 1;
	else img_index--;
}
function setImageIndexToCurrentImage(img) {
	img_index = array_of_images.index(img);
}
