function showAnotherImage(pCurrent_image, pIncrement)
{
	var wanted_indice = 0;
	var tabImages = new Array();
	
	tabImages = getElementsByClassName('showed_image');

	if(tabImages.length != null)
	{
		var current_indice = getCurrentIndice();
		wanted_indice = parseInt(current_indice,10) + parseInt(pIncrement,10)
		var max =  tabImages.length;
		
		if(wanted_indice < 0)
		{
			wanted_indice = (max - 1);
		}else{
			if(wanted_indice > (max - 1))
			{
				wanted_indice = 0;
			}
		}

		var Current_image = 'image:'+pCurrent_image;
		var Wanted_image = tabImages[wanted_indice];
		
		new Effect.Fade($(Current_image),{queue:'front'});
		new Effect.Appear($(Wanted_image),{queue:'end', afterFinish:changeFlecheIndice});
	}

	function changeFlecheIndice(pCurrent_indice, pWanted_indice)
	{
		$('fleche_droite:'+pCurrent_image).id = 'fleche_droite:'+Wanted_image.replace('image:','');
		$('fleche_gauche:'+pCurrent_image).id = 'fleche_gauche:'+Wanted_image.replace('image:','');
	}
	
	function getCurrentIndice()
	{
		for(var ind = 0; ind < tabImages.length; ind++)
		{
			curr = $(tabImages[ind]).id.replace('image:','');
			if(curr == pCurrent_image)
			{
				return ind;
			}
		}
		return 0;
	}
};

function getElementsByClassName(clsName){
    var retVal = new Array();
    var elements = document.getElementsByTagName("*");
    for(var i = 0;i < elements.length;i++){
    	if(elements[i].className != "")
    	{
        	if(elements[i].className == clsName)
        	{
        		retVal.push(elements[i].id);
        	}
        }
    }	
    return retVal;
}

function opacifyMe(bloca)
{
	new Effect.Opacity(bloca,{ duration:0.2, from:1.0, to:0.5});
}

var myrules = {
		
		'img.thumbs' : function(im) {

			opacifyMe(im);

			im.onmouseover = function()
			{
				new Effect.Appear(im,{duration:0.1});
			}
			
			im.onmouseout = function()
			{
				opacifyMe(im);
			}
		},
		
		'.fleche_gauche' : function(fg){
			fg.onclick = function(){
				current_indice = fg.id.replace('fleche_gauche:','');
				showAnotherImage(current_indice,-1);
			};
		},
		
		'.fleche_droite' : function(fd){

			fd.onclick = function(){
				current_indice = fd.id.replace('fleche_droite:','');
				showAnotherImage(current_indice,1);
			};
		}
};

// Enregistrement des regles definies ci dessus dans Behaviour
Behaviour.register(myrules);
