//Fonction UNE pour les premières news sur la page d'accueil
$$('html').addClass('js');

var Une = new Class({
	
	setOpt:function(opt){
		this.options={
			illusSpeed:   800
		};
		Object.extend(this.options,opt ||{});
	},

	initialize: function(element,options){
		this.element = this.element || element;
		this.setOpt(options);
		
		// Get elements

		this.accroches = $$('#une .accroche');
		this.illus = $$('#une .illus');
		
		this.construct();
	},
	
	/**
	 *  Prépare les Unes pour le défilement
	 */
	construct: function() {

		// Ajout des événements		
		$$('#une-list a').forEach(function(link){
			link.addEvent('mouseover',this.display.bind(this));
		}.bind(this));
		
		// Met la première une en actif
		var i=20;
		this.accroches.forEach(function(accroche){
			i = i-2;
			accroche.setStyle('z-index',i);
		})
		var i=19;
		this.illus.forEach(function(illu){
			i = i-2;
			illu.setStyle('z-index',i);
		})
		this.active = $('une-li0').addClass('active');
	},
	
	/**
	 * Affiche l'illustration de la une
	 * @param {Object} e
	 */
	display: function(e) {
		if($type(e)=='string' || $type(e)=='number') var id = e;
		else {
			var id = new Event(e).getTarget('LI').id.replace('une-li','');
			new Event(e).stop();
		}		
		if('une-li'+id==this.active.id) return false;
		
		var i=18;
		this.accroches.forEach(function(accroche){
			if (accroche.getStyle('z-index') == 20) zindex = 18;
			else zindex = i = i-2;
			accroche.setStyle('z-index',zindex);
		}.bind(this));
		var i=17;
		this.illus.forEach(function(illu){
			if (illu.getStyle('z-index') == 19) zindex = 17;
			else zindex = i = i-2;
			illu.setStyle('z-index',zindex);
		}.bind(this));
		
		this.active.removeClass('active');
		
		this.active = $('une-li'+id).addClass('active');
		var nid = id*1+1;
		this.accroches[id].setStyles({
			'opacity':0,
			'z-index':20
		});
		this.illus[id].setStyles({
			'opacity':0,
			'z-index':19
		});
		
		if(window.ie && window.ie6) var end = .8;
		else var end = 1;
		
		new Fx.Style(this.accroches[id], 'opacity',{duration:this.options.illusSpeed}).start(0,1);
		new Fx.Style(this.illus[id], 'opacity',{duration:this.options.illusSpeed}).start(0,1);
	},
	
	prev: function() {
		var id = this.active.id.replace('une-li','')*1-1;
		this.display(id);
	},
	
	next: function() {
		var id = this.active.id.replace('une-li','')*1+1;
		this.display(id);
	}
});

window.addEvent('domready',function(){
	new Une();
});
//Fonction Toggle pour les matchs sur la page d'accueil
function toggle(){
	var div1 = document.getElementById('li-1')
	var div2 = document.getElementById('li-2')
	if (div1.style.display == 'none') {
		div1.style.display = 'block'
		div2.style.display = 'none'
	} else {
		div1.style.display = 'none'
		div2.style.display = 'block'
	}
}