var BarackSlideshow2 = new Class({
	  
	  Extends: Fx.MorphList2,
	  
	  options: {
		
	    onShow: 1,
		namesite : '',
	    auto: false,
	    autostart: false,
	    autointerval: 4000,
	    transition: 'fade',
	    tween: { duration: 700 },
		namepage : [''],
		id: null,
		useHistory: false
	  },
	  
	  initialize: function(menu, images, loader, options){
		var vectorpage=new Array();
		$$('#'+menu+' li').each(function(element,i){vectorpage[i]='item_'+i});
		this.options.namepage=vectorpage;
	    this.parent(menu, options);
	    this.images = $(images);
	    if (this.images != null)
	    	this.imagesitems = this.images.getChildren().fade('hide');
	    if ($(loader) != null)
	    	$(loader).fade('in');
	    if (this.images != null){
	    	new Asset.images(this.images.getElements('img').map(function(el) { return el.setStyle('display', 'block').get('src'); }), { onComplete: function() {
	    	this.loaded = true;      
	        if ($(loader) != null)
	    	$(loader).fade('out');
	      if (this.current) this.show(this.items.indexOf(this.current));
	      else if (this.options.auto && this.options.autostart) this.progress();
	    }.bind(this) });
	    }
	    if ($type(this.options.transition) != 'function') this.options.transition = $lambda(this.options.transition);
		
		if (this.options.useHistory) {
			this.history = HistoryManager.register( 
				'Page',
				[0],
				function(values) {
					var ind = values;
					for (i=0; i<this.options.namepage.length; i++){if(this.options.namepage[i]==values){ind=i;}}
				    this.show(ind);
				}.bind(this),
				false,

				false
			);
		}
	  },
	  
	  auto: function(){
	    if (!this.options.auto) return false;
	    $clear(this.autotimer);
	    this.autotimer = this.progress.delay(this.options.autointerval, this);
	  },
	  			
	  onClick: function(event, item){
		this.options.auto=false;
	    this.parent(event, item);
	    event.stop();
	    this.show(this.items.indexOf(item));
	    $clear(this.autotimer);
	  },
	  
	  show: function(index) {
	  
		$('title-enter').innerHTML=this.items[index].title;
		/*$('background').innerHTML='<span>'+this.items[index].title+'</span>';*/
		for (i=0; i<this.options.namepage.length; i++){if(index!=i){$("item_"+i).removeClass('active');}else{$("item_"+i).addClass('active');}}
		if (this.history) this.history.setValue(0,this.options.namepage[index]);
		/*document.title=this.options.namesite+" : "+this.options.namepage[index];*/
		
	    if (!this.loaded) return;
	    var image = this.imagesitems[index];   

			if (image == this.curimage) return;
	    image.set('tween', this.options.tween).dispose().inject(this.curimage || this.images.getFirst(), this.curimage ? 'after' : 'before').fade('hide');
			image.getElement('div').setStyle('display', 'block');
	    var trans = this.options.transition.run(null, this).split('-');
	    switch(trans[0]){
	      case 'slide': 
	        var dir = $pick(trans[1], 'left');
	        var prop = (dir == 'left' || dir == 'right') ? 'left' : 'top';
	        image.fade('show').setStyle(prop, image['offset' + (prop == 'left' ? 'Width' : 'Height')] * ((dir == 'bottom' || dir == 'right') ? 1 : -1)).tween(prop, 0); 
	        break;
	      case 'fade': image.fade('in'); break;
	    }
	    image.get('tween').chain(function(){ 
	      this.auto();
	      this.fireEvent('show', image); 
	    }.bind(this));
	    this.curimage = image;
	    this.setCurrent(this.items[index])
	    this.morphTo(this.items[index]);
			return this;
	  },
	  
	  progress: function(){
	    var curindex = this.imagesitems.indexOf(this.curimage);
	    this.show((this.curimage && (curindex + 1 < this.imagesitems.length)) ? curindex + 1 : 0);
	  }
	  
	});
