﻿var PlayInterval;
var PlayCurrentIndex = 0;
var PlaySize = 0;

function showAuto() {
    PlayCurrentIndex = PlayCurrentIndex >= (PlaySize - 1) ? 0 : ++PlayCurrentIndex;
    $("#play_text li").eq(PlayCurrentIndex).trigger('click');
}

$("#play").ready(function () {
    PlaySize = $("#play_list a").size();

    $("#play_list a:not(:first-child)").hide();
    $("#play_text li:first-child").addClass('current');
    $("#play_text li").hover(function () {
        clearInterval(PlayInterval);
        var i = $(this).children(":first-child").text() - 1;
        if (i >= PlaySize) return;
        PlayCurrentIndex = i;
        $("#play_list a").filter(":visible").fadeOut(100).parent().children().eq(i).fadeIn(200);
        $(this).addClass('current').siblings().removeClass('current');
    }, function () { PlayInterval = setInterval("showAuto()", 5000); });

    $("#play_text li").click(function () {
        var i = $(this).children(":first-child").text() - 1;
        if (i >= PlaySize) return;
        PlayCurrentIndex = i;
        $("#play_list a").filter(":visible").fadeOut(500).parent().children().eq(i).fadeIn(1000);
        $(this).addClass('current').siblings().removeClass('current');
    });

    PlayInterval = setInterval("showAuto()", 5000);
    //$("#play").hover(function () { clearInterval(PlayInterval) }, function () { PlayInterval = setInterval("showAuto()", 5000); });
});
