function pageLeft(loopStore,id,once) {

    if ( ELOCKS.get("UI_IS_BUSY") ) {
        debug ( "*********** QUEUE PAGE_LEFT");
        if ( !EBUFFER.get() ) {
            EBUFFER.set("PAGE_LEFT");
        }
        return;
    }

    debug ( "*********** pageLeft UI_IS_BUSY ");
    ELOCKS.set("UI_IS_BUSY");

    if ( $("popup") ) {
        $("popup").style.display ="none";
    }
    if ( $("thumbnail_tooltip") ) {
        $("thumbnail_tooltip").style.display="none";
    }

    if(!loopStore.exists(id)){ //are we active
        ELOCKS.unset("UI_IS_BUSY");
        debug ("------------------- pageLeft unset UI_IS_BUSY 1");
        return false;
    }
    if ($("pageLeftToggle").value == "true") {

        //check for image fetching
        if(areWeInRegularSearch() && SearchAjax.inProgress){
 			leftIndex = getLeftIndex();
			if (!$("img_" + (leftIndex - 20))) {	// Only pause if the images aren't buffered on the next page.
				highlightWait();
	            var new_id = loopStore.getNew();
	            AUTO_BROWSE_TIMEOUT = setTimeout(curry(pageLeft,window,loopStore,new_id,once),250);
                ELOCKS.unset("UI_IS_BUSY");
                debug ("------------------- pageLeft unset UI_IS_BUSY 2");
                return false;
			}
        }
        $("direction").value = "1";

        openToolbarContent.set(0);
	    openToolbarContent.isOpen = false;

        if ($("sxDownload_panel")) {        
            $("sxDownload_panel").style.display = "none";
        }
        openSxDownloadContent.isOpen = false;

		closeFeatureImage();



		windowWidth = ww();

		currentLeft = new Array();
		newLeft = new Array();

		currentLeft[0] = parseInt($("search_results_a").style.left);
		currentLeft[1] = parseInt($("search_results_b").style.left);

		newLeft[0] = Math.floorThumb(currentLeft[0] + windowWidth);
		newLeft[1] = Math.floorThumb(currentLeft[1] + windowWidth);

		//debug("[pageLeft] Calculated newLefts: [" + newLeft[0] + ", " + newLeft[1] + "]");

		offsetA = parseInt($("search_results_a_offset").value);
		offsetB = parseInt($("search_results_b_offset").value);

		/* The way we currently have it set up, A will always be the page at which we start.
		 * We might have to change this later to make things more flexible, but this will work
		 * quite happily for now.
		 */
		if (offsetA == 0) {
			if (currentLeft[0] == 0) {
				stopThrottle();	// we're already there!
                ELOCKS.unset("UI_IS_BUSY");
                debug ("------------------- pageLeft unset UI_IS_BUSY 3");
                return;
			} else if (newLeft[0] >= 0) {
				newLeft[1] -= newLeft[0];
				newLeft[0] = 0;
				moveResultsOverA.lastPage = true;

				moveResultsOverA.start(newLeft[0]);
				moveResultsOverB.start(newLeft[1]);

                var new_id = loopStore.getNew();
                AUTO_BROWSE_TIMEOUT = setTimeout(curry(pageLeft,window,loopStore,new_id,once), USER_PREF_MAP.get("auto_browse_pause"));
                //window.setTimeout("pageLeft()", 3800);  // do we need this call?  probably not.

                ELOCKS.unset("UI_IS_BUSY");
                debug ("------------------- pageLeft unset UI_IS_BUSY 4");
                return;
			}
		}

		//debug("[pageLeft] Moving div_a to " + newLeft[0] + ", and div_b to " + newLeft[1]);

		if (once) {
			moveResultsOverA.manualBrowse = true;
			setLastAction(application.events.MANUAL_BROWSE_LEFT);
		} else {
			moveResultsOverA.manualBrowse = false;
			setLastAction(application.events.AUTO_BROWSE_LEFT + " " + USER_PREF_MAP.get("auto_browse_pause") + "ms");
		}

		moveResultsOverA.start(newLeft[0]);
		moveResultsOverB.start(newLeft[1]);

        if (!once){
            var new_id = loopStore.getNew();
            AUTO_BROWSE_TIMEOUT = setTimeout(curry(pageLeft,window,loopStore,new_id,once), USER_PREF_MAP.get("auto_browse_pause"));
        }

    }
}

