window.addEvent('domready', function(){
	document.getElement('body').removeClass('no-js').addClass('js');
	
	var ticker = new Ticker($('news').getElement('ul'));
	
	var header = new Swiff('/swf/header.swf', {
		width: 900,
		height: 195,
		container: $('flash')
	});
	
	$$('#menu > ul > li').each(function(item, i){
		item.store('fade', new Fx.Tween(item.getElement('a'), {property: 'opacity', link: 'cancel', duration: 'short'}));
		item.addEvents({
			mouseenter: function(event){
				item.retrieve('fade').start(0.001);
			},
			mouseleave: function(event){
				item.retrieve('fade').start(1);
			}
		});
		if(ul = item.getElement('ul')){
			var slide = new Fx.Slide(ul, {link: 'cancel'});
			item.store('slide', slide);
			if(!item.hasClass('current')){
				slide.hide();
				item.addEvents({
					mouseenter: function(event){
						 item.retrieve('slide').slideIn();
					},
					mouseleave: function(event){
						 item.retrieve('slide').slideOut();
					}
				});
			}
		}
	});
});

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

	initialize: function(list, options){
		this.setOptions(options);
		this.list = $(list);
		this.items = this.list.getChildren();
		this.effect = new Fx.Morph(this.list, {duration: this.options.duration});
		if(this.items.length > 1){
			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({
			opacity: 0
		}).chain(this.next.bind(this));
	},
	
	next: function(){
		this.items.setStyle('display', 'none');
		var last = this.list.getLast();
		last.setStyle('display', 'block').injectTop(this.list);
		this.effect.start({
			opacity: 1
		});
	}
});

Ticker.implement(new Events, new Options);