var	bucle = 0 ;
var ti ;
var inc = 1;//14 ;
var timer = 5 ;
var min_scroll = 33 ;
var drag_scroll ;
var drag_pos ;
var pos_anterior ;
var isExplorer = (navigator.appName.search("Explorer") > 0) ;

	function doScroll(strScroll, tics) { 
		Scroll     = document.getElementById(strScroll) ;
		Div        = Scroll.asoc ;

		Scroll.acttics += tics ;
		if (Scroll.acttics < 0)					Scroll.acttics = 0 ;
		if (Scroll.acttics > Scroll.maxtics)	Scroll.acttics = Scroll.maxtics
		Scroll.actpos  = (Scroll.acttics * Scroll.factor) ;
		Scroll.style.top  = Math.round(Scroll.actpos) ;
		Div.style.top     = -Scroll.acttics * inc ;
	}

	function SetScroll(strScroll, nPos) {
		
		if(!(Scroll     = document.getElementById(strScroll))) return ;
		if(!(Div        = Scroll.asoc)) return ;

		if (nPos<0) nPos = 0 ;
		if (nPos>Scroll.maxpos) nPos = Scroll.maxpos ;

		Scroll.actpos  = nPos ;
		Scroll.acttics = Math.round(nPos / Scroll.factor) ;

		Scroll.style.top  = nPos ;
		Div.style.top     = -Scroll.acttics * inc ;
	}

	function ScrollDown(obj, scroll) {
		scroll.maxtics = ( obj.scrollHeight - parseInt(obj.parentNode.style.height) ) / inc ;
		scroll.maxpos  = parseInt(obj.parentNode.style.height) - min_scroll ;

		if (scroll.maxtics<=0) return ;

		bucle = 1 ;
		scroll.factor  = scroll.maxpos / scroll.maxtics ;
		scroll.asoc    = obj ;
		if (!scroll.acttics) scroll.acttics = 0 ;
		if (!scroll.actpos ) scroll.actpos  = 0 ;
		if (bucle)
			ti = setInterval("doScroll('"+scroll.id+"',1)", timer) ;
	}

	function ScrollUp(obj, scroll) {
		scroll.maxtics = ( obj.scrollHeight - parseInt(obj.parentNode.style.height) ) / inc ;
		scroll.maxpos  = parseInt(obj.parentNode.style.height) - min_scroll ;

		if (scroll.maxtics<=0) return ;

		bucle = 1 ;
		scroll.factor  = scroll.maxpos / scroll.maxtics ;
		scroll.asoc    = obj ;
		if (!scroll.acttics) scroll.acttics = 0 ;
		if (!scroll.actpos ) scroll.actpos  = 0 ;
		if (bucle)
			ti = setInterval("doScroll('"+scroll.id+"',-1)", timer) ;
	}

	function StopScroll() { if(bucle) { clearInterval(ti); bucle=0} }

	function StartDragScroll(scroll,obj,e) { 

		scroll.maxtics = ( obj.scrollHeight - parseInt(obj.parentNode.style.height) ) / inc ;
		scroll.maxpos  = parseInt(obj.parentNode.style.height) - min_scroll ;

		if (scroll.maxtics<=0) return ;

		scroll.factor  = scroll.maxpos / scroll.maxtics ;
		scroll.asoc    = obj ;
		if (!scroll.acttics) scroll.acttics = 0 ;
		if (!scroll.actpos ) scroll.actpos  = 0 ;

		drag_scroll = scroll.id ;
		drag_pos = e.clientY - scroll.actpos;

		e.cancelBubble=true ;
		if (isExplorer)
			e.returnValue = false ;
		else
			e.preventDefault();//		e.returnValue = false ;
	}

	function StopDragScroll(e) {
		var s ;
		if (drag_scroll) { 
			s = drag_scroll ;
			drag_scroll=null;
			e.cancelBubble=true ;
			if (isExplorer)
				e.returnValue = false ;
			else
				e.preventDefault();//		e.returnValue = false ;
			document.getElementById("pil_"+s).onmouseout() ;
		}
	}

	function MoveDragScroll(e) {
		if (drag_scroll) {
			movimiento = e.clientY - drag_pos ;
			SetScroll (drag_scroll, movimiento) ;
			e.cancelBubble=true ;
			if (isExplorer)
				e.returnValue = false ;
			else
				e.preventDefault();//		e.returnValue = false ;
		}
	}

	function ScrollPage (Scroll, Div, e) {
		Scroll.maxtics = ( Div.scrollHeight - parseInt(Div.parentNode.style.height) ) / inc ;
		Scroll.maxpos  = parseInt(Div.parentNode.style.height) - min_scroll ;

		if (Scroll.maxtics<=Scroll.maxpos) return ;

		Scroll.factor  = Scroll.maxpos / Scroll.maxtics ;
		Scroll.asoc    = Div ;
		if (!Scroll.acttics) Scroll.acttics = 0 ;
		if (!Scroll.actpos ) Scroll.actpos  = 0 ;

		if ( e.clientY < Scroll.offsetTop) 
			ScrollPageUp(Scroll) ;
		else {
			if ((e.clientY-Scroll.offsetTop) >  min_scroll ) 
				ScrollPageDown(Scroll) ;
		}
	}

	function ScrollPageUp(Scroll) {
		doScroll(Scroll.id, -(Scroll.maxpos+min_scroll)/inc) ;
	}


	function ScrollPageDown(Scroll) {
		doScroll(Scroll.id, (Scroll.maxpos+min_scroll)/inc) ;
	}


	function RefreshScroll(Scroll) {
		if (!document.getElementById("scroll_"+Scroll))
			return ;
		if (!(contenedor = document.getElementById("div_cont_"+Scroll)))
			return ;
		if (!(contenido  = document.getElementById("div_"+Scroll)))
			return ;

		if (contenido.scrollHeight > parseInt(contenedor.style.height)) {
			document.getElementById("scroll_"+Scroll).style.display='inline' ;
			document.getElementById("ab_"+Scroll).style.display    ='inline' ;
			document.getElementById("al_"+Scroll).style.display    ='inline' ;
		}
		else {
			document.getElementById("scroll_"+Scroll).style.display='none' ;
			document.getElementById("ab_"+Scroll).style.display    ='none' ;
			document.getElementById("al_"+Scroll).style.display    ='none' ;
		}
		SetScroll("scroll_"+Scroll,0) ;
	}
