﻿$(document).ready(function() {

    var arrId = new Array();
    var arrIdPos = 0;

    $("#prox").click(function() {
        /*if (arrIdPos < (arrId.length - 1)) {
            $("." + arrId[arrIdPos]).slideUp();
            arrIdPos++;
            $("." + arrId[arrIdPos]).slideDown();
        }*/
        
        $("." + arrId[arrIdPos]).slideUp();
        arrIdPos++;
        if (arrIdPos > (arrId.length - 1)) {
            arrIdPos = 0;
        }
        $("." + arrId[arrIdPos]).slideDown();
        
    });

    $("#ant").click(function() {
        /*if (arrIdPos > 0) {
            $("." + arrId[arrIdPos]).slideUp();
            arrIdPos--;
            $("." + arrId[arrIdPos]).slideDown();
        }*/
        
        $("." + arrId[arrIdPos]).slideUp();
        arrIdPos--;
        if (arrIdPos < 0) {
            arrIdPos = arrId.length-1;
        }
        $("." + arrId[arrIdPos]).slideDown();
        
    });

    var abrePrimeiraFoto = true;

    $(".loadingImg").load(function() {
        var idRef = $(this).attr("id");
        var src = $(this).attr("src");
        $("." + idRef).removeClass("loading");
        $("." + idRef).css("background-image", "url('" + src + "')");
        if (abrePrimeiraFoto == true) {
            abrePrimeiraFoto = false;
            $("." + idRef).slideDown();
        }
        $("#" + idRef).remove();
        arrId.push($(this).attr("id"))
    });

    $(".clienteMarca").each(function(index, item) {

        if (index == 0) { $(this).show(); }

    });

    $(".nossoClientesEsq").click(function() {

        var stop = false;

        $(".clienteMarca").each(function(index, item) {

            if ($(this).is(":hidden") == false && stop == false) {

                $(this).fadeOut("fast",function() {
                    if (index == 0) {
                        $(this).parent().children("img.clienteMarca:last").fadeIn("fast");
                    } else {
                        $(this).prev().fadeIn("fast");
                    };
                });

                stop = true;

            };

        });

    });

    $(".nossoClientesDir").click(function() {

        var stop = false;

        $(".clienteMarca").each(function(index, item) {

            if ($(this).is(":hidden") == false && stop == false) {

                $(this).fadeOut("fast", function() {
                    if (index == ($(".clienteMarca").length - 1)) {
                        $(this).parent().children("img.clienteMarca:first").fadeIn("fast");
                    } else {
                        $(this).next().fadeIn("fast");
                    };
                });

                stop = true;

            };

        });

    });

});
