
var reel = function() {
	periodicalId	= (function(){
		prev	= current;

		current	= (current < objects.length-1) ? current + 1 : 0;

		slideLeft 		= new Fx.Tween(objects[current], {property: 'left', duration: 1000 });
		objects[current].setStyle('left','240px');
		objects[current].show();
		objects[current].setStyle('z-index','100');
		
		slideLeft.start(8);
		
		$$('.items div').removeClass('active');
		$(objects[current].id.replace('news','')).addClass('active');
		
		objects.setStyle('z-index','10');
		objects[current].setStyle('z-index','12');
		objects[prev].setStyle('z-index','11');
	}).periodical(8000);
}


	
/*
var HeaderLoop = new Class({
	
	Implements					: Options,
	
	options						:
	{
		'speed'						: 5000
	},
	
	initialize					: function(container,options)
	{
		this.setOptions(options);
		this.images		= $(container).getElements('img');
		this.count		= this.images.length;
		this.current	= 0;
		this.running	= false;
		this.loadImage();
		this.loop = this.loadImage.periodical(this.options.speed,this,'next');
	},
	
	stopLoop					: function()
	{
		$clear(this.loop);
	},
	
	loadImage					: function(neg)
	{	
	
		this.running = true;
		this.images.setStyle('z-index',0);
		
		var current = false;
		
		if (neg) {
			var next = (this.current < this.count - 1) ? this.current + 1 : 0;
			var prev = (this.current == 0) ? this.count - 1 : this.current - 1;
			current			= this.images[this.current];
			var active 		= (neg == 'next') ? this.images[next] : this.images[prev];
			var previous 	= (neg == 'next') ? this.images[prev] : this.images[next];
		} else {
			var active 		= this.images[this.current];
			var previous 	= this.images[this.count - 1];
		}
		
		var tween = new Fx.Tween(active);
		active.setStyle('z-index',2);
		
		if (document.all) {
			active.setStyle('opacity',1);
			if (current) current.setStyle('opacity',0);
		} else {
			tween.start('opacity',0,1).chain(function(){
				if (current) {
					var tween2 = new Fx.Tween(current);
					tween2.start('opacity',1,0);
				}
				//if (current) current.setStyle('opacity',0);
				this.running = false;			
			}.bind(this));
		}
		if (neg)
		{
			if (neg == 'next') {
				this.current++;
				if (this.current == this.count) this.current = 0;
			} else {
				this.current--;
				if (this.current == -1) this.current = this.count - 1;
			}
		}
		
	}
	
});
*/
window.addEvent("domready",function(){
	/*if ($('header-slideshow') && $('header-slideshow').getChildren().length > 1) {
		//console.log('hi');
		var header = new HeaderLoop('header-slideshow');
	}*/
	//new NewsReel($$('.roller'));
	current		= 0;
	objects		= $$('.roller');

	reel();

	$$('.roller').addEvents({
		mouseenter: function() {
			$clear(periodicalId);
		},
		mouseleave: reel
	});
	
	$$('.items div').addEvent('click',function() {
		$clear(periodicalId);
			
		prev			= current;
		current			= this.get('rank') * 1;
		slideLeft 		= new Fx.Tween(objects[current], {property: 'left', duration: 1000 });
		objects[current].setStyle('left','240px');
		objects[current].show();
		objects[current].setStyle('z-index','100');
		
		slideLeft.start(8);
		
		objects.setStyle('z-index','10');
		objects[current].setStyle('z-index','12');
		objects[prev].setStyle('z-index','11');

		$$('.items div').removeClass('active');
		$(objects[current].id.replace('news','')).addClass('active');
		
		reel();
	});
});
