var timerScroll;

function stopScroll(evnt){
	obj = Event.element(evnt);
	$(obj.getAttribute('scroll')).velocidad = 1;
	clearTimeout(timerScroll)
}

function acelerarScroll(evnt){
	obj = Event.element(evnt);
	$(obj.getAttribute('scroll')).velocidad = 3;
}

function frenarScroll(evnt){
	obj = Event.element(evnt);
	$(obj.getAttribute('scroll')).velocidad = 1;
}

function scroll(scrollName, direccion){
	anchoScroll = $(scrollName).offsetWidth;
	anchoCont = $(scrollName + 'Cont').offsetWidth;
	altoScroll = $(scrollName).offsetHeight;
	altoCont = $(scrollName + 'Cont').offsetHeight;
	velocidad = $(scrollName).getAttribute('velocidad');	
	mov = parseInt(1) + parseInt(velocidad);
	switch(direccion){
		case 'derecha' :			
			$(scrollName + 'Cont').style.left = parseInt(parseInt($(scrollName + 'Cont').style.left) - mov) + 'px';	
			if (parseInt($(scrollName + 'Cont').style.left) > parseInt(anchoScroll - anchoCont)){
				timerScroll = setTimeout(function(){
					scroll(scrollName, direccion);
				}, 10);
			}else{
				
				$(scrollName + 'Cont').style.left = parseInt(anchoScroll - anchoCont);
			}
			break;
		case 'izquierda':
			$(scrollName + 'Cont').style.left = parseInt(parseInt($(scrollName + 'Cont').style.left) + mov) + 'px';	
			if (parseInt($(scrollName + 'Cont').style.left) < 0){
				timerScroll = setTimeout(function(){
					scroll(scrollName, direccion);
				}, 10);
			}else{
				$(scrollName + 'Cont').style.left = 0;
			}
			break;
		break;
		case 'arriba':
			$(scrollName + 'Cont').style.top = parseInt(parseInt($(scrollName + 'Cont').style.top) + mov) + 'px';	
			if (parseInt($(scrollName + 'Cont').style.top) < 0){
				timerScroll = setTimeout(function(){
					scroll(scrollName, direccion);
				}, 10);
			}else{
				$(scrollName + 'Cont').style.top = 0;
			}
			break;
		break;
		case 'abajo':
			$(scrollName + 'Cont').style.top = parseInt(parseInt($(scrollName + 'Cont').style.top) - mov) + 'px';	
			if (parseInt($(scrollName + 'Cont').style.top) > parseInt(altoScroll - altoCont)){
				timerScroll = setTimeout(function(){
					scroll(scrollName, direccion);
				}, 10);
			}else{				
				$(scrollName + 'Cont').style.top = parseInt(altoScroll - altoCont);
			}
			break;	
		break;		
	}
}


function initScroll(evnt){
	obj = Event.element(evnt);
	scroll(obj.getAttribute('scroll'), obj.getAttribute('direccion'));
}

function initScrolls(){
	listZoom = $$("a.controlScroll");
	listZoom.each(function(element,indx){
		Event.observe(element,"mouseover",initScroll);
		Event.observe(element,"mouseout", stopScroll);
		Event.observe(element, "mousedown", acelerarScroll);
		Event.observe(element, "mouseup", frenarScroll);
	});
}

Event.observe(window,"load",initScrolls);