/**************************************************************
	Script		: The Nice Slider
	Version		: 0.1
	Authors		: Carlos garcia
	Desc		: Slides a layer in and out.
	Licence		: Open Source MIT Licence
**************************************************************/
var theNiceSlider = new Class({
	startUp:function(){
		this.myDivs = $$('.categoriaFlotar');
		var theSlides = [];
		var clicked = false;
		var hasChanged = false;
		this.myDivs.each(function(div){
			var someSlide = new Fx.Slide(div,{mode: 'horizontal'});
			someSlide.hide();
			theSlides.push(someSlide); 
		});
		this.mySlides = theSlides;
		this.citem = 0;
		this.isInside = false;
		this.theWidth = document.documentElement.clientWidth;
		/* startup of the floating divisions for location and widths */
		this.baseWidth = 990;
		this.newWidth = Math.round((this.theWidth - this.baseWidth)/2-3) + "px";
		$('categoriaOcultador').setStyle('width',this.newWidth);
		$('categoriaContenedor').setStyle('left',this.newWidth);
	},
	setTheItems:function(items){
		var theItems = [];
		for(var i=0; i < items.length; i++) theItems.push(items[i]);
		this.myItems = theItems;
	},
	doFadeIn:function(index){
		if(this.clicked){
			$('categoriaFlotar').innerHTML = this.myItems[index];
			this.mySlides[0].slideIn();
			this.isInside = true;
			this.clicked = false;
		}
	},
	doFadeOut:function(index){
		$clear(this.myTimer);
		this.mySlides[0].slideOut();
		this.isInside = false;
	},
	change:function(index){
		if(this.clicked && this.isInside){
			if(this.citem != index/2) {
				this.doFadeOut(index/2);
			}
		}
		if(!this.clicked && !this.isInside){
			if(this.citem == index/2) {
				this.clicked = true;
				this.doFadeIn(index/2);
			}
		}
	},
	showThisDiv:function(index){
		if(!(index%2) || index == 0) {
			this.doFadeIn.delay(100,this,index/2);
			this.hasChanged = true;
			this.myTimer = this.doFadeOut.delay(9000,this,index/2);
		}
		this.citem = index/2;
	}
});

