//Declaration des variables globales
var num_actu;
var nb_actu;
var num_img;
var nb_img;
var stop = true;
//Gestionnaires du défilement des actualités
function next_actu(){
	new Effect.Fade('effect_actus',{
	duration:0.5,
	afterFinish: function(){
								if((num_actu+1) >= nb_actu){
									num_actu = 0;
								}else{
									num_actu++;
								}
								new Ajax.Updater('actus',
													'includes/modules/latest_news.php?ajax=true&numactu='+num_actu,
													{	method:'get',
														asynchronous:true,
														onSuccess: function() {},
														onComplete: function(){
															new Effect.Appear('effect_actus',{duration:0.5});
														},
														evalScripts:true
													}
												);
								return false;
							}
	});
}
function go_actu(id){
	new Effect.Fade('img_defil_img',{
		duration:0.5,
		afterFinish: function(){
			new Ajax.Updater('img_defil',
								'includes/application_image.php?ajax=true&num_img='+id,
								{	method:'get',
									asynchronous:true,
									onSuccess: function() {},
									onComplete: function(){
										new Effect.Appear('img_defil_img',{duration:0.5});
									},
									evalScripts:true
								}
							);
			return false;
		}
	});
}
function previous_actu(){
	new Effect.Fade('effect_actus',{
	duration:0.5,
	afterFinish: function(){
								if((num_actu-1) < 0){
									num_actu = nb_actu-1;
								}else{
									num_actu--;
								}
								new Ajax.Updater('actus',
													'includes/modules/latest_news.php?ajax=true&numactu='+num_actu,
													{	method:'get',
														asynchronous:true,
														onSuccess: function() {},
														onComplete: function(){
															new Effect.Appear('effect_actus',{duration:0.5});
														},
														evalScripts:true
													}
												);
								return false;
							}
	});
}
function init_actu(nb){
	nb_actu = nb;
	num_actu = 0;
	new Effect.Appear('effect_actus');
}
//Gestionnaires du défilement des images
function next_img(defil){
	stop = defil;
	new Effect.Fade('img_defil_img',{
	duration:1.0,
	afterFinish: function(){
								if((num_img+1) >= nb_img){
									num_img = 0;
								}else{
									num_img++;
								}
								new Ajax.Updater('img_defil',
													'includes/application_image.php?ajax=true&num_img='+num_img,
													{	method:'get',
														asynchronous:true,
														onSuccess: function(){},
														onComplete: function(){
															new Effect.Appear('img_defil_img',{duration:1.0});
														},
														evalScripts:true
													}
												);
								return false;
							}
	});
}
function previous_img(defil){
	stop = defil;
	new Effect.Fade('img_defil_img',{
	duration:1.0,
	afterFinish: function(){
								if((num_img-1) < 0){
									num_img = nb_img-1;
								}else{
									num_img--;
								}
								new Ajax.Updater('img_defil',
													'includes/application_image.php?ajax=true&num_img='+num_img,
													{	method:'get',
														asynchronous:true,
														onSuccess: function(){},
														onComplete: function(){
															new Effect.Appear('img_defil_img',{duration:1.0});
														},
														evalScripts:true
													}
												);
								return false;
							}
	});
}
function init_img(nb){
	nb_img = nb;
	num_img = 0;
	new Effect.Appear('img_defil_img');
}

function animAccueil(){
	var dur = .5;

	if($$('div.cat_img_defil')[0]){
		$('pageContent').setStyle({width:'1000px'});
		$$('table.cmsCategories td').invoke('setStyle', {verticalAlign:'middle'});
		$$('div.cmsCategoriesBloc').invoke('setStyle', {width:'auto', height:'auto', position:'relative'});
		$$('div.cmsCategoriesBloc img.prv').invoke('setStyle', {display:'none', position:'absolute', top:'28px', left:'5px', cursor:'pointer'});
		$$('div.cmsCategoriesBloc img.nxt').invoke('setStyle', {display:'none', position:'absolute', top:'28px', right:'5px', cursor:'pointer'});

		$$('div.cmsCategoriesBloc').each(function(item){
			item.down().next().down().down().onmouseover=function(){
				if((item.down().next().getWidth() == 300)){ // reinitialisation
					$$('div.cmsCategoriesBloc div.cat_img_defil a img').each(function(item2){
						new Effect.Parallel([
						  new Effect.Morph(item2, { sync: true, style: 'width:230px; height:138px' }),
						  new Effect.Morph(item2.up().up().up().down('h3'), { sync: true, style: 'font-size:10px' })
						], {
						  duration: dur,
							afterFinish:function(){
						  		item2.setStyle({width:'230px', height:'138px'});
						  		item2.up().up().up().down('h3').setStyle({fontSize:'10px'});

						  		item2.up().up().up().select('img.nxt')[0].hide();
						  		item2.up().up().up().select('img.prv')[0].hide();
							}
						});

				  		item2.up().up().up().select('img.nxt')[0].hide();
				  		item2.up().up().up().select('img.prv')[0].hide();
					});
				} else {
					//retraississement des autres blocs
					$$('div.cmsCategoriesBloc div.cat_img_defil a img').each(function(item2){
						if(item2.up().up().up() != item) {
							new Effect.Parallel([
								new Effect.Morph(item2, { sync: true, style: 'width:200px; height:111px' }),
								new Effect.Morph(item2.up().up().up().down('h3'), { sync: true, style: 'font-size:10px' })
							], {
								duration: dur,
								afterFinish:function(){
							  		item2.setStyle({width:'200px', height:'111px'});
							  		item2.up().up().up().down('h3').setStyle({fontSize:'10px'});

							  		item2.up().up().up().select('img.nxt')[0].hide();
							  		item2.up().up().up().select('img.prv')[0].hide();
								}
							});

					  		item2.up().up().up().select('img.nxt')[0].hide();
					  		item2.up().up().up().select('img.prv')[0].hide();
						}
					});
					//agrandissement du bloc
					item.select('div.cat_img_defil img').each(function(item2){
						new Effect.Parallel([
						  new Effect.Morph(item2, { sync: true, style: 'width:300px; height:180px' }),
						  new Effect.Morph(item2.up().up().up().down('h3'), { sync: true, style: 'font-size:13px' })
						], {
						  	duration: dur,
							afterFinish:function(){
						  		item2.setStyle({width:'300px', height:'180px'});
						  		item2.up().up().up().down('h3').setStyle({fontSize:'13px'});

						  	//	item.select('img.nxt')[0].show();
						  	//	item.select('img.prv')[0].show();
							}
						});
					});
					current = item;
				}
				return false;
			};
		});
	}
}

function entretien(id){
	new Effect.Fade('entretien_dt',{
		duration:0.5,
		afterFinish: function(){
			new Ajax.Updater('entretien_dt',
								'ajax.entretien.details.php?option_id='+id,
								{	method:'get',
									asynchronous:true,
									onSuccess: function() {},
									onComplete: function(){
										new Effect.Appear('entretien_dt',{duration:0.5});
									},
									evalScripts:true
								}
							);
			return false;
		}
	});
}
