window.addEvent('domready', function(){
	document.getElement('body').removeClass('no-js').addClass('js');
	
	swfobject.embedSWF('/swf/en/animation-haut.swf', 'animation-haut', 473, 131, '9.0.0', '/swf/expressInstall.swf');

	var scrollTicker = new ScrollTicker($E('.scroll', $('actualites')));
	
	$$('#corps h3').each(function(item, i){
		item.addClass('gd');
		if(a = $E('a', item)) item = a;
		item.getChildren().each(function(child){
			child.remove();
		});
		var text = item.getText().clean();
		new Element('img', {src: '/img/titres/h3/'+encodeURIComponent(text)+'.png', width: 738, height: 72, alt: text}).injectInside(item.empty());
	});
	
	if(window.ie6){
		$$('img[align=left]').addClass('align-left');
		$$('img[align=right]').addClass('align-right');
	}
});

var ScrollTicker = new Class({
	options: {
		timeout: 5000,
		duration: 1000,
		transition: Fx.Transitions.Quad.easeInOut
	},

	initialize: function(element, options){
		this.setOptions(options);
		this.element = $(element);
		this.items = this.element.getChildren()[0].getChildren();
		this.numItems = this.items.length;
		if(this.numItems > 1){
			this.current = 0;
			this.scroll = new Fx.Scroll(this.element, {
				wheelStops: false,
				wait: false,
				duration: this.options.duration,
				transition: this.options.transition
			});
			this.scroll.toTop();
			this.periodical = this.next.periodical(this.options.timeout, this);
			
			that = this;
			this.element.addEvents({
				mouseenter: function(){
					$clear(that.periodical);
				},
				mouseleave: function(){
					that.periodical = that.next.periodical(that.options.timeout, that);
				},
				mousewheel: function(event){
					event = new Event(event);
					if(event.wheel > 0) that.previous(); // UP
					else if(event.wheel < 0) that.next(); // DOWN
					event.stop();
				}
			});
			
			this.controls = new Element('ul', {'class': 'controles'});
			this.controlsPrevious = new Element('a', {href: '#', title: 'Actualité précédente', events: {click: function(event){
				event = new Event(event).stop();
				that.previous();
			}}}).setText('Précédent').injectInside(new Element('li', {'class': 'precedent'}).injectInside(this.controls));
			this.controlsNext = new Element('a', {href: '#', title: 'Actualité suivante', events: {click: function(event){
				event = new Event(event).stop();
				that.next();
			}}}).setText('Suivant').injectInside(new Element('li', {'class': 'suivant'}).injectInside(this.controls));
			this.controls.injectInside(element);
		}
	},
	
	next: function(){
		if(this.current < this.numItems-1) this.current++;
		else this.current = 0;
		this.scroll.toElement(this.items[this.current]);
	},
	
	previous: function(){
		if(this.current > 0) this.current--;
		else this.current = this.numItems-1;
		this.scroll.toElement(this.items[this.current]);
	}
});

ScrollTicker.implement(new Events, new Options);