var FeaturesArea = new Class({

	initialize: function(list){
		var that = this;

		this.carousel = $('featured').empty();
		this.list = list;
		this.slides = [];
		
		$each(this.list, function(item, index){
			that.slides[index] = new Element('li').inject(that.carousel);
			that.slides[index].link = new Element('a', {
				'href': item.LinkURL !== '' ? item.LinkURL : '#',
				'target': item.TargetURL !== '' ? item.TargetURL : ''
			}).inject(that.slides[index]);
			that.slides[index].img = new Element('img', {
				'src' : '/images/features/' + item.ImageFile
			}).inject(that.slides[index].link);
		});
		
		this.nav = new Element('ul',{
			'class': 'nav'
		});
		this.nav.items = [];
		
		this.slides.each(function(slide, index){
			slide.fx = new Fx.Tween(slide);
			that.nav.items[index] = new Element('li').inject(that.nav);
			that.nav.items[index].link = new Element('a', {
				'text': index+1,
				'href': '#',
				'events': {
					'click': function(e){
						e.preventDefault();
						if(!this.getParent('li').hasClass('selected')) that.goToSlide(index);
					}
				}
			}).inject(that.nav.items[index]);
			
			if(index > 0) slide.fx.set('opacity', 0);
		});
		this.slides.index = 0;
		
		this.nav.inject(this.carousel, 'bottom');
		this.updateNav();
		this.autoScroll = this.nextSlide.periodical(5000, this);
	
	},
	
	nextSlide: function(){
		var that = this;
		
		this.slides[this.slides.index].fx.start('opacity', 0).chain(function(){
			that.slides.index < that.slides.length-1 ? that.slides.index = ++that.slides.index : that.slides.index = 0;
			that.updateNav();
			that.slides[that.slides.index].fx.start('opacity', 1);
		});
		
	},
	
	goToSlide: function(index){
		var that = this;
		
		$clear(this.autoScroll);
		this.slides[this.slides.index].fx.start('opacity', 0).chain(function(){
			that.slides.index = index;
			that.updateNav();
			that.slides[that.slides.index].fx.start('opacity', 1);
			that.autoScroll = that.nextSlide.periodical(5000, that);
		});
	
	},
	
	updateNav: function(){
	
		this.nav.items.each(function(item){
			item.removeClass('selected');
		});
		this.nav.items[this.slides.index].addClass('selected');
	
	}

});

function setFooter()
{
var footerCopy = null;
var currentYear = (new Date).getFullYear();
document.getElementById('footer-right').innerHTML = document.getElementById('footer-right').innerHTML.replace('2009', currentYear);
}
window.onload = setFooter;

