var NewsCarousel=new Class({
	
	Implements: [Options],
	options: {
		
			linkSelect: 'RecentTitles',
			contentDiv: 'carouselContentContainer',
			contentClass: 'newsContent',
			curSelected: false,
			contentItems: [],
			contentLinks: [],
			playInterval: false
		
	},
	
	initialize: function(options){
		this.setOptions(options);
		
		this.options.contentItems=$$('div.'+this.options.contentClass);	
		this.build();		
	},
	
	build: function(){
		
		$$('a.'+this.options.linkSelect).each(function(el){
											   
			var elID=this.getID(el, this.options.linkSelect)
			
			if(!this.options.curSelected){
				this.options.curSelected=elID;
			}
			
			
			this.options.contentLinks.push(elID);
			
			el.addEvent('click', function(e){
									  	
				this.options.curSelected=elID;
				this.showCurrent();
				$clear(this.options.playInterval);
				
			}.bind(this))											   
											   
											   
		}, this);
		
		this.showCurrent();
		this.options.playInterval=this.play.periodical(10000, this);
		
		
	},
	
	
	showCurrent: function(){
		
		this.options.contentItems.each(function(el){
												
			var elID=this.getID(el, this.options.contentClass);
			if(elID==this.options.curSelected){
				el.setStyle('display','');
				el.fade(1);
			}
			else{
				el.fade(0);
				el.setStyle('display','none');												
			}
			
		},this)
		
	},
	
	getID: function(el, preFix){
		
		var elName=el.id;
		var elID=elName.substring(preFix.length+1, elName.length);
		return elID;		
		
	},
	
	play: function(){
		
		var cur=this.options.curSelected;
		var links=this.options.contentLinks
		
		for(var i=0; i<links.length; i++){
			
			if(links[i]==cur){
				
				if(i==(links.length-1)){
					this.options.curSelected=links[0];
					break;
				}
				else{
					this.options.curSelected=links[i+1];
					break;
				}			
				
			}
			
		}
		
		this.showCurrent();
		
		
	}
					   
					   
})
