// Script encodé avec http://javascriptcompressor.com/
// avec l'option "Base62 encode"

var $$ = $.fn;

var settings = {
	'speed': 2000, // En milliseconde
	'delay': 6000, // En milliseconde
	'runningclass':     'innerfade',
	'children':         null
};

$$.extend({
	
	Slideshow : 
	{
		Ready : function()
		{
			$('div.tmpSlideshowControl')
			
			.hover(
				function() {
					$(this).addClass('tmpSlideshowControlOn');
				},
				function() {
					$(this).removeClass('tmpSlideshowControlOn');
				}
			)
			
			.click(
				function() {
					$$.Slideshow.Interrupted = false;
					
					clearTimeout(interval);
					
					// L'image en cours devient l'image précédente pour effectuer le fondu
					$$.Slideshow.Last = $("#courant").val();
					
					//alert($$.Slideshow.Last);
					var elem_id = $(this).attr('id');
					
					var temp = elem_id.split("-");
					
					// Récupération de l'index de l'image cliquée
					$$.Slideshow.Counter = temp[1];
					
					// Calcul du nombre d'image dans le diaporama !
					nb_image_total = $('div#portfolio').children().size();
					
					//alert('Nb images : ' + nb_image_total + '\nLast : ' + $$.Slideshow.Last + '\nCourant : ' + $$.Slideshow.Counter);

					$("#courant").val($$.Slideshow.Counter);
					$("#last").val($$.Slideshow.Last);
					
					//document.getElementById('courant').innerHTML = $$.Slideshow.Counter;
					//document.getElementById('last').innerHTML = $$.Slideshow.Last;
					
					$('div.tmpSlideshowControl').removeClass('tmpSlideshowControlActive');
					
					$('div#tmpSlide-' + $$.Slideshow.Last).fadeOut(settings.speed);
					
					$('div#tmpSlide-' + $$.Slideshow.Counter).fadeIn(settings.speed);

					$('div#tmpSlideshowNum-' + $$.Slideshow.Last).hide();
					$('div#tmpSlideshowNum-' + $$.Slideshow.Counter).show();
					
					var cpt_marge_G = $$.Slideshow.Counter - 1;
			
					$('div#tmpSlideshowNum-' + $$.Slideshow.Counter).css("margin-left", (cpt_marge_G * 13) + "px");
					
					$('div#tmpSlideshowControl-' + $$.Slideshow.Last).removeClass('tmpSlideshowControlActive');
					$('div#tmpSlideshowControl-' + $$.Slideshow.Counter).addClass('tmpSlideshowControlActive');

					if($$.Slideshow.Counter<5)
						$$.Slideshow.Counter++;
					else
						$$.Slideshow.Counter=1;
						
					interval = setTimeout('$$.Slideshow.Transition();', settings.delay);
				}
			);

			this.Counter = 1;
			this.Interrupted = false;

			this.Transition();
		},

		Transition : function()
		{
			
			if (this.Interrupted) {
				return;
			}
			
			nb_image_total = $('div#portfolio').children().size();
			this.Last = this.Counter - 1;
			//alert(nb_image_total);
			
			$('div.tmpSlideshowControl').removeClass('tmpSlideshowControlActive');
			
			if (this.Last < 1) {
				this.Last = nb_image_total;
			}
			
			$("#courant").val( $$.Slideshow.Counter );
			$("#last").val( $$.Slideshow.Last );
			//document.getElementById('courant').innerHTML = $$.Slideshow.Counter;
			//document.getElementById('last').innerHTML = $$.Slideshow.Last;
			
			$('div#tmpSlide-' + this.Last).fadeOut(settings.speed);
				
			$('div#tmpSlideshowNum-' + $$.Slideshow.Last).hide();
			$('div#tmpSlideshowNum-' + $$.Slideshow.Counter).show();
			
			var cpt_marge_G = $$.Slideshow.Counter - 1;
			
			$('div#tmpSlideshowNum-' + $$.Slideshow.Counter).css("margin-left", (cpt_marge_G * 13) + "px");
				
			$('div#tmpSlideshowControl-' + $$.Slideshow.Last).removeClass('tmpSlideshowControlActive');
			$('div#tmpSlideshowControl-' + $$.Slideshow.Counter).addClass('tmpSlideshowControlActive');
			
			$('div#tmpSlide-' + $$.Slideshow.Counter).fadeIn(settings.speed);

			

			$$.Slideshow.Counter++;

			if ($$.Slideshow.Counter > nb_image_total) {
				$$.Slideshow.Counter = 1;
			}
			
			interval = setTimeout('$$.Slideshow.Transition();', settings.delay);
		}
  }
});

$(document).ready(
	function() {
	
		$$.Slideshow.Ready();
		
	}
);

function removeFilter(element) {
	if(element.style.removeAttribute){
		element.style.removeAttribute('filter');
	}
}
