// script for handling switching between different VEs
$(document).ready(function() {
	//hide all the div directly (first level) in #VEImageRotator except the first one
	$("#VEImageRotator > div:gt(0)").addClass("hidden");
	$("#VEImageRotator hr.VEsSeparator").addClass("hidden");

	//count the number of VEs (meaning the number of direct div under VEImageRotator)
	var n_numVEs = $("#VEImageRotator  > div").size();

	//Display only the navigation necessary
	display(1);
	
	//for each click on a link in the Header (number and next)
	$('#VEsPromotionHeader a').click(function(event) {
		// switch image
		$('#VEImageRotator > div').addClass('hidden');	//hide all div in #VEImageRotator
		var $newImageId = $(this).attr('href');
		$newImageId = $newImageId.substring(1);
		$('#VEImageRotator-0' + $newImageId).removeClass('hidden');
		
		//change active number
		$('#VEsPromotionHeader li').removeClass('VEsPromotionNumberActiv');			//put all numbers as inactive
		$('#VENum-0' + $newImageId).addClass('VEsPromotionNumberActiv');			//activate the current number
	});
	
	//for each click on Previous
	$('#VEsPromotionHeader #VENum-previous a').click(function(event) {
		var $newImageId = $(this).attr('href');
		$newImageId = $newImageId.substring(1);
		$newImageId = parseInt($newImageId)-2;
		display($newImageId);
	});
		
	//for each click on Next
	$('#VEsPromotionHeader #VENum-next a').click(function(event) {
		var $newImageId = $(this).attr('href');
		$newImageId = $newImageId.substring(1);
		display($newImageId);
	});
	
	
	function  display(start){
		//Display only the navigation necessary
		$("#VEsPromotionNav li").addClass("hidden");		//hide all navigation
		end=parseInt(start)+3;
		for( i=start; i <= n_numVEs && i <end; i++){		//display the 3 next exhibits 1-2-3 if enough VEs
			$('#VENum-0' + i).removeClass('hidden');
		}
		next=parseInt(start)+2;
		if (n_numVEs > next){							//display next if still more exhibits
			$('#VENum-next').removeClass('hidden');	
		}
		if (start > 3){										//display previous if not the first item
			$('#VENum-previous').removeClass('hidden');	
		}
	}
});
