function stopSimsThrottle() {
	clearSimsSelected();
	$("ss_traffic_light").value = "stop";
	$("ss_pageLeftToggle").value = "false";
	$("ss_pageRightToggle").value = "false";
	
	return false;
}

function clearSimsSelected() {
	$("ss_page_left").className = "";
	$("ss_page_right").className = "";
}

function setSimsSearchThrottle() {
	$("ss_speed").value = "3300";

    $("ss_page_right").onclick  = function(){DISPATCHER.fire("CANCEL_NEXT_SIM_POPUP");DISPATCHER.fire("CLOSE_SIMSEARCH_POPUP");DISPATCHER.fire("MANUAL_SS_RIGHT"); return false; };
    $("ss_page_left").onclick  = function(){DISPATCHER.fire("CANCEL_NEXT_SIM_POPUP");DISPATCHER.fire("CLOSE_SIMSEARCH_POPUP");DISPATCHER.fire("MANUAL_SS_LEFT"); return false; };
}

function ss_pageLeft(once) {
	if ($("ss_pageLeftToggle").value == "true") {
		var windowWidth = ww();
        var fwWidth = parseInt($("feature_wrap").style.width) + application.simSquareSize;
        windowWidth -=  fwWidth;

		currentLeft = parseInt($("simsearch").style.left);
       	newLeft = currentLeft + Math.simfloorThumb(windowWidth);

        if ( currentLeft == fwWidth) {
			stopThrottle();	// we're already there!
			return;
        } 

        if (newLeft >= fwWidth) {
            newLeft = fwWidth;
            moveSimsOver.lastPage = true;
        } else {
            moveSimsOver.lastPage = false;
        }

        moveSimsOver.start(newLeft);

        if (!once)
			window.setTimeout("ss_pageLeft()", $("ss_speed").value);
	}
}

function ss_pageRight(once) {
	if ($("ss_pageRightToggle").value == "true") {
		var windowWidth = ww();
        var fwWidth = parseInt($("feature_wrap").style.width) + application.simSquareSize;
        windowWidth -=  fwWidth;
     
        currentLeft = parseInt($("simsearch").style.left);
		newLeft = currentLeft - Math.simfloorThumb(windowWidth);
 
        totalResults = parseInt($("numSimsResults").innerHTML);

        // For result sets smaller than the window width.
		if ( totalResults * application.simSquareSize < windowWidth ){
			stopThrottle();
			return;
		}

        currentPosLeft = Math.ceil(Math.abs(currentLeft -( fwWidth ) )/application.simSquareSize);
        currentPosRight =  currentPosLeft + (Math.floor( (windowWidth) / application.simSquareSize)) - 1;
        resultsPerScreen = currentPosRight - currentPosLeft;

		if (currentPosLeft + resultsPerScreen + 1 >= totalResults)
			return;
			
        // If the search results end on the next page.
        if (currentPosRight + resultsPerScreen >= totalResults - 1 ) {
            var numColsDifference = totalResults - currentPosRight - 1;
            newLeft = currentLeft - numColsDifference * application.simSquareSize;
            moveSimsOver.lastPage = true;
        }

		for (i = currentPosLeft; i < currentPosLeft + 32; i++) {
			if (!$("sim_img_" + i)) {
                fetchSimSearchResults({startPos: i, stream: "simsearch", type: 2, streamThis: "yes", streamSource: ">",license: $("feature_license").value});
				break;
			}
        }

        moveSimsOver.start(newLeft);
		
		if (!once)
			window.setTimeout("ss_pageRight()", $("ss_speed").value);		
	}
}

