$(document).ready(function () {
    function r(a) {
        e = parseInt($("#logos").css("margin-left").replace("px", ""));
        h = $("#logos").width();
        f = 920;
        g = 150;
        $("#debug").html(h);
        if (a == 1) {
            if (e > (h - f) * -1) {
                if (e - g < (h - f) * -1) {
                    e = e - (e + (h - f))
                } else {
                    e = e - g
                }
                $("#logos").animate({
                    "margin-left": e
                }, {
                    queue: false,
                    duration: 300,
                    easing: "easeOutQuint"
                })
            }
            if (e == (h - f) * -1) {
                return true
            }
        }
        if (a == 0) {
            if (e < h - f && e < 0) {
                if (e + g > 0) {
                    e = 0
                } else {
                    e = e + g
                }
                $("#logos").animate({
                    "margin-left": e
                }, {
                    queue: false,
                    duration: 300,
                    easing: "easeOutQuint"
                })
            }
        }
    }
    function p() {
        n()
    }
    function o(a) {
        clearInterval(q);
        var b = a.id;
        if (b !== d) {
            n(1, b)
        }
        q = setInterval(p, 5e3)
    }
    function n(e, f) {
        if (e == 1) {
            d = Number(f)
        } else {
            if (d < c - 1) {
                d = d + 1
            } else {
                d = 0
            }
        }
        for (j = 0; j < c + 1; j++) {
            if (k[j] == 1 && j !== d) {
                $(a[j]).css({
                    "z-index": 0
                });
                $(a[j]).animate({
                    top: "-273px",
                    opacity: "0"
                }, {
                    queue: false,
                    duration: 800,
                    easing: "easeOutQuint",
                    complete: function () {
                        $(this).css({
                            top: "273px",
                            opacity: "1"
                        })
                    }
                });
                $(b[j]).find("img").removeClass("active");
                k[j] = 0
            }
        }
        if (k[d] == 0) {
            $(a[d]).css({
                "z-index": 10
            });
            $(b[d]).find("img").addClass("active");
            $(a[d]).animate({
                top: 0
            }, {
                queue: false,
                duration: 1e3,
                easing: "easeOutQuint",
                complete: function () {
                    i = 1
                }
            });
            if (d == 0) {
                $(b[d]).find("img").addClass("active")
            } else {
                if (d == c - 1) {
                    $(b[d]).find("img").addClass("active")
                } else {
                    $(b[d]).find("img").addClass("active")
                }
            }
            $(".slider_link").attr("href", $(a[d]).find("a").attr("href"));
            k[d] = 1
        }
    }
    var a = $(".slides").children();
    var b = $("#logos").children();
    var c = Number(a.length);
    var d = -1;
    var e;
    var f;
    var g;
    var h;
    var i = 1;
    var k = new Array(c);
    var l = new Array(c);
    for (m = 0; m < c; m++) {
        k[m] = 0
    }
    for (m = 0; m < c; m++) {
        $(b[m]).attr("id", m)
    }
    $("#logos li").click(function () {
        if (i == 1) {
            o(this);
            i = 0
        }
    });
    r();
    p();
    var q;
    q = setInterval(p, 5e3);
    $(".arrow_right").click(function () {
        r(1)
    });
    $(".arrow_left").click(function () {
        r(0)
    })
})
