/*
 * Home controller
 * 
 * @package Impatients
 * @category Controllers
 * @author Frédéric Trudeau <ftrudeau@prospek.ca>
 * @copyright Copyright (c) 2009-2010 Prospek Inc. All rights reserved.
 */
	jQuery( function()
	{

		$(".navigation").show();

		////////////////
		// SLIDESHOW //
		//////////////
		
		var p = 1;
		var max_p = $(".btn_home_slideshow").length;
		var playslideshow = true;
		var time = 5500;
		var timerAuto;
		
		// Part avec l'animation automatique
		showNextSlide();
		
		//Lorsque l'on clique sur un bouton de la navigation
		$(".btn_home_slideshow").click
		(
			function ()
			{	
				clearTimeout(timerAuto);
				
				//Change current page value
				p = $(this).html();
				
				//Animate the slide
				animateSlide();
				
				//Si un bouton à été cliquer on attend puis on repart la fonction automatique
				playslideshow = false;
				
				timerAuto = setTimeout
				(
					function ()
					{
						playslideshow = true;
						showNextSlide();
					}, 
					time
				)
				
			}
		);

		//Fonction qui passe à la prochaine slide automatiquement
		function showNextSlide ()
		{
			setTimeout
			(
				function ()
				{
					if(playslideshow == true)
					{
						p++;
						
						if(p > max_p)
						{
							p = 1;
						}
						
						//Animate the slide
						animateSlide();						
						showNextSlide();
					}
					
				}, time 
			);
		}

		//Fonction qui anime le slideshow et donne au bouton courant une classe current
		function animateSlide ()
		{			
			$(".btn_home_slideshow").removeClass("current_slide");
			$(".btn_home_slideshow." + p).addClass("current_slide");
			
			if($.browser.msie && $.browser.version < 7){
				$(".slide").hide();
				$("#slide_" + p).show();
			}
			else
			{	
				$(".slide").fadeOut(750);
				$("#slide_" + p).fadeIn(750);
			}
	
		}
	
	});
