// Settings:
var animation_speed = 500; // time to scroll 100 pixels (ms)

// Do not touch below this line
var image_spacer_px = 8; // pixels
var total_pics = 19;
var current_pic = 0, max_pic;
var animation = "";

function Animate ()
{
    if (animation != '' && (animation == "left" && current_pic > 0 || animation == "right" && current_pic <= max_pic))
    {
        var left = animation == "left";
        var width = $("#thumbs .content img:eq(" + current_pic + ")").width () + image_spacer_px;
        var pixels_left = (left ? '+' : '-') + '=' + width + 'px';
        var pixels_right = (left ? '-' : '+') + '=' + width + 'px';
        current_pic += left ? -1 : 1;
        $("#thumbs .content").animate ({
        "marginLeft" : pixels_left,
        "marginRight" : pixels_right
        }, width / 100 * animation_speed, "linear", function () {
        if (animation != '')
        Animate ();
        });
    }
}

$(window).ready (function ()
{
    // Calculate max_pic
    var images_width = 0;
    max_pic = total_pics;
    while (max_pic > 0 && images_width < $("#thumbs .content").parent ().width ())
    images_width += $("#thumbs .content img:eq(" + --max_pic + ")").width () + image_spacer_px;
    if (max_pic == 0 && images_width < $("#thumbs .content").parent ().width ())
    max_pic--;

    $("#thumbs .arrow-left, #thumbs .arrow-right").hover (function () {
    animation = $(this).is (".arrow-left") ? "left" : "right";
    Animate ();
    }, function () {
        animation = "";
    });

    // Initialize fancybox
//    $("a.fancybox").fancybox ({
//        'overlayShow'  : true,
//        'zoomSpeedIn'  : 600,
//        'zoomSpeedOut' : 500,
//        'easingIn'     : 'easeOutBack',
//        'easingOut'    : 'easeInBack'
//    });
});


