var NewsDiaporama = new Class({
	initialize: function(container){
		this.container = container;
		this.title = this.container.getFirst();
		this.imgs = this.container.getElements('img');
		this.titles = new Array();
		for(var i = 0; i < this.imgs.length; i++){
			this.titles.push(this.imgs[i].get('title'));
			this.imgs[i].set('title', null);
		}
		this.interval = null;
		this.count = 0;
		this.setup();
	},
	
	get: function(index){
		return this.imgs[index % this.imgs.length];
	},
	
	getTitle: function(index){
		return this.titles[index % this.titles.length];
	},
	
	setTitle: function(title){
		this.title.set('text', title);
	},
	
	empty: function(){
		for(var e = 0; e < this.container.getChildren(); e++){
			if(this.container.getChildren()[e].get('tag') == 'img'){
				this.container.getChildren()[e].dispose();
			}
		}
	},
	
	play: function(){
		this.interval = setInterval(
			"$('" + this.container.get('id') + "').retrieve('diaporama').next()",
			4000
		);
	},
	
	next: function(){
		this.count++;
		this.empty();
		this.container.appendChild(this.get(this.count));
		this.setTitle(this.getTitle(this.count));
	},
	
	setup: function(){
		this.container.store('diaporama', this);
		this.empty();
		this.container.appendChild(this.get(this.count));
		this.setTitle(this.getTitle(this.count));
		this.play();
	}
});

