/* Gallery scripting
--------------------------  */

var cpos = 0;

function showimage(o, pos, io, is, it, ia) {
    // get the ul
    var ul = o.parentNode;
    while (ul.tagName != "UL") {
        ul = ul.parentNode;
    }
    ul.getElementsByTagName("LI")[cpos].className = "";
    o.className = "selected";
    cpos = pos;
    document.getElementById(io).setAttribute("src", is)
    document.getElementById(io).setAttribute("title", it)
    document.getElementById(io).setAttribute("alt", ia)
}

var scrolling = false;
function scrolllist(d, lo) {
    if (!scrolling) {
        var coffset = 2;
        if (document.getElementById(lo).style.left) {
            coffset = parseFloat(document.getElementById(lo).style.left);
        }
        var fwidth = parseFloat(document.getElementById(lo).style.width);
        var noffset;
        if (d == "right") {
            noffset = coffset - 27.75;
            if (noffset > (fwidth * -1)) {
                scrolling = true;
                document.getElementById(lo).style.left = (coffset - 2) + "em";
                window.setTimeout(function() { easeinout(d, document.getElementById(lo), coffset - 4, 2, noffset, 5); }, 5);
            }
        }
        else if (d == "left") {
            noffset = coffset + 27.75;
            if (noffset <= 2) {
                scrolling = true;
                document.getElementById(lo).style.left = (coffset + 2) + "em";
                window.setTimeout(function() { easeinout(d, document.getElementById(lo), coffset + 4, 2, noffset, 5); }, 5);
            }
        }
    }
}

function easeinout(d, o, ov, oi, ol, iv) {
    if (d == "right") {
        o.style.left = ov + "em";
        if (ov > ol) {
            var nv = ov - oi
            if (nv < ol) {
                nv = ol;
            }
            window.setTimeout(function() { easeinout(d, o, nv, oi, ol, iv); }, iv);
        }
        else {
            scrolling = false;
        }
    }
    else if (d == "left") {
        o.style.left = ov + "em";
        if (ov < ol) {
            var nv = ov + oi
            if (nv > ol) {
                nv = ol;
            }
            window.setTimeout(function() { easeinout(d, o, nv, oi, ol, iv); }, iv);
        }
        else {
            scrolling = false;
        }
    }
}