function closeGallery(ids){
	var myEffect = new Fx.Morph('gallery_'+ids, {duration: 'long', transition: Fx.Transitions.linear});

	$('evoc_img_'+ids).getParent().setProperty('href','javascript:openGallery('+ids+');');
	$('close_btn_action').setProperty('href','javascript:closeHistory();');
	
	myEffect.start({
	    'opacity': [1, 0.01]
	});
	
	var myEffect = new Fx.Morph('box_storiaTesto_'+ids, {duration: 'long', transition: Fx.Transitions.linear});
	myEffect.start({
	    'opacity': [0.2, 1]
	});
	
	myEffect.onComplete=function(){
		$('gallery_'+ids).setStyle('display','none');
	}
}

function openGallery(ids){
	$('gallery_'+ids).setStyle('opacity','0');
	$('gallery_'+ids).setStyle('display','block');
	
	$('close_btn_action').setProperty('href','javascript:closeGallery('+ids+');');
	
	var myEffect = new Fx.Morph('box_storiaTesto_'+ids, {duration: 'long', transition: Fx.Transitions.linear});
	myEffect.start({
	    'opacity': [1, 0.2]
	});
	myEffect.onComplete=function(){
		var myEffect2 = new Fx.Morph('gallery_'+ids, {duration: 'long', transition: Fx.Transitions.linear});
		
		myEffect2.start({
		    'opacity': [0, 1]
		});
		myEffect2.onComplete=function(){

		}
	}
}

function nextPics(lenght,ids){
	var current=$('pics_'+ids).getStyle('left').toInt();
	
	if (semaphorePrev==false && semaphoreNext==false && current > -((lenght-1)*558)){
		semaphoreNext=true;
			
		var myEffect = new Fx.Morph('pics_'+ids, {duration: 'long', transition: Fx.Transitions.linear});
		myEffect.start({
		    'left': [current,current-558]
		});
		
		myEffect.onComplete=function(){
			showPrev(lenght,ids);
			semaphoreNext=false;
			if ((current-558) == -((lenght-1)*558)){
				//$('next_btn_'+ids).setStyle('opacity','0');
				$('next_btn_'+ids).setStyle('cursor','default');
				
				var myEffect = new Fx.Morph('next_btn_'+ids, {duration: 250, transition: Fx.Transitions.linear});
				myEffect.start({
				    'opacity': [0.3,0.01]
				});
			}
		}
	}
	
}

function prevPics(lenght,ids){
	var current=$('pics_'+ids).getStyle('left').toInt();
	
	if (semaphorePrev==false && semaphoreNext==false && current < 0){
		semaphorePrev=true;	
	
		var myEffect = new Fx.Morph('pics_'+ids, {duration: 'long', transition: Fx.Transitions.linear});
		myEffect.start({
		    'left': [current,current+558]
		});
		
		myEffect.onComplete=function(){
			showNext(lenght,ids);
			semaphorePrev=false;
			if (current+558==0){			
				//$('prev_btn_'+ids).setStyle('opacity','0');
				$('prev_btn_'+ids).setStyle('cursor','default');
				
				var myEffect = new Fx.Morph('prev_btn_'+ids, {duration: 250, transition: Fx.Transitions.linear});
				myEffect.start({
				    'opacity': [0.3,0.01]
				});
				
			}
		}
	}
}


function showPrev(lenght,ids){
	var current=$('pics_'+ids).getStyle('left').toInt();
	
	if (semaphorePrev==false && $('prev_btn_'+ids).getStyle('opacity')!='0.3' && (current)<0){
		semaphorePrev=true;
		$('prev_btn_'+ids).setStyle('cursor','pointer');
		
		var myEffect = new Fx.Morph('prev_btn_'+ids, {duration: 250, transition: Fx.Transitions.linear});
		myEffect.start({
		    'opacity': [0,0.3]
		});
		
		myEffect.onComplete=function(){
			semaphorePrev=false;
		}
	}else{
		$('prev_btn_'+ids).setStyle('cursor','default');
	}
}

function hidePrev(lenght,ids){
	var current=$('pics_'+ids).getStyle('left').toInt();
	
	if (semaphorePrev==false && $('prev_btn_'+ids).getStyle('opacity')!='0' && (current)<0){
		semaphorePrev=true;
		$('prev_btn_'+ids).setStyle('cursor','pointer');
		
		var myEffect = new Fx.Morph('prev_btn_'+ids, {duration: 250, transition: Fx.Transitions.linear});
		myEffect.start({
		    'opacity': [0.3,0.01]
		});
		
		myEffect.onComplete=function(){
			semaphorePrev=false;
		}
	}else{
		$('prev_btn_'+ids).setStyle('cursor','default');
	}
}

function showNext(lenght,ids){
	var current=$('pics_'+ids).getStyle('left').toInt();
	
	if (semaphoreNext==false && $('next_btn_'+ids).getStyle('opacity')!='0.3' && ((current) > -((lenght-1)*558))){
		semaphoreNext=true;
		$('next_btn_'+ids).setStyle('cursor','pointer');
			
		var myEffect = new Fx.Morph('next_btn_'+ids, {duration: 250, transition: Fx.Transitions.linear});
		myEffect.start({
		    'opacity': [0,0.3]
		});
		
		myEffect.onComplete=function(){
			semaphoreNext=false;
		}
	}else{
		$('next_btn_'+ids).setStyle('cursor','default');
	}
}

function hideNext(lenght,ids){
	var current=$('pics_'+ids).getStyle('left').toInt();
	
	if (semaphoreNext==false && $('next_btn_'+ids).getStyle('opacity')!='0' && ((current) > -((lenght-1)*558))){
		semaphoreNext=true;
		$('next_btn_'+ids).setStyle('cursor','pointer');
		
		var myEffect = new Fx.Morph('next_btn_'+ids, {duration: 250, transition: Fx.Transitions.linear});
		myEffect.start({
		    'opacity': [0.3,0.01]
		});
		
		myEffect.onComplete=function(){
			semaphoreNext=false;
		}
	}else{
		$('next_btn_'+ids).setStyle('cursor','default');
	}
}
