﻿var startFancyboxIndex = 0;
var maxFancyboxesToShow = 5;

$(document).ready(function () {
    // fancybox configuration
    $(".fancybox").fancybox({
        helpers: {
            title: {
                type: 'over'
            }
        }
    });

    // set fancybox thumbnails (made by us) to change the primary image source on mouseover
    $(".fancybox-thumbnail").mouseover(function () {
        $('div.item-image').trigger('zoom.destroy');
        $(".item-image-file").attr("src", $(this).attr("src"));
        $('div.item-image').zoom({ magnify: "1" });
        //{ magnify: "1.2"}
    });

    // show the first [max #] fancyboxes
    startFancyboxIndex = 0;
    showFancyBoxes();
});
function fancyBoxShift(shiftValue) {
    // shift the initial index
    startFancyboxIndex += shiftValue;
    var fbCount = $(".fancybox").length;

    if (startFancyboxIndex + maxFancyboxesToShow > fbCount) {
        startFancyboxIndex = fbCount - maxFancyboxesToShow;
    } else if (startFancyboxIndex < 0) {
        startFancyboxIndex = 0;
    }

    showFancyBoxes();
}
function showFancyBoxes() {
    // show or hide fancyboxes by index
    var tempIndex = 0;
    $(".fancybox").each(function () {

        if (tempIndex < startFancyboxIndex || tempIndex >= startFancyboxIndex + maxFancyboxesToShow) {
            $(this).hide();
        } else {
            $(this).show();
        }

        tempIndex++;
    });

    // show fancybox shift arrows (left only, right only, both, or neither)
    var prev = $(".fancybox-shift-left");
    var next = $(".fancybox-shift-right");
    var fbCount = $(".fancybox").length;

    if (fbCount < maxFancyboxesToShow) {
        prev.hide();
        next.hide();
    } else if (startFancyboxIndex === 0) {
        prev.css("visibility", "hidden");
        next.css("visibility", "visible");
    } else if (startFancyboxIndex + maxFancyboxesToShow >= fbCount) {
        prev.css("visibility", "visible");
        next.css("visibility", "hidden");
    } else {
        prev.css("visibility", "visible");
        next.css("visibility", "visible");
    }
}