window.addEvent('domready', function(){
	var thide=0;
	if ($('leftarrow')) {
		if ($('thumbs')) {var scrolldiv = $('thumbs');};
		var txtsizeo = scrolldiv.getScrollSize();
		var divsizeo = scrolldiv.getSize();
		var divsize = divsizeo.x;
		var txtsize = txtsizeo.x;
		var step=0;
		if (txtsize>=divsize) {
			function calcwheel(event){
				event = new Event(event);						
					/* Mousewheel UP */
				if (event.wheel > 0) {
					clearInterval(periodicalmove);
					periodicalmove="";
					clearInterval(periodicalmove2);
					periodicalmove2="";
					moveleft();
				}
					/* Mousewheel DOWN*/
				else if (event.wheel < 0) {
					clearInterval(periodicalmove);
					periodicalmove="";
					clearInterval(periodicalmove2);
					periodicalmove2="";
					moveright();
				}
			}
			function moveleft() {
				step=step-90;
				if (step<20) {step=0;}
				var myFx = new Fx.Scroll(scrolldiv).start(step, 0);	
			}
			function moveright() {
				step=step+90;
				if (step>(txtsize-divsize-20)) {step=txtsize-divsize;}
				var myFx = new Fx.Scroll(scrolldiv).start(step, 0);	
			}
			var periodicalmove;
			var beginup = function() {
				periodicalmove = moveleft.periodical(500);
			}
			var periodicalmove2;
			var begindwn = function() {
				periodicalmove2 = moveright.periodical(500);
			}
			$('leftarrow').addEvents({
				mousedown: function() {
					clearInterval(periodicalmove);
					periodicalmove="";
					clearInterval(periodicalmove2);
					periodicalmove2="";
					moveleft();
					beginup(); 
				},
				mouseup: function() {
					clearInterval(periodicalmove);
					periodicalmove="";
					clearInterval(periodicalmove2);
					periodicalmove2="";
				}
			});
			$('rightarrow').addEvents({
				mousedown: function() {
					clearInterval(periodicalmove);
					periodicalmove="";
					clearInterval(periodicalmove2);
					periodicalmove2="";
					moveright();
					begindwn(); 
				},
				mouseup: function() {
					clearInterval(periodicalmove);
					periodicalmove="";
					clearInterval(periodicalmove2);
					periodicalmove2="";
				}
			});
			scrolldiv.addEvent('mousewheel', calcwheel);
		}
	}
	
	
	
	if ($('carousel')) {
		var thismaxkey=-1;
		var theimgs;
		var theimgarray=[];
		var thisnewkey;
		var thisgalkeyg=0;
		theimgs = $(carousel).getElements('img');	
		Array.each(theimgs, function(theimg, key){
			thismaxkey++
			theimgarray[key]= theimg;
			if (thismaxkey>0) {theimgarray[key].fade('hide');};
						
		});
		function thisnextimage() {
			thisnewkey=thisgalkeyg+1;
			if (thisnewkey>thismaxkey) {thisnewkey=0;};
			theimgarray[thisnewkey].fade('in');
			theimgarray[thisgalkeyg].fade('out');
			thisgalkeyg = thisnewkey;
		}
		var tperiodicalID;
		var tbegin = function() {			
			tperiodicalID = thisnextimage.periodical(4000);
		}
		tbegin();
		
	}
});

