<!-- By Dylan Wagstaff, http://www.alohatechsupport.net -->

var intRotation=""

function theRotator() {
	//Set the opacity of all images to 0
	$('div#rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 5000 = change to next image after 6 seconds
	intRotation=window.setInterval("rotate()",5000)
}

function rotate() {	
	//image
	var currentImage = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));
	var nextImage = ((currentImage.next().length) ? ((currentImage.next().hasClass('show')) ? $('div#rotator ul li:first') :currentImage.next()) : $('div#rotator ul li:first'));	
	//li
	var currentLI = ($('div#tabs ul li.selected')?  $('div#tabs ul li.selected') : $('div#tabs ul li:first'));
	var nextLI = ((currentLI.next().length) ? ((currentLI.next().hasClass('selected')) ? $('div#tabs ul li:first') :currentLI.next()) : $('div#tabs ul li:first'));

	//Set the fade in effect for the next image, the show class has higher z-index
	nextImage.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	currentImage.animate({opacity: 0.0}, 1000)
	.removeClass('show');

	nextLI.addClass('selected');
	currentLI.removeClass('selected');
};

$(document).ready(function() {		
	//Load the slideshow
//	theRotator();
	
	$("#tabs a").click(function () {
		//Get the first image
		var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));
		
		//trouve le bon lien par rapport au title
		var _a = $(this).attr('id');
		_a = _a -1;
		
		var next = $('#rotator').find('li').eq(_a)

		//Set the fade in effect for the next image, the show class has higher z-index
		next.css({opacity: 0.0})
		.addClass('show')
		.animate({opacity: 1.0}, 1000);
	
		//Hide the current image
		current.animate({opacity: 0.0}, 1000)
		.removeClass('show');
		
		//remet l'interval
		/*window.clearInterval(intRotation)
      	intRotation=""
		intRotation=window.setInterval("rotate()",5000)*/
	});

	$("#tabs li").click(function () {
			//enleve la class a tous les li								  
			$('div#tabs ul li').removeClass('selected')
			//ajoute la class au li sur lequel on a cliquer
			$(this).addClass('selected');			
			
			//remet l'interval
			/*window.clearInterval(intRotation)
      		intRotation=""
			intRotation=window.setInterval("rotate()",5000)*/
	});

});



