function vIE(){
	return(navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):99;
}

version = vIE();

function lit(spot, num){
	if(version >= 7){
		switch(num){
			case 1 :
				$(spot+'-gauche').style.backgroundImage = "url('../img/menu-picto-actif-gauche.png')";
				$(spot+'-centre').style.backgroundImage = "url('../img/menu-picto-actif-centre.png')";
				$(spot+'-droite').style.backgroundImage = "url('../img/menu-picto-actif-droite.png')";
				break;
			case 2 :
				$(spot+'-gauche').style.backgroundImage = "url('../img/menu-picto-actif-gauche.png')";
				$(spot+'-centre').style.backgroundImage = "url('../img/menu-picto-actif-centre.png')";
				$(spot+'-droite').style.backgroundImage = "url('../img/menu-picto-actif-droite.png')";
				break;
			case 3 :
				$(spot+'-gauche').style.backgroundImage = "url('../img/menu-picto-actif-gauche.png')";
				$(spot+'-centre').style.backgroundImage = "url('../img/menu-picto-actif-centre.png')";
				$(spot+'-droite').style.backgroundImage = "url('../img/menu-picto-actif-droite.png')";
				break;
			case 4 :
				$(spot+'-gauche').style.backgroundImage = "url('../img/menu-picto-actif-gauche.png')";
				$(spot+'-centre').style.backgroundImage = "url('../img/menu-picto-actif-centre.png')";
				$(spot+'-droite').style.backgroundImage = "url('../img/menu-picto-actif-droite.png')";
				break;
		}
	}else{
		switch(num){
			case 1 :
				$(spot+'-gauche').style.backgroundImage = "url('../img/menu-picto-actif-gauche-ie6.png')";
				$(spot+'-centre').style.backgroundImage = "url('../img/menu-picto-actif-centre-ie6.png')";
				$(spot+'-droite').style.backgroundImage = "url('../img/menu-picto-actif-droite-ie6.png')";
				break;
			case 2 :
				$(spot+'-gauche').style.backgroundImage = "url('../img/menu-picto-actif-gauche-ie6.png')";
				$(spot+'-centre').style.backgroundImage = "url('../img/menu-picto-actif-centre-ie6.png')";
				$(spot+'-droite').style.backgroundImage = "url('../img/menu-picto-actif-droite-ie6.png')";
				break;
			case 3 :
				$(spot+'-gauche').style.backgroundImage = "url('../img/menu-picto-actif-gauche-ie6.png')";
				$(spot+'-centre').style.backgroundImage = "url('../img/menu-picto-actif-centre-ie6.png')";
				$(spot+'-droite').style.backgroundImage = "url('../img/menu-picto-actif-droite-ie6.png')";
				break;
			case 4 :
				$(spot+'-gauche').style.backgroundImage = "url('../img/menu-picto-actif-gauche-ie6.png')";
				$(spot+'-centre').style.backgroundImage = "url('../img/menu-picto-actif-centre-ie6.png')";
				$(spot+'-droite').style.backgroundImage = "url('../img/menu-picto-actif-droite-ie6.png')";
				break;
		}
	}
}

