var ASlide = new Class({
	Implements: [Options,Events],
	options: {
		showControls: false,
		showDuration:4000,
		showTOC: true,
		tocWidth: 20,
		tocClass: 'toc',
		tocActiveClass: 'toc-active',
		onChange:$empty()
	},
	initialize: function(container,elements,options) {
		this.setOptions(options);
		//settings
		this.container = $(container);
		this.elements = $$(elements);
		this.currentIndex = 0;
		this.interval = '';
		if(this.options.showTOC) this.toc = [];
		
		/** solo para dulcesorpresa**/
		
		var capa= new Element('div',{
			id:'div__linksACarrusel',
			styles:{
				width:643,
				height:27,
				top:326,
				position:'relative',
				zIndex:4,
				texAlign:'right'
			},
			align:'right'
		});
		
		var interior = new Element('div',{
			align:'right',
			styles:{
				textAlign:'right',
				float :'right'
			}
		}).inject(capa);
		
		/*****/
		var y=0;
		//assign
		var number = "";
		
		this.elements.each(function(el,i){
			y++;
			capa.inject(this.container);
			
			if(this.options.showTOC) {
				
				/***/
				
				var izq = 0;
				
				
				switch(i){
				
					case 0:
						number="uno";
					break;
				
					case 1:
						number="dos";
					break;
				
					case 2:
						number="tres";
					break;
					
					case 3:
						number="cuatro";
					break;
					
					case 4:
						number="cinco";
					break;
					
					case 5:
						number="seis";
					break;
					
					case 6:
						number="siete";
					break;
					
					case 7:
						number="ocho";
					break;
					
				}	
				
				/****/
				
								this.toc.push(new Element('a',{
									id:number,
									html: '',//(i+1),
									href: '#',
									rel:'nofollow',
									'class': this.options.tocClass + '' + (i == 0 ? ' ' + this.options.tocActiveClass+"1" : ''), //modificado para dulce
									//'class': 'toc'+(i+1)+' ' + (i == 0 ? ' ' + 'toc'+(i+1)+'-active' : ''),
									events: {
										click: function(e) {
											if(e) e.stop();
											this.stop();
											this.show(i);
										}.bind(this)
									},
									styles: {
										left: 0+ ((i + 1) * (this.options.tocWidth + izq)) //mpodificado parsa dulce  < ((i + 1) * (this.options.tocWidth + 10)) >
									}
								//}).inject(this.container));
								}).inject(interior));	
			}
			
			if(i > 0) el.set('opacity',0);
			
			
		},this);
		
		if(y==1){capa.hide();};
		
		
		//next,previous links
		if(this.options.showControls) {
			this.createControls();
			
		}
		//events
		this.container.addEvents({
			mouseenter: function() { this.stop(); }.bind(this),
			mouseleave: function() { this.start(); }.bind(this)
		});

	},
	show: function(to) {
	
		
		/*para dulce*/
		
		/**/
		
		
		this.elements[this.currentIndex].set("tween",{duration:800});
		
		//this.elements[this.currentIndex].fade('out');
		this.elements[this.currentIndex].tween('opacity',0);
		
		//if(this.options.showTOC) this.toc[this.currentIndex].removeClass(this.options.tocActiveClass);
		
		
		
		if(this.options.showTOC) this.toc[this.currentIndex].removeClass(this.options.tocActiveClass+(this.currentIndex+1));//solo papa Jonhs
		
		
		
		this.elements[this.currentIndex = ($defined(to) ? to : (this.currentIndex < this.elements.length - 1 ? this.currentIndex+1 : 0))].tween("opacity",1);//.fade('in');
		
		//if(this.options.showTOC) this.toc[this.currentIndex].addClass(this.options.tocActiveClass);
		
		
		this.toc[this.currentIndex].addClass(this.options.tocActiveClass +(this.currentIndex+1));
		
		
		
		//if(this.options.showTOC) this.toc[this.currentIndex].addClass(this.options.tocActiveClass +(this.currentIndex+1)); solo papa Jonhs
		
		this.fireEvent('change');
		
		
	},
	start: function() {
		this.interval = this.show.bind(this).periodical(this.options.showDuration);
	},
	stop: function() {
		$clear(this.interval);
	},
	//"private"
	createControls: function() {
		var next = new Element('a',{
			href: '#',
			id: 'next',
			text: '>>',
			events: {
				click: function(e) {
					if(e) e.stop();
					this.stop(); 
					this.show();
				}.bind(this)
			}
		}).inject(this.container); 
		var previous = new Element('a',{
			href: '#',
			id: 'previous',
			text: '<<',
			events: {
				click: function(e) {
					if(e) e.stop();
					this.stop(); 
					this.show(this.currentIndex != 0 ? this.currentIndex -1 : this.elements.length-1);
				}.bind(this)
			}
		}).inject(this.container); 
	}
});
