/*
       mapb_scroll
       0.2
       09/07/2001
*/

var NN = (document.layers)? true : false;
var hideName = (NN ? 'hide' : 'hidden');
var showName = (NN ? 'show' : 'visible');
var theX,theY;
var mostrat = false;

function mapbScroll (){
    this.scrollbody = 'scrollbody';
    this.scrollUp = 'scrollUp';
    this.scrollDown = 'scrollDown';
    this.scrollLayout = 'scrollOut';
    this.scrollLayer = 'scrollIn';
    this.pixelsToScroll = 30;
    this.LonMove =  new refL(this.scrollLayout,'');
    this.LtoMove =  new refL(this.scrollLayer,this.scrollLayout);
    this.whatStep = 1;
    this.theSpeed = 100;
    
    this.scrollObj = new Object ();
    this.scrollObj.calculIncrement = calculIncrement;
    this.firstInt = 0;
    
    this.puja = puja;
    this.mou = mou;
    this.deixa = deixa;
    this.calculMov = calculMov;
    this.calculsteps = calculsteps;
    this.activateMapbScroll = activateMapbScroll;
}

function activateMapbScroll (){
    if (this.LonMove.theHeight < this.LtoMove.inHeight){
	this.scrollUp = new refL(this.scrollUp,'');
	this.scrollDown = new refL(this.scrollDown,'');
	lullobert = new refL('ullobertLayer','');
	lulltancat = new refL('ulltancatLayer','');
	showL (this.scrollUp);
	showL (this.scrollDown);
	showL (lullobert);
	showL (lulltancat)
    }
}

function puja (whatThis,up){
    if ((up && -(this.LtoMove.theTop) < (this.LtoMove.inHeight - this.LonMove.theHeight)) || (!up && this.LtoMove.theTop < 0)){
	this.currentImg = (!up)? new refL('scrollUpImg',this.scrollUp.theName): new refL('scrollDownImg',this.scrollDown.theName);
	this.currentImg.originalSrc = this.currentImg.myRef.src
	this.currentImg.myRef.src = (up)? this.upaltimg : this.downaltimg;
	this.mou (up,this.pixelsToScroll);
	this.theInterval = setInterval (whatThis + '.mou (' + up + ',' + this.pixelsToScroll + ')',this.theSpeed)
    }
}

var theObj;

function mou (up,pxToScroll){
    this.calculMov (up,pxToScroll);
    if ((up && -(this.LtoMove.theTop) < (this.LtoMove.inHeight - this.LonMove.theHeight)) || (!up && this.LtoMove.theTop < 0)){
	this.newpixelsToScroll = (this.a < pxToScroll)? this.a : pxToScroll;
	this.newpixelsToScroll = (!up)? this.newpixelsToScroll: -(this.newpixelsToScroll);
	this.LtoMove.theTop = this.LtoMove.theTop + this.newpixelsToScroll;
	moveIt (this.LtoMove.myRef,0,this.LtoMove.theTop);
	this.scrollObj.aStep = (up)? this.scrollObj.nStep : -(this.scrollObj.nStep);
    }
    this.lastAction = 'click'
}

function calculMov (up,pxToScroll){
    if (up){
	this.a = (this.LtoMove.inHeight + this.LtoMove.theTop) - this.LonMove.theHeight;
	this.calculsteps (this.a,pxToScroll);
    } else {
	this.a = -(this.LtoMove.theTop);
	this.calculsteps (this.a,pxToScroll);
    }
}

function deixa (up){
    if (this.lastAction == 'click'){
	if ((up && -(this.LtoMove.theTop) <= (this.LtoMove.inHeight - this.LonMove.theHeight)) || (!up && this.LtoMove.theTop <= 0)){
	    this.currentImg.myRef.src = this.currentImg.originalSrc;
	}
	clearInterval (this.theInterval);
    }
    this.lastAction = 'nothing'
}

function showL(theObj) {
    if (document.layers){
	theObj.myRef.visibility = showName
    } else {
	theObj.myRef.style.visibility = showName
    }
}

function showObject(theObj) {
    if (document.layers){
	theObj.visibility = showName
    } else {
	theObj.style.visibility = showName
    }
}

