var thumb = $("#gallerySmallImages > :eq(0)"); // starts thumb

function onAfter(curr, next, opts) {
    thumb.children('img').fadeTo('slow',0.3);

    var index = opts.currSlide;
    $("#gallerySmallImages > a").attr("lang", "");
    thumb = $("#gallerySmallImages > :eq("+ index +")").attr("lang", "current");

    thumb.children('img').fadeTo('slow',1);
}

$(document).ready(function() {
    $('#galleryBigImages').cycle({
        fx: 'fade',
        timeout: 10000,
        after: onAfter
    });
    $('#galleryInfo').cycle({
        fx: 'fade',
        timeout: 10000
    });


    $("#gallerySmallImages > a").each(function(i) {

        // Click on image and cycle to that image
        $(this).click(function() {
            $('#galleryBigImages').cycle(i);
            $('#galleryInfo').cycle(i);
            return false;
        });

        // Fade all elements
        if($(this).attr("lang") == "") {
            $(this).children('img').fadeTo('fast',0.3)
        }

        // Fade over effect
        $(this).hover(
            function() {
                $(this).children('img').fadeTo('fast',1);
            },
            function() {
                // don't fade out if the parent is active
                if( $(this).attr("lang") == "") {
                    $(this).children('img').fadeTo('fast',0.3);
                }
            }
            );

    });



});