var defaultSpeed = 2;
var speed;
var timeout = 1;
var scrolling;
var maxScroll = 75;
var lastThumb = "thumb0";

function startScroll(dir) {
    speed = defaultSpeed;
    scrolling = setTimeout("scroll('" + dir + "')", timeout);
}

function getMaxScroll() {
    maxScroll = $("#lyr").outerWidth() - $("#win").outerWidth();
}

function scroll(dir) {
    var pos = $("#lyr").css("left").replace(/px/, "");
    if (dir == "left") {
        // left arrow = move div right
        pos = pos / 1 + speed;
        if (pos > 0)
            stopScroll();
        else {
            $("#lyr").css("left", pos);
            scrolling = setTimeout("scroll('" + dir + "')", timeout);
        }
    }
    else {
        // figure maximum scroll value
        getMaxScroll();
        // right arrow, move div left
        pos = pos / 1 - speed;
        if (pos < -maxScroll)
            stopScroll();
        else {
            $("#lyr").css("left", pos);
            scrolling = setTimeout("scroll('" + dir + "')", timeout);
        }
    }
}

function stopScroll() {
    speed = 0;
    clearTimeout(scrolling);
}

function doubleSpeed() {
    speed = speed * 2;
}

function resetSpeed() {
    speed = speed / 2;
}

function showPic(image, alt, thumb) {
    $("#ctl00_cphMain_imgProperty").attr("src", image);
    $("#ctl00_cphMain_imgProperty").attr("alt", alt);
    $("#" + thumb).attr("class", "selectedThumb");

    if (lastThumb != null && lastThumb != thumb)
        $("#" + lastThumb).attr("class", "detailsThumb");

    lastThumb = thumb;
}
