var currentProduct = 0;
var slideDirection = "right";

function init() {

	$("#gallery-container .gallery-list li a").click(function() {
		$("#gallery-container .gallery-list li a").removeClass("active");
		$(this).addClass("active");
		$('#rotation-list').hide().load('product.html #' + $(this).attr("rel") + ' li').fadeIn("slow");
		
		/* This code is for the gallery and carousel to work together for rotation */
		currentProduct = $("#gallery-container .gallery-list li a").index($(this));
	});
	
	$($("#gallery-container .gallery-list li a")[currentProduct]).click();
	
	$("#next").click(function() {
		slideDirection = "right";
		currentProduct++;
		if (currentProduct >= $("#gallery-container .gallery-list li a").length) {
			currentProduct = 0;
		}
		$($("#gallery-container .gallery-list li a")[currentProduct]).click();
	});
	
	$("#previous").click(function() {
		slideDirection = "left";
		currentProduct--;
		if (currentProduct <= -1) {
			currentProduct = $("#gallery-container .gallery-list li a").length - 1;
		}
		$($("#gallery-container .gallery-list li a")[currentProduct]).click();
	});
	
	

}

$(window).load(init);
