var thisTimer;
var newTimer;
var testTimer;

var delayTimer = 5000;

function simpleSlideInit(){
	if($('switchholder')){
		var allofthem = $$('.switch');
		var mycounter = 1;
		allofthem.each(function(e){
			e.setProperty('id','info_homey'+mycounter);
			mycounter++;
		});
		$('switchholder').addEvent('load',thisTimer = function(s){
			for(var i =0;i < allofthem.length;i++){
				var e = allofthem[i];
				if(e.getStyle('display') == 'block'){
					var nexty = i + 2;
					if(nexty > allofthem.length){
						nexty = Number(1);
					}
					var showthis = 'info_homey' + String(nexty);
					e.fade('out');

					(function(){ e.setStyle('display','none'); }).delay(400);
					(function(){
						$(showthis).setStyles({ opacity:0,display:'block'});
						$(showthis).fade('in');
					}).delay(400);

					break;
				}
			}
		}.periodical(delayTimer));

	}
}

// modified for motorfist... do not copy!
var limitedScrollControls = new Class({
	Implements: [Options],

	options: {
		'backdiv': 		'',
		'forwarddiv': 		'',
		'scrollholder': 	'',
		'scrolls_selector': 	'',
		'size': 		1024,
		'leftortop': 		'left',
		'controlsholder': 	'',
		'activeclassname': 	'active',
		'inactiveclassname': 	'inactive',
		'fade': 		true,
		'fadeamt':	 	0.3,
		'transition': 		'sine:in:out', //linear, quad, cubic, quart, quint, pow, expo, circ, sine, back, bounce, elastic
		'transitiontime': 	500,
		'periodical':		8000
	},
	'classtimer': null,
	'ismoving': false,
	'count': 0,
	initialize: function(options) {
		this.setOptions(options);
		if(this.options.backdiv){
			this.count = $$(this.options.scrolls_selector).length;
			if(this.count > 1){
				for(var i=this.count;i>=1;i--){
					new Element('a',{'href':'#','id':'control_'+i,'class':((i == 1) ? this.options.activeclassname : this.options.inactiveclassname)+' rotatenumber','text':i}).inject(this.options.controlsholder);
				}
				this.options.backdiv.setStyle('display','block');
				this.options.backdiv.setStyle('opacity',0);
				this.options.forwarddiv.setStyle('display','block');
				var counter = 0;
				$$(this.options.scrolls_selector).each(function(el){
					el.setStyle(this.options.leftortop,(this.options.size*counter));
					el.setStyle('display','block');
					counter++;
				},this);
				this.options.forwarddiv.addEvent('click',this.moveforward.pass([1,true],this));
				this.options.backdiv.addEvent('click',this.movebackward.pass([1,true],this));
				$$('.'+this.options.activeclassname+', .'+this.options.inactiveclassname).each(function(el){
					el.addEvent('click',function(ev){
						ev.stop();
						if(!el.hasClass(this.options.activeclassname)){
							var num = this.options.controlsholder.getFirst('.'+this.options.activeclassname).getProperty('id').substring(8) - el.getProperty('id').substring(8);
							if(num > 0){
								this.movebackward(num,true);
							}
							else{
								this.moveforward(Math.abs(num),true);
							}
						}
					}.bindWithEvent(this));
				},this);
				this.options.forwarddiv.addEvent('load',this.classtimer = function(ev){
					if(this.options.forwarddiv.getStyle('opacity') == '0'){
						this.movebackward((this.count-1),false);
					}
					else{
						this.moveforward(1,false);
					}
				}.periodical(this.options.periodical,this),this);
			}
		}
	},
	activate: function(element) {
		element.removeClass(this.options.inactiveclassname);
		element.addClass(this.options.activeclassname);
	},
	inactivate: function(element) {
		element.removeClass(this.options.activeclassname);
		element.addClass(this.options.inactiveclassname);
	},
	moveforward: function(number,cleartimer){
		if(cleartimer == true){
			clearInterval(this.classtimer);
		}
		if(this.ismoving == false){
			if($(this.options.controlsholder).getFirst('.'+this.options.activeclassname) == $(this.options.controlsholder).getFirst()){
				return false;
			}
			this.ismoving = true;
			$(this.options.backdiv).setStyle('display','block').fade('in');
			var x = 1;
			var nexts;
			$$('.'+this.options.activeclassname).each(function(el){
				this.inactivate(el);
				nexts = el.getAllPrevious();
			},this);
			if(nexts.length != 0){
				this.activate(nexts[(number-1)]);
				if(nexts.length == number){
					$(this.options.forwarddiv).fade('out');
				}
			}
			$$(this.options.scrolls_selector).each(function(el){
				var newFX = new Fx.Tween(el,{	'transition':this.options.transition,'duration':this.options.transitiontime	}).start(this.options.leftortop,(el.getStyle(this.options.leftortop).toInt()-(this.options.size*number)));
				if(this.options.fade == true && (el.getStyle(this.options.leftortop).toInt()-(this.options.size*number)) != 0){
					el.fade(this.options.fadeamt);
				}
				else if(this.options.fade == true){
					el.fade('in');
				}
				newFX.addEvent('complete',function(){
					this.ismoving = false;
				}.bindWithEvent(this));
			},this);
		}
		return false;
	},
	movebackward: function(number,cleartimer){
		if(cleartimer == true){
			clearInterval(this.classtimer);
		}
		if(this.ismoving == false){
			if($(this.options.controlsholder).getLast('.'+this.options.activeclassname) == $(this.options.controlsholder).getLast()){
				return false;
			}
			this.ismoving = true;
			$(this.options.forwarddiv).setStyle('display','block').fade('in');
			var counter = 0;
			var prevs;
			$$('.'+this.options.activeclassname).each(function(el){
				this.inactivate(el);
				prevs = el.getAllNext();
			},this);
			if(prevs.length != 0){
				this.activate(prevs[(number-1)]);
				if(prevs.length == number){
					$(this.options.backdiv).fade('out');
				}
			}
			$$(this.options.scrolls_selector).each(function(el){
				var newFX = new Fx.Tween(el,{	'transition':this.options.transition,'duration':this.options.transitiontime	}).start(this.options.leftortop,(el.getStyle(this.options.leftortop).toInt()+(this.options.size*number)));
				if(this.options.fade == true && (el.getStyle(this.options.leftortop).toInt()+(this.options.size*number)) != 0){
					el.fade(this.options.fadeamt);
				}
				else if(this.options.fade == true){
					el.fade('in');
				}
				newFX.addEvent('complete',function(){
					this.ismoving = false;
				}.bindWithEvent(this));
			},this);
		}
		return false;
	}
});
