var t = n = 0, count;
$(document).ready(function () {
    count = $("#banner_list a").length;
    if (count <= 1) return;
    var lis = "<li class='on'>1</li>";
    for (var i = 2; i <= count; i++) {
        lis += "<li>" + i + "</li>";
    }
    $("#banner_index").append(lis);
    $("#banner_list a:not(:first-child)").hide();
    $("#banner_title").html($("#banner_list a:first #_title").html());
    $("#banner_index li").click(function () {
        var i = $(this).text() - 1;
        n = i;
        if (i >= count) return;
        var $A = $("#banner_list a:visible").fadeOut(500).parent().children().eq(i).fadeIn(1000);
        $("#banner_title").html($("#_title", $A).html());
        $(this).toggleClass("on");
        $(this).siblings().removeAttr("class");
    });
    t = setInterval("showAuto()", 4000);
    $("#banner").hover(function () { clearInterval(t) }, function () { t = setInterval("showAuto()", 4000); });


    var speed = 16;
    var $tab = $("#teachers");
    if ($tab.get(0)) {
        var $tab1 = $("#m_arquee_1");
        var $tab2 = $("#m_arquee_2");
        $tab2.html($tab1.html());

        var item_w = $("li:first", $tab1).width() + 8;
        var icount = $("li", $tab1).length;
        var a_width = item_w * icount;

        $tab1.width(a_width);
        $tab2.width(a_width);
        $tab.width(a_width * 2);

        var Marquee = function () {
            var mLeft = getPx($tab.css("margin-left"));
            if (mLeft + a_width <= 0) {
                $tab.css("margin-left", (0 - item_w) + "px");
            }
            else {
                $tab.css("margin-left", (mLeft - 1) + "px");
            }
        }
        var MyMar = setInterval(Marquee, speed);
        $tab.bind("mouseover", function () { clearInterval(MyMar) });
        $tab.bind("mouseout", function () { MyMar = setInterval(Marquee, speed) });
    }
});

function getPx(str) {
    var p = parseInt(str.replace('px', ''), 10);
    return (isNaN(p) ? 0 : p);
}

function showAuto() {
    n = n >= (count - 1) ? 0 : ++n;
    $("#banner li").eq(n).trigger('click');
}



