var SlideShow = new Class({
	
	name: null,
	speed: null,
	params: null,
	
	current: 0,
	totWidth:0,
	positions: null,
	infoPos: null,
	intvl:null,
	
	initialize: function(args){
		this.speed = args.speed || 5;
		this.name = args.name || 'gallery';
		this.params = args.params || {};	
		
		this.positions = [];
		this.infoPos = [];	
		
		var slides = $('#'+this.name+'_slides .slide');
		
		for(var i=0; i<slides.length; i++) {
			this.positions[i]= this.totWidth;
			this.infoPos[i] = this.params.info_width * i;
			this.totWidth += $(slides[i]).width();
		}
		
		
		$('#'+this.name+'_slides').width(this.totWidth);
		$('#'+this.name+'_slide_info').width(this.params.info_width*this.positions.length);
		
		var me = this;
		
		$('#'+this.name+'_next').click(function(e){
			me.next(false);
			e.preventDefault();
		});
		$('#'+this.name+'_prev').click(function(e){
			me.prev(false);
			e.preventDefault();
		});
		
		$('#'+this.name+'_more').click(function(e){
			me.goto();
			e.preventDefault();
		});
	
		if (this.positions.length > 1 && this.params.autorun) {
			this.intvl = setInterval(function(){me.next(true)},this.speed*1000);
		}
		
	},
	
	goto: function() {
		var s = $('#'+this.name+'_slide_info .slide')[this.current];
		var target = s.getElementsByTagName('div')[0];
		var link = target.innerHTML;
		document.location = link.split("&amp;").join("&");
	},
	
	showSlide: function() {
		$('#'+this.name+'_slides').stop().animate({marginLeft:-this.positions[this.current]+'px'},450);
		$('#'+this.name+'_slide_info').stop().animate({marginLeft:-this.infoPos[this.current]+'px'},450);
	},
	
	next: function(keepScroll) {			
		this.current++;
		if (this.current>this.positions.length-1) this.current = 0;
		this.showSlide();
		if(!keepScroll) clearInterval(this.intvl);
	},
	
	prev: function(keepScroll) {
		this.current--;
		if (this.current<0) this.current = this.positions.length-1;
		this.showSlide();
		if(!keepScroll) clearInterval(this.intvl);
	}
	
	
});
