/*var timer = 0;
var interval = 5500;

function slideNext() {
    window.clearTimeout(timer);
    var img = 0;
    var count = 0;
    $('#pictures > li').each(function(){
        if ($(this).attr('class')=='current') {
            img = count;
        }
        count++;
    });
    var obj = $('#pictures').parent();
    $('.nav',obj).removeClass('active');
    $($('.nav',obj)[img]).addClass('active');

    var prev = img - 1;
    var next = img + 1;
    if (prev < 0) {
        prev = count -1;
    }
    if (next > count-1) {
        next = 0;
    }
    $('#pictures > li').css('z-index','1');
    $($('#pictures > li')[img]).css('z-index','6');
    $($('#pictures > li')[next]).css('z-index','5');

    $("#textoAnimacao").children("div").hide()
    $("#textoAnimacao").children("div").eq(next).show();
    $('#pictures > li.current').fadeOut(1000,function(){
        $('#pictures > li.current').attr('class','').css('z-index','1');
        $($('#pictures > li')[img]).show();
        // $('#pictures > li > img.current').attr('class','').hide();
        $($('#pictures > li')[next]).attr('class','current').css('z-index','6');
        
        
        timer = window.setTimeout('slideNext()',interval);
    });
}

$(function(){
    var obj = $('#pictures').parent();
    $('.nav',obj).remove();
    var count=0;
    
    $('#pictures > li').each(function(){
        count++;
        obj.append("<a class='nav' atual='"+(count-1)+"' href='javascript:void(0)' style='margin-top: "+ ((count * 5) + count * 21) +"px;'>"+count+"</a>");
    });
    $('#pictures > li').removeClass('current');
    $($('#pictures > li')[0]).addClass('current');
    //slideNext();
    $(window).load(function() {
        $('a.nav',obj).click(function(){
            $('#pictures > li').removeClass('current');
            $($('#pictures > li')[$(this).attr('atual')]).addClass('current');
            window.clearTimeout(timer);
            slideNext();
        });

        $("#textoAnimacao").children("div").eq(count-1).fadeIn("slow");
        timer = window.setTimeout('slideNext()',interval);
    });
});*/

$(function() {
    //variaveis globais
    var timer = 0;
    var interval = 5500;
    var eq = 0;

    //pictures
    var $pictures = $("#pictures");
    var $li = $pictures.children("li");
    var length = $li.length;

    //frase
    var $textoAnimacao = $("#textoAnimacao");
    var $frase = $textoAnimacao.children("div");

    //navegador
    var $obj_nav = $pictures.parent();

    for(var i = 1; i <= length; i++) {
        $obj_nav.append("<a class='nav' href='javascript:void(0)' style='margin-top: "+ ((i * 5) + i * 21) +"px;'>"+i+"</a>");
    }

    var $a_nav = $obj_nav.children("a.nav");

    $li.eq(eq).addClass('current');
    $(window).load(function() {
        $a_nav.unbind("click").bind("click",function(){
            var $obj = $(this);
            slideshow($a_nav.index($obj));
        });

        slideshow(0)
    });

    function slideshow(this_eq) {
        if ($li.eq(this_eq).is(":visible")) {
            return;
        }

        //a_nav
        $a_nav.removeClass("active");
        $a_nav.eq(this_eq).addClass("active");

        //clear
        window.clearTimeout(timer);

        //foto
        $li.stop(true,true).fadeOut("slow");
        $li.eq(this_eq).fadeIn("slow");

        //frase
        $frase.stop(true,true).fadeOut("slow");
        $frase.eq(this_eq).fadeIn("slow");

        //final
        eq = this_eq +1;
        if (eq == length) {
            eq = 0;
        }

        //começa de novo
        timer = window.setTimeout(function() {
            $a_nav.eq(eq).trigger("click");
        },interval);
    }
});