function unlit(spot, num) {
	if(version >= 7){
		switch(num){
			case 1 :
				$(spot+'-gauche').style.backgroundImage = "url('../img/menu-picto-gauche-jaune.png')";
				$(spot+'-centre').style.backgroundImage = "url('../img/menu-picto-centre-jaune.png')";
				$(spot+'-droite').style.backgroundImage = "url('../img/menu-picto-droite-jaune.png')";
				break;
			case 2 :
				$(spot+'-gauche').style.backgroundImage = "url('../img/menu-picto-gauche-bleu.png')";
				$(spot+'-centre').style.backgroundImage = "url('../img/menu-picto-centre-bleu.png')";
				$(spot+'-droite').style.backgroundImage = "url('../img/menu-picto-droite-bleu.png')";
				break;
			case 3 :
				$(spot+'-gauche').style.backgroundImage = "url('../img/menu-picto-gauche-orange.png')";
				$(spot+'-centre').style.backgroundImage = "url('../img/menu-picto-centre-orange.png')";
				$(spot+'-droite').style.backgroundImage = "url('../img/menu-picto-droite-orange.png')";
				break;
			case 4 :
				$(spot+'-gauche').style.backgroundImage = "url('../img/menu-picto-gauche-vert.png')";
				$(spot+'-centre').style.backgroundImage = "url('../img/menu-picto-centre-vert.png')";
				$(spot+'-droite').style.backgroundImage = "url('../img/menu-picto-droite-vert.png')";
				break;
		}
	}else{
		switch(num){
			case 1 :
				$(spot+'-gauche').style.backgroundImage = "url('../img/menu-picto-gauche-ie6.png')";
				$(spot+'-centre').style.backgroundImage = "url('../img/menu-picto-centre-ie6.png')";
				$(spot+'-droite').style.backgroundImage = "url('../img/menu-picto-droite-ie6.png')";
				break;
			case 2 :
				$(spot+'-gauche').style.backgroundImage = "url('../img/menu-picto-gauche-ie6.png')";
				$(spot+'-centre').style.backgroundImage = "url('../img/menu-picto-centre-ie6.png')";
				$(spot+'-droite').style.backgroundImage = "url('../img/menu-picto-droite-ie6.png')";
				break;
			case 3 :
				$(spot+'-gauche').style.backgroundImage = "url('../img/menu-picto-gauche-ie6.png')";
				$(spot+'-centre').style.backgroundImage = "url('../img/menu-picto-centre-ie6.png')";
				$(spot+'-droite').style.backgroundImage = "url('../img/menu-picto-droite-ie6.png')";
				break;
			case 4 :
				$(spot+'-gauche').style.backgroundImage = "url('../img/menu-picto-gauche-ie6.png')";
				$(spot+'-centre').style.backgroundImage = "url('../img/menu-picto-centre-ie6.png')";
				$(spot+'-droite').style.backgroundImage = "url('../img/menu-picto-droite-ie6.png')";
				break;
		}
	}
}

var Ticker = new Class({
	options: {
		number: 1,
		timeout: 5000,
		duration: 250
	},

	initialize: function(list, options){
		this.setOptions(options);
		this.list = $(list);
		this.items = this.list.getChildren();
		this.effect = new Fx.Style(this.list, 'opacity', {duration: this.options.duration});
		this.next();
		this.periodical = this.start.periodical(this.options.timeout, this);
		that = this;
		this.list.addEvents({
			'mouseenter': function(){
				$clear(that.periodical);
			},
			'mouseleave': function(){
				that.periodical = that.start.periodical(that.options.timeout, that);
			}
		});
	},
	
	start: function(){
		this.effect.start(0).chain(this.next.bind(this));
	},
	
	next: function(){
		this.items.setStyle('display', 'none');
		for(var i = 0; i < this.options.number; i++) this.list.getFirst().setStyle('display', 'block').injectInside(this.list);
		this.effect.start(1);
	}
});

Ticker.implement(new Events, new Options);

window.addEvent('domready', function(event){
	var scroll2 = new Scroller('lien-scroll', {area: 25, velocity: 1});
	
	$('lien-scroll').addEvent('mouseover', scroll2.start.bind(scroll2));
	$('lien-scroll').addEvent('mouseout', scroll2.stop.bind(scroll2));
	
	/*var scroll3 = new Scroller('doc-scroll', {area: 25, velocity: 1});
	
	$('doc-scroll').addEvent('mouseover', scroll2.start.bind(scroll3));
	$('doc-scroll').addEvent('mouseout', scroll2.stop.bind(scroll3));*/
	
	ticker = new Ticker($('actualites-liste'));
	
	$('menu').getElements('li[id^=menu]').each(function(item, index){
		var alpha = 0.90;
		var alpha_duration = 400;
		var alpha_delay = 200;
		
		var menu = item;
		var submenu = menu.getElement('ul');
		var menu_link = menu.getElement('a');
		var menu_delay;
		
		if(submenu != null){
			var menu_alpha = new Fx.Style(submenu, 'opacity', {duration: alpha_duration});
			menu_alpha.set(0);
			
			menu_link.addEvent('mouseenter', function(){
				menu_alpha.stop();
				menu_alpha.start(0.90);
			});
			menu.addEvent('mouseleave', function(){
				menu_alpha.stop();
				if(submenu.getStyle('opacity') != alpha){
					menu_alpha.start(0);
				}else{
					menu_delay = (function(){menu_alpha.start(0)}).delay(alpha_delay);
				}
			});
			submenu.addEvent('mouseenter', function(){
				$clear(menu_delay);
				menu_alpha.stop();
				menu_alpha.start(alpha);
			});
						
			submenu.getElements('li').each(function(item, index){
				item.addEvent('click', function(){
					window.location = $E('a', item).href;
				});
				item.addEvent('mouseenter', function(){
					$E('a', item).setStyle('color', '#000');
				});
				item.addEvent('mouseleave', function(){
					$E('a', item).setStyle('color', '#fff');
				});
			});
		};
	});
});