var periodical;
var botrotate = new Class({
	
	options: {
	},
	
	initialize: function(elements, options){
		//STORE THE ID
			this.elements = elements;

		//this.setOptions(options);
		this.createRotate();
	},
	
	createRotate: function(){
		//ADD THE CLASS FOR CSS
			//$(this.elements).addClass("botrotate");
		//COUNT OUR SLIDES
			this.slide_count = $$("div.slide");
		//SET OUR TRACKING VARS
			this.current = 0;
			this.next = 1;
		//HIDE ALL OF OUR IMAGES
			$$("div.image img").each(function(el){
				el.setStyles({
					"display":"none"
				});
			});
		//
			$("image-0").setStyle("display", "block");
		//HIDE ALL OF OUR TEXT
			$$("div.text").each(function(el){
				el.setStyles({
					"display":"none"
				});
			});
			$("text-0").setStyles({
				"display":"block"
			});
		//
			$("button-0").addEvent("mouseover", function(e){
				$clear(periodical);
				if(this.current!=0){
					this.next = 0;
					this.rotate(true);
				}
			}.bind(this));
			
			$("button-1").addEvent("mouseover", function(e){
				$clear(periodical);
				if(this.current!=1){
					this.next = 1;
					this.rotate(true);
				}
			}.bind(this));
			
			$("button-2").addEvent("mouseover", function(e){
				$clear(periodical);
				if(this.current!=2){
					this.next = 2;
					this.rotate(true);
				}
			}.bind(this));
			
			$("button-3").addEvent("mouseover", function(e){
				$clear(periodical);
				if(this.current!=3){
					this.next = 3;
					this.rotate(true);
				}
			}.bind(this));
			
			$("button-4").addEvent("mouseover", function(e){
				$clear(periodical);
				if(this.current!=4){
					this.next = 4;
					this.rotate(true);
				}
			}.bind(this));
		//
			periodical = this.rotate.periodical((1000*5), this);
	},
	
	rotate: function(but){
		//HIDE OUR CURRENT IMAGE
			$("text-"+this.current).setStyles({
				"opacity":0
			});
			if($("image-"+this.current).fx){
				$("image-"+this.current).fx.stop();
			}
			var fadeout_image = $("image-"+this.current).effects({duration: 250, transition: Fx.Transitions.Quart.easeOut});
			fadeout_image.start({
				'opacity': 0
			});
			if($("text-"+this.current).fx){
				$("text-"+this.current).fx.stop();
			}
			var fadeout_text = $("text-"+this.current).effects({duration: 250, transition: Fx.Transitions.Quart.easeOut});
			fadeout_text.start({
				'opacity': 0
			});
		//SHOW OUR CURRENT IMAGE
			$("image-"+this.next).setStyles({
				"display":"block",
				"opacity":0
			});	
			$("text-"+this.next).setStyles({
				"display":"block",
				"opacity":0
			});
			if($("image-"+this.next).fx){
				$("image-"+this.next).fx.stop();
			}
			var fadein_image = $("image-"+this.next).effects({duration: 250, transition: Fx.Transitions.Quart.easeIn});		
			fadein_image.start({
				'opacity': 1
			});
			if($("text-"+this.next).fx){
				$("text-"+this.next).fx.stop();
			}
			var fadein_text = $("text-"+this.next).effects({duration: 250, transition: Fx.Transitions.Quart.easeIn});		
			fadein_text.start({
				'opacity': 1
			});
		//
			$("slide-"+this.current).setStyle("z-index", 0);
			$("button-"+this.current).removeClass("selected");
			$("slide-"+this.next).setStyle("z-index", 1);
			$("button-"+this.next).addClass("selected");
			if(but){
				this.current = this.next;
			}else{
				//
				//
					if(this.current < 4){
						this.current++;
					}else{
						this.current = 0;
					}
				//
					if(this.next < 4){
						this.next++;
					}else{
						this.next = 0;
					}
			}
	}
});

