$(document).ready(function(){
    
    if($("ul.sf-menu").length > 0){
        $("ul.sf-menu").superfish({ 
            delay:       1,                            // one second delay on mouseout 
            animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
            speed:       'fast',                          // faster animation speed 
            autoArrows:  false,                           // disable generation of arrow mark-up 
            dropShadows: false                            // disable drop shadows 
        });
    }

    $( "#tabs_destra" ).tabs();

    $( "#accordion" ).accordion();
    $( "#accordion" ).accordion( "option", "icons", false );
    $( "#accordion" ).accordion({autoHeight: false});
    
    if($(".jcarousel-skin-tango").length > 0){
        jQuery('.jcarousel-skin-tango').jcarousel({
            scroll: 1,
            wrap: 'last',
            initCallback: mycarousel_initCallback
        });
    }
    if($('#slider').length > 0){
        $('#slider').nivoSlider();
    }
    
});

$(document).ready(function(){
    $('#form_preventivo').hide();
    $('#clickme').click(function() {
          $('#form_preventivo').toggle('slow', function() {
            // Animation complete.
          });
        });
});

var test_click = false;
function inizializza_ricerca(){
    if(test_click==false){$("#testo_search").val('');test_click = true;}
}

function ricerca(){
    
    var ricerca = $("#testo_search").val().replace(" ","+");
    if(ricerca.length == 0){
        alert('non hai inserito il testo da ricercare!');
        return false;
    }
    document.location.href='/tags/'+ricerca;
    return false;
}

function vedi_tutte(){
    
    $("#menu2").animate({'height': 0},{queue:false, duration:250, complete: function() { $(this).hide();}});
    var altrearee= document.getElementById('altrearee');
    altrearee.style.display='none';

    $("#menu3").show();
    var currentHeight = $("#menu3").height();
    $("#menu3").css('height', 'auto');
    var height = $("#menu3").height();
    $("#menu3").css('height', currentHeight + 'px');
    $("#menu3").animate({'height': height},{queue:false, duration:250});

    return false;
}

function chiudi(){
    $("#menu3").animate({'height': 0},{queue:false, duration:250, complete: function() { $(this).hide();}});
    
    var altrearee= document.getElementById('altrearee');
    altrearee.style.display='block';
    
    $("#menu2").show();
    var currentHeight = $("#menu2").height();
    
    $("#menu2").css('height', 'auto');
    var height = $("#menu2").height();
    $("#menu2").css('height', currentHeight + 'px');
    $("#menu2").animate({'height': height},{queue:false, duration:250});
    return false;
}

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

var tempo;
function call_sottodominio(categoria){      
    clearTimeout(tempo);
    tempo = setTimeout(function(){
        call_sottodominio_ajax(categoria);
    }, 900);
}

function clear_timeout(){       
    clearTimeout(tempo);
}

function call_sottodominio_ajax(categoria)
{
    $.ajax({
        type : "POST",
        url : "/welcome/sotto_menu_ajax.htm",
        dataType : "html",
        data: {categoria: categoria},
        cache : false,
        beforeSend : function() {
            $("#box_menu_ajax").html('<div class="caricamento_menu">Caricamento in corso...</div>');            
        },
        success : function(data, textStatus) {
            $("#box_menu_ajax").html(data);
        },          
        complete : function(XMLHttpRequest, textStatus) {
            carica_stop();
        },
        async : false
    });
};
// JavaScript Document