function pageRight(loopStore,id,once) {


    if ( ELOCKS.get("UI_IS_BUSY") ) {
        debug ( "*********** QUEUE PAGE_RIGHT");
        if ( !EBUFFER.get() ) {
            EBUFFER.set("PAGE_RIGHT");
        }
        return;
    }

    debug ( "*********** pageRight UI_IS_BUSY ");
    ELOCKS.set("UI_IS_BUSY");

    if ( $("popup") ) {
        $("popup").style.display ="none";
    }
    if ( $("thumbnail_tooltip") ) {
        $("thumbnail_tooltip").style.display="none";
    }

    if(!loopStore.exists(id)){ //are we active
        ELOCKS.unset("UI_IS_BUSY");
        debug ("------------------- pageRight unset UI_IS_BUSY 1");
        return false;
    }
    if ($("pageRightToggle").value == "true") {
        //check for image fetching
        if(areWeInRegularSearch() && SearchAjax.inProgress){
			leftIndex = getLeftIndex();
			if (!$("img_" + getRightIndex(leftIndex + 20))) {	// Only pause if the images aren't buffered on the next page.
				highlightWait();
	            var new_id = loopStore.getNew();
	            AUTO_BROWSE_TIMEOUT = setTimeout(curry(pageRight,window,loopStore,new_id,once),250);
                ELOCKS.unset("UI_IS_BUSY");
                debug ("------------------- pageRight unset UI_IS_BUSY 2");
                return false;
			}
        }
        $("direction").value = "-1";

		closeFeatureImage();
        openToolbarContent.start(0);
	    openToolbarContent.isOpen = false;

	    openSxDownloadContent.start(0);
        openSxDownloadContent.isOpen = false;

		windowWidth = ww();
		totalResults = parseInt($("totalNumResults").value);

		currentLeft = new Array();
		newLeft = new Array();

		currentLeft[0] = parseInt($("search_results_a").style.left);
		currentLeft[1] = parseInt($("search_results_b").style.left);

		// For result sets smaller than the window width.
		if (currentLeft[0] == 0 && (totalResults * application.squareSize / application.colSize) < windowWidth) {
			stopThrottle();
            ELOCKS.unset("UI_IS_BUSY");
            debug ("------------------- pageRight unset UI_IS_BUSY 3");
            return;
		}

		debug("Paging right, SS: " + application.squareSize + ", CS: " + application.colSize);

		newLeft[0] = Math.ceilThumb(currentLeft[0] - windowWidth);
		newLeft[1] = Math.ceilThumb(currentLeft[1] - windowWidth);

		//debug("[pageRight] Calculated newLefts: [a:" + newLeft[0] + ", b:" + newLeft[1] + "]");

		offsetA = parseInt($("search_results_a_offset").value);
		offsetB = parseInt($("search_results_b_offset").value);

		currentPosLeft = getLeftIndex();
		currentPosRight = getRightIndex(currentPosLeft);

		resultsPerScreen = currentPosRight - currentPosLeft;

		// If the search results end on the next page.
		if (currentPosRight + resultsPerScreen >= totalResults - 1) {
			//debug("[pageRight] Search results end on next page.")
			var difference = totalResults - currentPosRight - 1;

			var numColsDifference = Math.ceil(difference / application.colSize);

			var pixelDifference = numColsDifference * application.squareSize; 	// - (windowWidth % application.squareSize);
																				// ^ EM-573: we now align to left at the end of results.

			// In case the Browse has started on a partial thumbnail (i.e. in the middle of a slow scroll).
			// Disabling since we don't have slow scroll anymore.
			//var inbetweenOffset = application.squareSize - Math.abs(Math.ceilThumb(currentLeft[0]) - currentLeft[0]);

			//debug("[pageRight] inbetweenOffset is " + inbetweenOffset);

			newLeft[0] = currentLeft[0]  - pixelDifference;
			newLeft[1] = currentLeft[1]  - pixelDifference;

			moveResultsOverA.lastPage = true;
		}

		//debug("[pageRight] Moving div_a to " + newLeft[0] + ", and div_b to " + newLeft[1]);

		if(once){
            moveResultsOverA.manualBrowse = true;
            setLastAction(application.events.MANUAL_BROWSE_RIGHT);
        } else {
			moveResultsOverA.manualBrowse = false;
			setLastAction(application.events.AUTO_BROWSE_RIGHT + " " + USER_PREF_MAP.get("auto_browse_pause") + "ms");
        }

		moveResultsOverA.start(newLeft[0]);
		moveResultsOverB.start(newLeft[1]);

		if (!once){
            var new_id = loopStore.getNew();
            AUTO_BROWSE_TIMEOUT = setTimeout(curry(pageRight,window,loopStore,new_id,once), USER_PREF_MAP.get("auto_browse_pause"));
        }
    }
}



