﻿var big, small, current, numElems, textElems;

init();

function init() {
    textElems = Array();
    small = { width: 100, height: 75 };
    big = { width: 200, height: 150 };
    current = 3;
    numElems = $("#gallery img").size() - 1;

    $("#gallery img").each(function(intIndex) {
    textElems[intIndex + 1] = $("#gallery img:nth-child(" + (intIndex + 1) + ")").attr("text");
    });
    $(window).load(function() {
        show(current - 1);
        makeBig(current);
        show(current + 1);
    });
}
function doGallery(shift) {
    if (numElems < 2) return;
    from = current;
    current += shift;
    if (current < 2) current = 2;
    if (current > numElems) current = numElems;
    if (from < current) { // right shift
        hide(from - 1);
        makeSmall(from);
        makeBig(current);
        show(current + 1)
    }
    if (from > current) { // left shift
        hide(from + 1);
        makeSmall(from);
        makeBig(current);
        show(current - 1)
    }
}
function makeBig(elem) {
    $("#gallery img:nth-child(" + elem + ")").animate({ width: big.width, height: big.height });
    $("#textElem").html(textElems[elem]);
}
function makeSmall(elem) {
    $("#gallery img:nth-child(" + elem + ")").css("display", "block").animate({ width: small.width, height: small.height });
}
function hide(elem) {

    $("#gallery img:nth-child(" + elem + ")").hide('slow');    
}
function show(elem) {
    $("#gallery img:nth-child(" + elem + ")").css({ width: small.width, height: small.height });
    $("#gallery img:nth-child(" + elem + ")").show('slow');
}
