var SlideShow = Class.create({
	element: null,
	data: [],
	current: null,
	duration: 0.8,
	count: 0,
	initialize: function(element, data) {
		this.element = $(element);
		this.data = $(data);

		this._updateText($H(this.data).values()[0]);
	},
	switchTo: function(id) {
		this.current = this.data[id];
		this._slide();
	},
	_slide: function() {
		if(!this.current)
			return;

		if(this.count == 0) {
			//this._updateText(this.current);
		} else {
			var switchCallback = function() {
				this._updateText(this.current);
				var effectAttributes = { from: 0.0,  to: 1.0, duration: this.duration };
	
				new Effect.Opacity(this.element, effectAttributes);			
			}.bindAsEventListener(this);
		
			var effectAttributes = { from: 1.0, to: 0.0, duration: this.duration, afterFinish: switchCallback };
			new Effect.Opacity(this.element, effectAttributes);
		}

		this.count += 1;
	},
	_updateText: function(data) {
		if (!data)
			return;

		var titleNode = this.element.select('#slide_title')[0];
		var descNode = this.element.select('#slide_desc')[0];

		if (titleNode)
			titleNode.update(data["title"]);
//		titleNode.update(data["title"].stripTags().truncate(22));

		if(descNode)		
	       	descNode.update(data["desc"]);
	       	//descNode.update(data["desc"].stripTags());
	}
});
