var bg = 2;
$(document).ready(function(){
    
    
    
    
    
    
    $.backstretch($('#bgimage1').html(), {
        speed: 500,
        centeredY: true,
        centeredX: false
    });
    
    
    var hCnt = (Math.ceil($('#content').children('.thumb').length / 5) * 88) + 4;
    
    $('#container').objectRePos({
       h: hCnt
    });


    $(".thumb > a").fancybox({
        'hideOnContentClick': false,
        'titlePosition': 'over',
        'autoDimensions': true,
        'padding': '0',
        'margin': '10px',
        'overlayColor': '#a28561',
        'overlayOpacity': '0.7',
        'titleShow': true
    });

    
    $('#divScrollPane').animate({
        opacity: 0
    }, 1);
    $('.divENG').css('z-index', '-8000');
    
    $('#divScrollPane').sbscroller();
    $('#divScrollPaneIta').sbscroller();
    
    $('#btnEngTxt').click(function(){
        $(this).addClass('active');
        $('#btnItaTxt').removeClass('active');
        $('.divENG').animate({
            opacity: 1
        }, 500);
        $('.divENG').css('z-index', '8000');
        $('.divITA').animate({
            opacity: 0
        }, 500);
        $('.divITA').css('z-index', '-8000');
    });
    
    $('#btnItaTxt').click(function(){
        $(this).addClass('active');
        $('#btnEngTxt').removeClass('active');
       $('.divENG').animate({
            opacity: 0
        }, 500);
        $('.divENG').css('z-index', '-8000');
        $('.divITA').animate({
            opacity: 1
        }, 500);
        $('.divITA').css('z-index', '8000');
    });
    
    
    /*
    $('#navigationLeft ul li').click(function(){
        $(this).children('ul').css('display', 'block');
    });
    */
    
    
    
    
    
});

function reloadBG(){
    var n;
    if(bg == 1){
        bg = 2;
        n = 1;
    }else{
        bg = 1;
        n = 1;
    }
    
    $.backstretch($('#bgimage'+bg).html(), {
        speed: 500,
        centeredY: true,
        centeredX: false
    }, function(){
        t=setTimeout("reloadBG()",25000);    
    });
    
    
    
    
}

function formatTitle(title, currentArray, currentIndex, currentOpts) {
    return '<div id="tip7-title"><span><a href="javascript:;" onclick="$.fancybox.close();"><img src="/data/closelabel.gif" /></a></span>' + (title && title.length ? '<b>' + title + '</b>' : '' ) + 'Image ' + (currentIndex + 1) + ' of ' + currentArray.length + '</div>';
}
