var slideShowUpdater = Class.create({
	initialize: function(id, sliderClass, i, tags) {
		this.id = id;
		this.base = sliderClass;
		this.i = String(i);
		//console.log(tags);
		this.tags = tags;
		this.updating = false;
	},
	update: function(offset, replace){
		this.offset = offset;
		this.replace = replace;
		if(!this.updating) {
			new Ajax.Request('/index.php?type=6&tags='+this.tags+'&offset='+this.offset, {
				method:'get',
				onCreate: function(){
					$('t2cSlideshow'+this.i).down('.loading').setStyle({visibility:'visible'});
					this.updating = true;
				}.bind(this),
				onSuccess: function(transport){
					var response = transport.responseJSON;
					this.updateList(response);
					this.updating = false;
				}.bind(this),
				onFailure: function(error){
					console.log(error);
					this.updating = false;
				}
			});
		}
	},
	updateList: function(response){
		//console.log(response);
		var list = $(this.id);
		var i = 0;
		var l = response.length-1;
		response.each(function(data){
			var listItem = new Element('li');
			var imageBox = new Element('div',{'class':'imgbox'});
			var image = new Element('img',{'src':data.thumb});
			if(data.caption) {
				var textBox = new Element('div',{'class':'text'});
				var caption = new Element('h4').update(data.caption);
				var description = new Element('p').update(data.description);
				textBox.update(caption);
				textBox.insert(description);
			}
			var link = new Element('a',{'href':data.zoom}).update('zoom');
			link.options = (data.options) ? data.options : {};
			link.options.postBody = {'caption':data.caption, 'description':data.description};
			listItem.update(link);
			imageBox.update(image);
			listItem.insert(imageBox);
			listItem.insert(textBox);
			if(this.replace){
				list.update(listItem);
				this.replace=false;
			} else {
				list.insert(listItem);
			}
			link.observe('click', function(evt){
				evt.stop();
				link.zoom = new simpleLayer(link.href, link.options);
			});
			document.observe('simpleLayer:done', function(){
				Cufon.replace('.slideShowImageZoom h3');
			});
			if(i++==l) this.finishLoading();
		}.bind(this));
	},
	finishLoading: function(){
		$(this.id).style.width = $(this.id).offsetWidth + ($$('#'+this.id+' li')[0].offsetWidth*10) + 'px';
		this.base.refresh();
		$('t2cSlideshow'+this.i).down('.loading').setStyle({visibility:'hidden'});
		Cufon.replace('.t2cSlideshow h4', {hover:true});
	}
});