function scrollLeft() {
	if (numberLayers > numberVisible) {
        for (i=1; i<=numberLayers; i++) {
		  theDiv = MM_findObj( "layer" + i );

		  if ( theDiv == null ) {
			 return;
		  }

		  position = ((i - 1) * 150) - toMove;
		  if (position <= minPosition) {
			 position = position + (numberLayers * 150);
		  }
		  if (position > maxPosition) {
			 position = position - (numberLayers * 150);
		  }

		  if ((position > maxPosition) || (position <= minPosition)) {
			 theDiv.style.left = "-150px";
			 theDiv.style.visibility = "hidden";
		  } else {
			 theDiv.style.left = position + "px";
			 theDiv.style.visibility = "visible";
			 theDiv.style.clip = "rect(0px 150px 100px 0px)";
			 if (position < 0) {
				    theDiv.style.clip = "rect(0px 150px 100px " + (0 - position) + "px)";
			 }
			 if (position > (scrollWidth - 150)) {
				    theDiv.style.clip = "rect(0px " + (scrollWidth - position) + "px 100px 0px)";
			 }
		  }
	   }

	   toMove += toMoveIncrement;

	   if (toMove < maxToMove) {
		  timerID = setTimeout("scrollLeft()", 30);
	   } else {
		  toMove = 0;
		  timerID = setTimeout("scrollLeft()", 30);
	   }
    }
}

function scrollRight() {
    if (numberLayers > numberVisible) {
	   for (i=1; i<=numberLayers; i++) {
		  theDiv = MM_findObj( "layer" + i );

		  if ( theDiv == null ) {
			 return;
		  }

		  position = ((i - 1) * 150) - toMove;
		  if (position > maxPosition) {
			 position = position - (numberLayers * 150);
		  }
		  if (position <= minPosition) {
			 position = position + (numberLayers * 150);
		  }

		  if ((position > maxPosition) || (position <= minPosition)) {
			 theDiv.style.left = "-150px";
			 theDiv.style.visibility = "hidden";
		  } else {
			 //Set position.
			 theDiv.style.left = position + "px";
			 theDiv.style.visibility = "visible";
			 theDiv.style.clip = "rect(0px 150px 100px 0px)";
			 if (position < 0) {
				    theDiv.style.clip = "rect(0px 150px 100px " + (0 - position) + "px)";
			 }
			 if (position > ((numberVisible - 1) * 150)) {
				    theDiv.style.clip = "rect(0px " + (scrollWidth - position) + "px 100px 0px)";
			 }
		  }
	   }

	   toMove -= toMoveIncrement;

	   if (toMove > -maxToMove) {
		  timerID = setTimeout("scrollRight()", 30);
	   } else {
		  toMove = 0;
		  timerID = setTimeout("scrollRight()", 30);
	   }
    }
}

function changeToRight() {
	if (numberLayers > numberVisible) {
        direction = "Right";
	    timerID = clearTimeout(timerID);
	    scrollRight();
    }
}

function changeToLeft() {
	if (numberLayers > numberVisible) {
        direction = "Left";
	    timerID = clearTimeout(timerID);
	    scrollLeft();
    }
}

function stopScroll() {
	if (numberLayers > numberVisible) {
        timerID = clearTimeout(timerID);
    }
}

function continueScroll() {
	if (direction == "Right") {
		scrollRight();
	} else {
		scrollLeft();
	}
}

function initialiseScroller() {
	mainDiv = MM_findObj("scroller");
	mainDiv.style.display = "block";

    if (numberLayers <= numberVisible) {
       for (i=1; i<=numberLayers; i++) {
          layerDiv = MM_findObj( "layer" + i );
		  layerDiv.style.position = "relative";
       }
    } else {
	   for (i=1; i<=numberLayers; i++) {
		  layerDiv = MM_findObj( "layer" + i );
		  layerDiv.style.position = "absolute";
		  layerDiv.style.left = "0px";
		  layerDiv.style.top = "0px";
		  layerDiv.style.visibility = "hidden";
	   }
    }
}