var mw_scroll_do_javavar;
mw_scroll_do_javavar = 0;
function mw_scroll(id,scrollamount,scrolltime,horizontal) {
	mw_scroll_do_javavar = 1;
	mw_scrolldo(id,scrollamount,scrolltime,horizontal);
}
function mw_scroll_stop() {
	mw_scroll_do_javavar = 0;
}
function mw_scrolldo(id,scrollamount,scrolltime,horizontal) {
  if ((mw_scroll_do_javavar==1)){
	var obj=fp_get_element_by_id_siexiste(id);
	  if (obj){
		if (horizontal){
			obj.scrollLeft=obj.scrollLeft + scrollamount;
			var horizontaltxt="true";
		}else{
			obj.scrollTop=obj.scrollTop + scrollamount;
			var horizontaltxt="false";
		}
		setTimeout("mw_scrolldo('" + id + "'," + scrollamount + "," + scrolltime + ","+horizontaltxt +")",scrolltime);
	  }
  }
}

function mw_scroll_obj(iddiv,idobj){
    this.iddiv = iddiv;
    this.idobj = idobj;
    this.scrollamountTop = 10;
    this.scrollamountLeft = 0;
	
	
    this.scrolltime = 500;
    this.repetir = true;
    this.stopbyMO = false;
    this.stopbycmd = false;
    this.startonBot = false;
    this.startonRight = false;
    this.alculminar = '';
    this.getscrollHWtime = 500;
    this.getscrollHWmaxintentos = 100;
    this.getscrollHWintentos = 0;
    this.getscrollHWok = false;
    this.getscrollHWokH = false;
    this.getscrollHWokW = false;
	this.scrollstartTop = 0;
    this.scrollstartLeft = 0;

	
	//this.intervalo=setInterval(function(){this.doscroll()},	this.scrolltime);
	this.loaddiv=function(){
		if (this.div = fp_get_element_by_id_siexiste(this.iddiv)){
			
			if (this.getscrollHWtime>0){
				this.getscrollHW();	
			}else{
				this.doscroll();
				this.divok=true;
			}
			
			return true;
		}
	}
	this.getscrollHW=function(){
		if (this.getscrollHWintentos<this.getscrollHWmaxintentos){
			this.getscrollHWintentos+=1;
			this.debugmsgadd(" <B>getscrollHW intento:"+this.getscrollHWintentos+" </B><br>");
			if (this.div.scrollHeight>0){
				if (this.startonBot){
					this.scrollstartTop = this.div.scrollHeight;
					this.div.scrollTop=this.div.scrollHeight;
				}
				this.getscrollHWokH=true;
			}
			if (this.div.scrollWidth>0){
				if (this.startonRight){
   					this.scrollstartLeft = this.div.scrollWidth;;
					this.div.scrollLeft=this.div.scrollWidth;
				}
				this.getscrollHWokW=true;
			}
			if (this.getscrollHWokW){
				if (this.getscrollHWokH){
					 this.getscrollHWok = true;
				}
			}
			
			
			this.debugmsgadd(" T: "+this.div.scrollTop+" L: "+this.div.scrollLeft+" ");
			this.debugmsgadd(" mT: "+this.div.scrollHeight+" mL: "+this.div.scrollWidth+"<br>");
			this.debugmsgwrite();
			if (this.getscrollHWok){
				this.divok=true;
				this.doscroll();
				return true;	
			}else{
				if (this.getscrollHWtime>0){
					setTimeout(this.idobj+".getscrollHW();",this.getscrollHWtime);
				}
			}
		}
	}
	this.doscroll=function(){
		if (this.doscrollok()){
			
			//this.debugmsgadd(" T: "+this.div.scrollTop+" L: "+this.div.scrollLeft+" ");
			//this.debugmsgadd(" mT: "+this.div.scrollHeight+" mL: "+this.div.scrollWidth+"<br>");
			
			
			if (this.scrollamountTop!=0){
				scrollTopactual=this.div.scrollTop;
				this.div.scrollTop=this.div.scrollTop + this.scrollamountTop;
				if(scrollTopactual==this.div.scrollTop){
					if (this.alculminar=="rebotar"){
						this.scrollamountTop=this.scrollamountTop*(-1);
					}else if (this.alculminar=="reiniciar"){
						this.div.scrollTop=this.scrollstartTop;
					}else{
						this.scrollamountTop=0;
					}
					//this.debugmsgadd(" CHOCO TOP<br> ");
				}
			}
			if (this.scrollamountLeft!=0){
				scrollLeftactual=this.div.scrollLeft;
				this.div.scrollLeft=this.div.scrollLeft + this.scrollamountLeft;
				if(scrollLeftactual==this.div.scrollLeft){
					if (this.alculminar=="rebotar"){
						this.scrollamountLeft=this.scrollamountLeft*(-1);
					}else if (this.alculminar=="reiniciar"){
						this.div.scrollLeft=this.scrollstartLeft;
					}else{
						this.scrollamountLeft=0;
					}
					//this.debugmsgadd(" CHOCO LEFT<br> ");
				}
			}
			

			this.debugmsgwrite();
			
			if (this.repetir){
				this.setTimeoutdoscroll();
			}
			
		}
	}
	
	this.setTimeoutdoscroll=function(){
		setTimeout(this.idobj+".doscroll();",this.scrolltime);
	}
	this.setstoponMO=function(){
		this.stopbyMO = true;
	}
	this.setdoonMOUT=function(){
		this.stopbyMO = false;
		this.doscroll();
	}
	this.doscrollok=function(){
		if (this.divok){
			if (!this.stopbycmd){
				if (!this.stopbyMO){
					if((this.scrollamountTop==0)&&(this.scrollamountLeft==0)){
						return false;	
					}
					return true;
				}
			}
		}
		return false;
	}
	this.setdebugmsgdiv=function(debugid){
		this.bebugdiv=fp_get_element_by_id_siexiste(debugid);
		if (this.bebugdiv){
			this.debugmsg="";
			this.debug=true;	
		}
	}
	this.debugmsgwrite=function(){
		if (this.debug){
			this.bebugdiv.innerHTML=this.debugmsg;
		}
	}
	this.debugmsgadd=function(msg){
		if (this.debug){
			this.debugmsg+=msg;
		}
	}
	

}