/**
 * Copyright Abbazia San Sebastiano 2011
 */

$(document).ready(function(){

    //$('#accordion').accordion({collapsible: true , active: false, autoHeight: false});

    $('#tabs div.eventDescription').hide();
    $('#tabs div.mainBox').hide();
    $('#tabs div.mainBox:first').show();
    $('#tabs ul li:first').addClass('active');

    $('#tabs ul li a').click(function(){
        return changeTab($(this));
    });

    $('#contattaciFooter').click(function(){
        return changeTab($('#contatti_top'));
    });

    $('p.eventTitle a').click(function(){
        return toggleEvent($(this));
    });

    //galleryInit();
    loadGalleryId("2010");
    
});

function toggleEvent(el){
    var currentEvent = el.attr('href');
    $(currentEvent).slideToggle();
    return false;
}

function changeTab(el){
    $('#tabs ul li').removeClass('active');
    el.parent().addClass('active');
    var currentTab = el.attr('href');
    $('#tabs div.mainBox').hide();
    $(currentTab).show();
    $(currentTab + " > div.toShow").show();

    trackPageView(currentTab);

    return false;
}

function trackPageView(pageName){
    _gaq.push(['_trackPageview', "/" + pageName]);
}

function loadGalleryId(id){
    //alert(url);
    var _aux_url = "./index.php?c=gallery&m=view&id=";
    $('#main_outer_gallery_preview').load(_aux_url+id, function(){
        trackPageView("gallery/"+id);
        galleryInit(id);
    });
}

function galleryInit(id){

    $('#main_inner_gallery_menu ul li').removeClass('active');
    $('.gallery_menu_item_'+id).parent().addClass('active');

    //initialize jcarousel
    $(".jcarousel").jCarouselLite({
        visible: 5,
        btnNext: ".next",
        btnPrev: ".prev"
    });

    //initialize lightbox
    $("#page_gallery a").lightBox();
    
//    $("#waitDiv").hide("slow", function(){
//        $("#galleryDiv").show("slow");
//    });   
//    $("#waitDiv").hide("slow");
//    $("#galleryDiv").show("slow");
}


function switchInnerTab(tabId){
    //alert('#'+tabId + " .readAll");
    $('#'+tabId + " .readAll").slideToggle('slow');
    _textLink = $('#'+tabId + " #readAllLink a").text();
    //alert(_textLink);
    if(_textLink=='Leggi tutto')
        $('#'+tabId + " #readAllLink a").text('Chiudi');
    if(_textLink=='Chiudi')
        $('#'+tabId + " #readAllLink a").text('Leggi tutto');
    if(_textLink=='Read more')
        $('#'+tabId + " #readAllLink a").text('Close');
    if(_textLink=='Close')
        $('#'+tabId + " #readAllLink a").text('Read more');
    return false;
}

