// JavaScript Document
jQuery(function($) {$(document).ready(function () {
	
	$("#home_slider .panel").hide();
	$("#home_slider .panel#1").show();
	
	nb_dis = 1;
	timer = 1;
	max_slid = $("#home_slider .panel").length;
		
	function aff_case(to_dis)
	{
		if (to_dis != nb_dis)
		{
			$("#home_slider .panel#" + nb_dis).fadeOut();
			$("#home_slider .navigation a[href$=" + nb_dis + ']').removeClass('active');
			$("#home_slider .panel#" + to_dis).fadeIn();	
			$("#home_slider .navigation a[href$=" + to_dis + "]").addClass('active');	
		}
		nb_dis = to_dis;
	};
	
	function next()
	{
		var to_dis = (parseInt(nb_dis) + 1);
		if (to_dis > max_slid)
			to_dis = 1;
		aff_case(to_dis);		
	};

	function prev()
	{
		var to_dis = (parseInt(nb_dis) - 1);
		if (to_dis <= 0)
			to_dis = max_slid;
		aff_case(to_dis);		
	};
	
	function play()
	{
		next();
		if (timer == 1)
			timer = window.setTimeout(function() { play(); }, 4500);
	}
	
	function pause()
	{
		timer = 0;
	};
	
	$('#home_slider .fleches a[title$=next]').live('click', function() {
		next();
		return false;
	});

	$('#home_slider .fleches a[title$=prev]').live('click', function() {
		prev();
		return false;
	});
	
	$('#home_slider .fleches a[title$=pause]').live('click', function() {
		pause();
		return false;
	});
	

	timer2 = '';

	$("#home_slider").hover(
		function () {
			clearTimeout(timer2);
			pause();
		},
		function () {
			timer2 = setTimeout(function() { play(); }, 4500);
		}
	);
	
	play();
	
	$('#home_slider .navigation a').live('click', function () {
		var to_display = $(this).attr('href').substr(1);
		pause();
		
		aff_case(to_display);
		return (false);
	});
		
});});