function setProgressBar() {
	if (progressMeter = $("progress"))
		progressMeterSize = parseInt(progressMeter.style.width);
	else
		return;

	windowWidth = ww();
	
	totalResults = parseInt($("totalNumResults").value);
		
	leftIndex = getLeftIndex();
	rightIndex = getRightIndex(leftIndex);
	
	if (leftIndex == 0)
		avgIndex = 0;
	else if (rightIndex + 3 > totalResults - 1)
		avgIndex = totalResults;
	else
		avgIndex = (leftIndex + rightIndex) / 2;
	
	numDisplayed = rightIndex - leftIndex;	// this should work, yes?
	
	if (numDisplayed > totalResults) {	// in case the result set size is smaller than the screen
		$("indicator").style.width = progressMeterSize + "px";
		$("indicator").style.left = "0px";
		$("progress_left").innerHTML = "1";
		$("progress_right").innerHTML = totalResults;
		$("progress_number").innerHTML = "100";
		
		if ($("dynamic_tracker").value != "false") {
			$("the_ndash").style.width = "10px";
			$("progress_left").style.width = "25px";
			$("progress_right").style.width = "25px";
			$("tracker").style.marginLeft = progressMeterSize / 2 - 30 + "px";

			$("gti_toggle_wrapper").style.left = progressMeterSize + "px";
		}
		return;
	}
	
	indicatorWidth = Math.round(progressMeterSize * (numDisplayed / totalResults));
	
	if (indicatorWidth < 8) indicatorWidth = 8;
	
	percentageNum = avgIndex / totalResults;
	percentagePx = leftIndex / totalResults;
	
	if (percentageNum > 1) percentageNum = 1;
	if (percentagePx > 1) percentagePx = 1;
	
	progressLeft = Math.round(percentagePx * (progressMeterSize));
	
	$("indicator").style.width = indicatorWidth + "px";
	
	// Quick fix to avoid overflow on the right-hand size.  The "2" offset is for the borders of the GTA handle.
	if (progressLeft + indicatorWidth + 2 > progressMeterSize)
		progressLeft = progressMeterSize - indicatorWidth - 2;
	
	$("indicator").style.left = (progressLeft) + "px";
		
	if ($("dynamic_tracker").value != "false") {
		var gti_left;
		if (indicatorWidth < 110)
			gti_left = 110;
		else
			gti_left = indicatorWidth;

		$("gti_toggle_wrapper").style.left = progressLeft + gti_left + "px";

		if (indicatorWidth > 50) {
			$("the_ndash").style.width = "10px";
			$("progress_left").style.width = "25px";
			$("progress_right").style.width = "25px";
			$("tracker").style.marginLeft = indicatorWidth / 2 - 30 + "px";
		} else if (indicatorWidth >= 8) {
			$("the_ndash").style.width = indicatorWidth + "px";
			nw = 50 - Math.floor(indicatorWidth / 2);
			$("progress_left").style.width = nw + "px";
			$("progress_right").style.width = nw + "px";
			$("tracker").style.marginLeft = -1 * nw + "px";
		}
	}
	$("progress_left").innerHTML = leftIndex + 1;
	$("progress_right").innerHTML = rightIndex + 1;
	$("progress_number").innerHTML = Math.round(percentageNum * 100);
}

function updateProgressBarNumbers() {
	handlePos = parseInt($("indicator").style.left);
	meterWidth = parseInt($("progress").style.width);
	numResults = parseInt($("totalNumResults").value);

	handleWidth = parseInt($("indicator").style.width) + 2;  // add the borders

	percentage = handlePos / (meterWidth - handleWidth);

	// This is the abstract "position" based on the percentage.
	resultsPosition = numResults * percentage;
		
	rpp = getRightIndex(0) + 1;  // same thing, right?

	leftPosition = Math.ceil(resultsPosition - rpp / 2);

	while (Math.abs(leftPosition % 3) != 1)
		leftPosition--;

	if (leftPosition < 1)
		leftPosition = 1;

	rightPosition = getRightIndex(leftPosition);

	if (rightPosition > numResults)
		rightPosition = numResults;

	$("progress_left").innerHTML = leftPosition;
	$("progress_right").innerHTML = rightPosition;
	
	var pct = Math.round(percentage * 100);
	
	if (pct < 0) pct = 0;
	if (pct > 100) pct = 100;
	
	$("progress_number").innerHTML = pct;
}

