﻿var currentX = 0;
var righttime;
var lefttime;

function bigImage_onload() {


    var image = document.getElementById('bigImage');
    var newImage = new Image();
    newImage.src = image.src;

    var width = newImage.width;
    var height = newImage.height;
    var imageRatio = newImage.width / newImage.height;
    var destinationRatio = 470 / 266;

    image.style.width = 470 + "px";
    image.style.height = 266 + "px";

    if (imageRatio < destinationRatio);
    {
        image.style.width = 470 + "px";
        image.style.height = Math.round(470 / imageRatio) + "px";
    }
    if (imageRatio > destinationRatio);
    {
        image.style.width = Math.round(266 * imageRatio) + "px";
        image.style.height = 266 + "px";
    }
}

function moveleft() {
    try {
        if (currentX != 0) {
            var objCarriers = document.getElementById("images");
            currentX += 15;
            objCarriers.style.left = currentX + "px";
        }

        lefttime = setTimeout("moveleft()", 50);
    }
    catch (e) {
        alert(e.name + ' ' + e.message);
    }
}

function moveright(nImages) {
    try {
        var sliderwidth = 586;
        var carrierswidth = document.getElementById("images").style.Width;
        var diffwidth = ((149 * nImages) - sliderwidth);
        diffwidth = (diffwidth - (2 * diffwidth));


        if (currentX > diffwidth) {
            var objCarriers = document.getElementById("images");
            currentX -= 15;
            if (currentX < diffwidth) {
                objCarriers.style.left = currentX + 15 - ((currentX + 15) - diffwidth) + "px";
            }
            else {
                objCarriers.style.left = currentX + "px";
            }
        }

        righttime = setTimeout("moveright(" + nImages + ")", 50);
    }
    catch (e) {
        alert(e.name + ' ' + e.message);
    }
}

function switchimage(whichpic, strAlt, strCaption, strPhotographer) {
    document.getElementById("bigImage").alt = strAlt;

    if (strCaption != "") {
        document.getElementById("caption").innerHTML = strCaption;
    }
    else {
        document.getElementById("caption").innerHTML = "";
    }

    if (strPhotographer != "") {
        document.getElementById("photograph_by").innerHTML = "Photo By: " + strPhotographer + "&nbsp;";
    }
    else {
        document.getElementById("photograph_by").innerHTML = "";
    }

    document.getElementById("bigImage").src = whichpic.href;

    return false;
}
