﻿var comingfromjs = false;

$(document).ready(function () {
    $("#carousel a.piclink").hide().first().slideDown();

    $("#carousel").scrollable({
        circular: true,

        onBeforeSeek: function (event, itemIndex) {
            if (comingfromjs) { comingfromjs = false; return true; }
            comingfromjs = true;

            var currindex = this.getIndex();
            if (currindex < 0) currindex = this.getSize() - 1;
            var nextindex = itemIndex;
            if (nextindex >= this.getSize()) nextindex = 0;

            var item = this.getItems()[currindex];
            var api = this;
            $(item).find("a.piclink").slideUp(function () {
                api.seekTo(nextindex);
            });

            return false;
        },

        onSeek: function (event, itemIndex) {
            var item = this.getItems()[itemIndex];
            $(item).find("a.piclink").slideDown();

            return false;
        }
    }).navigator().autoscroll(7000);
});