function hideObject(theObj) {
    if (document.layers){
	theObj.visibility = hideName
    } else {
	theObj.style.visibility = hideName
    }
}

function moveIt (whatMove,theX,theY){
     if (document.all) {
        whatMove.style.visibility = 'hidden';
        whatMove.style.top = parseInt(theY);
        whatMove.style.left = parseInt(theX);
        whatMove.style.visibility = 'visible';
     } else if (document.getElementById) {
        whatMove.style.top = theY + 'px';
        whatMove.style.left = theX + 'px';
     } else if (document.layers) {
        whatMove.top = theY;
        whatMove.left = theX;
     }
}

function canviadalt (lobjecte,lamplada,noudalt){
	if (!mostrat){
    	if (document.getElementById) {
        	lobjecte.style.overflow = 'visible';
     	}  else if (document.all) {
        	lobjecte.style.overflow = 'visible';
    	} else if (document.layers) {
        	lobjecte.resizeTo (lamplada,noudalt);
    	}
		mostrat = !mostrat
	} else {
    	if (document.getElementById) {
        	lobjecte.style.overflow = 'hidden';
     	}  else if (document.all) {
        	lobjecte.style.overflow = 'hidden';
    	} else if (document.layers) {
        	lobjecte.resizeTo (lamplada,noudalt);
    	}
		mostrat = !mostrat
	}
}

function refL(aObject,aLayout) {
    this.theName = aObject;
    if (document.getElementById) {
	this.myRef = document.getElementById(aObject);
	this.theTop = parseInt(this.myRef.style.top);
	this.theLeft = parseInt(this.myRef.style.left);
	this.theHeight = parseInt(this.myRef.style.height);
	this.theWidth = parseInt(this.myRef.style.width);
	this.inHeight = parseInt(this.myRef.offsetHeight);
	this.inWidth = parseInt(this.myRef.offsetWidth);
	this.theRight = parseInt(this.myRef.style.left) + parseInt(this.myRef.style.width);
	this.theBottom = parseInt(this.myRef.style.top) + parseInt(this.myRef.style.height)
    } else if (document.layers){
	if (aLayout != ''){
	    this.myRef = eval ('document.layers[aLayout].document.' + aObject);
	} else {
	    this.myRef = eval ('document.' + aObject);
	}
	this.theTop = this.myRef.y;
	this.theLeft = this.myRef.x;
	this.theHeight = this.myRef.height || this.myRef.clip.height;
	this.theWidth = this.myRef.width || this.myRef.clip.width;
	this.theRight = this.myRef.x + this.theWidth;
	this.inHeight = this.theHeight;
	this.inWidth = this.theWidth;
	this.theBottom = this.myRef.y + this.theHeight
    } else if (document.all){
	this.myRef = eval ('document.all.' + aObject);
	this.theTop = parseInt(this.myRef.style.top);
	this.theLeft = parseInt(this.myRef.style.left);
	this.theHeight = parseInt(this.myRef.style.height);
	this.theWidth = parseInt(this.myRef.style.width);
	this.theRight = parseInt(this.myRef.style.left) + parseInt(this.myRef.style.width);
	this.inHeight = parseInt(this.myRef.offsetHeight);
	this.inWidth = parseInt(this.myRef.offsetWidth);
	this.theBottom = parseInt(this.myRef.style.top) + parseInt(this.myRef.style.height)
    }
}

function calculsteps (a,b){	
	a = parseInt(a);
	theModulus = a % b;
	if (theModulus == 0){
	    this.steps = a / b;
	    this.nStep = b;
	    this.lStep = b
	} else {
	    this.steps = (Math.floor (a / b)) + 1;
	    x = (Math.floor (a / b)) * b;
	    this.nStep = (a / x);
	    x = (a - x);
	    this.lStep = (x)
	}
}

function calculIncrement (a,b){	
	a = parseInt(a);
	theModulus = a % b;
	if (theModulus == 0){
	    this.nStep = a / b;
	    this.lStep = a / b
	} else {
	    this.nStep = (Math.floor (a / b));
	    x = (this.nStep + theModulus);
	    this.lStep = (x)
	}
}


