var servico_index=0;
var animation_flag=true;

function prevServico(){
    if(animation_flag && servico_index>0){
        animation_flag=false;
        $('#servicos').animate({
            left: '+='+$('#servicos li').outerWidth(true)
        },500,'easeInBack',function(){
            servico_index--;
            animation_flag=true;
            if(servico_index==0)
                $('#prev_servico').addClass('disabled');
            if(servico_index==$('#servicos li').length-4)
                $('#next_servico').removeClass('disabled');

        });
    }
}

function nextServico(){
    if(animation_flag && servico_index<$('#servicos li').length-3){
        animation_flag=false;
        $('#servicos').animate({
            left: '-='+$('#servicos li').outerWidth(true)
        },500,'easeInBack',function(){
            servico_index++;
            animation_flag=true;
            if(servico_index==$('#servicos li').length-3)
                $('#next_servico').addClass('disabled');
            if(servico_index==1)
                $('#prev_servico').removeClass('disabled');
        });
    }
}

/*
var cliente_index=0;
var cliente_animation_flag=true;

function prevCliente(){
    if(cliente_animation_flag && cliente_index>0){
        cliente_animation_flag=false;
        $("#clientes li:eq("+(cliente_index+0)+")").delay(75).animate({opacity:0},500,function(){
            $('#clientes').css({left: (-1*118*(cliente_index-3))+'px'},225);
            $("#clientes li:eq("+(cliente_index-3)+")").delay(75).animate({opacity:1},500);
            $("#clientes li:eq("+(cliente_index-2)+")").delay(150).animate({opacity:1},500);
            $("#clientes li:eq("+(cliente_index-1)+")").delay(225).animate({opacity:1},500,function(){
                cliente_index=cliente_index-3;
                cliente_animation_flag=true;
                if(cliente_index==0)
                    $('#prev_cliente').addClass('disabled');
                if(cliente_index<$('#clientes li').length-2)
                    $('#next_cliente').removeClass('disabled');
            });
        });
        $("#clientes li:eq("+(cliente_index+1)+")").delay(150).animate({opacity:0},500);
        $("#clientes li:eq("+(cliente_index+2)+")").delay(225).animate({opacity:0},500);
    }
}

function nextCliente(){
    if(cliente_animation_flag && cliente_index<$('#clientes li').length-3){
        cliente_animation_flag=false;
        $("#clientes li:eq("+(cliente_index+2)+")").delay(75).animate({opacity:0},500);
        $("#clientes li:eq("+(cliente_index+1)+")").delay(150).animate({opacity:0},500);
        $("#clientes li:eq("+(cliente_index+0)+")").delay(225).animate({opacity:0},500,function(){
            $('#clientes').css({left: (-1*118*(cliente_index+3))+'px'});
            $("#clientes li:eq("+(cliente_index+5)+")").delay(75).animate({opacity:1},500);
            $("#clientes li:eq("+(cliente_index+4)+")").delay(150).animate({opacity:1},500);
            $("#clientes li:eq("+(cliente_index+3)+")").delay(225).animate({opacity:1},500,function(){
                cliente_index=cliente_index+3;
                cliente_animation_flag=true;
                if(cliente_index>$('#clientes li').length-3)
                    $('#next_cliente').addClass('disabled');
                if(cliente_index>0)
                    $('#prev_cliente').removeClass('disabled');
            });
        });
    }
}
*/

$(function(){

    // HOMEPAGE SLIDESHOW
    $('#slideshow').nivoSlider({
        effect:'random', // Specify sets like: 'fold,fade,sliceDown'
        slices:15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed:500, // Slide transition speed
        pauseTime:5000, // How long each slide will show
        startSlide:0, // Set starting Slide (0 index)
        directionNav:false, // Next & Prev navigation
        directionNavHide:true, // Only show on hover
        controlNav:true, // 1,2,3... navigation
        controlNavThumbs:false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, // Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', // Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
        keyboardNav:true, // Use left & right arrows
        pauseOnHover:true, // Stop animation while hovering
        manualAdvance:false, // Force manual transitions
        captionOpacity:0.8, // Universal caption opacity
        prevText: 'Prev', // Prev directionNav text
        nextText: 'Next', // Next directionNav text
        beforeChange: function(){}, // Triggers before a slide transition
        afterChange: function(){}, // Triggers after a slide transition
        slideshowEnd: function(){}, // Triggers after all slides have been shown
        lastSlide: function(){}, // Triggers when last slide is shown
        afterLoad: function(){
            $('.nivo-controlNav').css({'opacity':'0'});
            $('#slideshow').hover(
              function () {
                $('.nivo-controlNav').animate({'opacity':'1'},300);
              },
              function () {
                $('.nivo-controlNav').animate({'opacity':'0'},300);
              }
            );
        } // Triggers when slider has loaded
    });

    // HOMEPAGE SERVIÇOS
    $('#servicos').width($('#servicos li').outerWidth(true)*$('#servicos li').length);

    // HOMEPAGE CLIENTES
/*
    $('#clientes').width($('#clientes li').outerWidth(true)*$('#clientes li').length);
    $("#clientes li:gt(2)").css({opacity:0});
*/

   var auto = true;
   var autostopped = false;
   var sudoSlider = $("#clientes_container").sudoSlider({
      auto:true,
      pause: '5000',
      autowidth:false,
      slideCount:3,
      continuous:true,
      moveCount:3
   })
   .mouseenter(function() {
      auto = sudoSlider.getValue('autoAnimation');
      if (auto)
      {
         sudoSlider.stopAuto();
      }
      else
      {
         autostopped = true;
      }
   }).mouseleave(function() {
      if (!autostopped)
      {
         sudoSlider.startAuto();
      }
   });

});
