// JavaScript Document
window.addEvent('domready', function() {
	var actIndex = 0;
	var nextIndex = 0;
	var timer;
	function showItem(){
		hideItem();
		actIndex = nextIndex;
		//console.log('SHOW:'+actIndex);
		if(actIndex > 4){
			actIndex = 0;
		}
		var picEle = $('pic_'+actIndex);
		picEle.setStyle('display', 'block');
		var fxP = new Fx.Styles(picEle, {duration:1000, wait:false});
 		fxP.start({
			'opacity': 1
		});
		var txtEle = $('txt_'+actIndex);
		txtEle.setStyle('display', 'block');
		var fxT = new Fx.Styles(txtEle, {duration:1000, wait:false});
 		fxT.start({
			'opacity': 1
		});
		nextIndex = actIndex+1;
	};
	function hideItem(){
		//console.log('HIDE:'+actIndex);
		var picEle = $('pic_'+actIndex);
		var fxP = new Fx.Styles(picEle, {duration:0, wait:false});
 		fxP.start({
			'opacity': 0
		});
		picEle.setStyle('display', 'none');
		var txtEle = $('txt_'+actIndex);
		var fxT = new Fx.Styles(txtEle, {duration:0, wait:false});
 		fxT.start({
			'opacity': 0
		});
		txtEle.setStyle('display', 'none');
	};
	// GET DATA
	var headerData = Array();
	var picIndex = 0;
	var txtIndex = 0;
	var linkIndex = 0;
	$$('#z_promo_img img').each(function(item){
		item.id = 'pic_'+picIndex;
		item.setStyle('opacity', 0);
		item.setStyle('display', 'none');
		picIndex++;
	});
	$$('#z_promo_texte div').each(function(item){
		item.id = 'txt_'+txtIndex;
		item.setStyle('opacity', 0);
		item.setStyle('display', 'none');
		txtIndex++;
	});
	$$('#z_promo_thumb a').each(function(item){
		item.rel = linkIndex;
		item.addEvent('click', function(){
			nextIndex = this.rel.toFloat();
			//console.log('INDEX:'+nextIndex);
			$clear(timer);
			showItem();
			timer = (function(){ showItem(); }).periodical(4000);
		});
		linkIndex++;
	});
	$$('#z_promo_texte div').each(function(item){
		item.addEvent('mouseover', function(){
			$clear(timer);
		});
		item.addEvent('mouseout', function(){
			timer = (function(){ showItem(); }).periodical(4000);
		});
	});
	showItem();
	timer = (function(){ showItem(); }).periodical(4000);
	
	
});


/*ACCUEIL LOADING RSS*/
window.addEvent('domready', function() {
	if($('rssBlock')){
		var url = "/imports/block/rss.news.php";
		
		function hideLoading(){
			$('rssLoading').setStyle('display', 'none');
		}
	 
		new Ajax(url, {
			method: 'get',
			update: $('rssBlock'),
			onComplete: hideLoading
		}).request();
	}
});