﻿$(document).ready(function() {

    var imgCount = $("#thumbs a").length;
    var curIdx = $("#photo > div").index($("#photo > div:not(:hidden)"));

    // enhancement for js
    if (imgCount > 1) {
        $(".nextprevious").show();
    };

    $("#previous").click(function() {
        if ((curIdx) > 0) {
            curIdx -= 1;
        } else {
            curIdx = imgCount - 1;
        };
        changePhoto(curIdx);
        return false;
    });

    $("#next").click(function() {
        if ((curIdx + 1) < imgCount) {
            curIdx += 1;
        } else {
            curIdx = 0;
        };
        changePhoto(curIdx);
        return false;
    });

    $("#thumbs a").click(function() {
        curIdx = $("#thumbs a").index(this);
        changePhoto(curIdx);
        return false;
    });

    $("h1 a").click(function() {
        window.close();
        return false;
    });

});

function changePhoto(idx) {
    $("#photo > div:not(.nextprevious)").hide();
    $("#photo > div:eq(" + idx + ")").show();
    
};