// JavaScript Document


$(document).ready(function(){
    //<![CDATA[
	var slideshowWidth  = 735;
	$.fn.slideshow = function(node) { 
		var nb = $(this).children('ul').children('li').length;
		$(this).css('overflow', 'hidden'); 
		$(this).children('ul').width(slideshowWidth * nb);
		//alert(node);
		eval('var cp_'+node+' = 0');
		// Insert les flèches de gauche et de droite  
		$(this)
			.prepend('<span class="control" id="leftControl" title="'+prev+'">'+prev+'</span>')  
			.append('<span class="control" id="rightControl" title="'+next+'">'+next+'</span>');
	
		// Cache la flèche de gauche au début  
		manageControls(eval('cp_'+node));  
		
		// crée un écouteur pour l'évènement de type clic sur les div qui ont la classe .control  
		$(this).children('.control')
			.bind('click', function(){  
			// Determine une nouvelle position  
			eval('var cp = cp_'+node);
			cp = ($(this).attr('id')=='rightControl')  
			? (parseInt(cp)+1 == eval('cp_'+node) 
			   ? cp 
			   : parseInt(cp)+1 
			  )
			: ( parseInt(cp)-1 == -1 
			   ? cp 
			   : parseInt(cp)-1
			  );
			eval('cp_'+node+' = cp');
			//alert('.'+medias[i][1]);
			
			//Cache ou montre les flèches  
			manageControls(cp);  
			// Move photos_produits using margin-left  
			$('.node-'+node).children('ul').animate({  
				'marginLeft' : slideshowWidth *(-cp)
			});  
		});
	
	
		// manageControls: Cache ou montre les flèches de contrôles en fonction de la position  
		function manageControls(position){
			// Hide left arrow if position is first slide  
			if(position==0)
				$('.node-'+node).children('#leftControl').hide();
			else
				$('.node-'+node).children('#leftControl').show();
			// Hide right arrow if position is last slide  
			if(position==nb-1)
				$('.node-'+node).children('#rightControl').hide();
			else
				$('.node-'+node).children('#rightControl').show();
		}  
    };

    //]]>
});
