// function callback on showing image
// get title and display it
function superbgimage_show(img) {
    $('#superbgimage').css('background', 'none');

    $('#showtitle p.imagecount').html('image ' + img + ' of ' + $.superbg_imgIndex);
    $('#showtitle p.title').html($('#photos a' + "[rel='" + img + "']").attr('title'));
    
    $('.btn-slide').fadeIn('fast');
}


$(document).ready(function(){ 

    // Options for SuperBGImage
    $.fn.superbgimage.options = {
        id: 'superbgimage', // id for the containter
        z_index: 0, // z-index for the container
        inlineMode: 0, // 0-resize to browser size, 1-do not resize to browser-size
        showimage: 1, // number of first image to display
        vertical_center: 1, // 0-align top, 1-center vertical
        transition: 1, // 0-none, 1-fade, 2-slide down, 3-slide left, 4-slide top, 5-slide right, 6-blind horizontal, 7-blind vertical, 90-slide right/left, 91-slide top/down
        transitionout: 1, // 0-no transition for previous image, 1-transition for previous image
        randomtransition: 0, // 0-none, 1-use random transition (0-7)
        showtitle: 0, // 0-none, 1-show title
        slideshow: 0, // 0-none, 1-autostart slideshow
        slide_interval: 5000, // interval for the slideshow
        randomimage: 0, // 0-none, 1-random image
        speed: 'slow', // animation speed
        preload: 0, // 0-none, 1-preload images
        onShow: superbgimage_show // function-callback show image
    };

    // initialize SuperBGImage
    $('#photos').superbgimage();

    // fade slide
    $('.btn-slide').fadeTo('slow', 0.45);
    
    $('.btn-slide').hover(
        function () {
            $(this).fadeTo('fast', 1.00);
        },
        function () {
            $(this).fadeTo('fast', 0.45);
        }
    );

    //slide buttons
    $("#btn-slide").click(function(){
        $("#panel").slideToggle("slow");
        $(this).toggleClass("active"); 
        return false;
    });
    
    jQuery.fn.fadeToggle = function(slow, easing, callback) {
       return this.animate({opacity: 'toggle'}, slow, easing, callback);
    };
    
    $("#thumbs-slide").click(function () {
        $("#photos").fadeToggle()
        $("#wrapper").fadeToggle()
        $(this).toggleClass("active"); 
        return false;
    });


    //	thumbs hide
    $("#photos a").click(function () {
        $("#photos").fadeToggle();
        $("#wrapper").fadeToggle();
        $("#thumbs-slide").toggleClass("active");
        return false;
    });

    //NAVIGATION
    // prev slide
    $('a.prev').click(function() {
        return $('#photos').prevSlide();
    });

    // next slide
    $('a.next').click(function() {
        return $('#photos').nextSlide();
    });

    $(document).keydown(function(e) {
        switch(e.keyCode) {
        // User pressed “right” arrow
            case 39:
                return $('#photos').nextSlide();
                break;
        
        // User pressed “left” arrow
            case 37:
                return $('#photos').prevSlide();
                break;
        }
    });

}); // end document.ready

