﻿function SetCase(obj) {
    var toCase = obj.id.split('_')[1];
    setSwitch(toCase);
    
}
function setSwitch(newCase) {
    $("li[id*=liLider]:visible").fadeOut(300, function() {
        $("span[class=on]").removeClass("on");
        $("li[id=liLider_" + newCase + "]").fadeIn(300);
        $("span[id=spanCase_" + newCase + "]").addClass("on");
    });
}
function NextCase() {
    if ($("span[class=on]").size() > 0) {
        var currentCase = $("span[class=on]")[0].id.split('_')[1];
        var nextC = (parseInt(currentCase) + 1).toString();
        var nextCaseObj = $("span[id=spanCase_" + nextC + "]");
        if (nextCaseObj.length == 0) nextC = 0;
        setSwitch(nextC);
    }
}
function PrevCase() {
    if ($("span[class=on]").size() > 0) {
        var currentCase = $("span[class=on]")[0].id.split('_')[1];
        var prevC;
        if (currentCase > 0) prevC = (parseInt(currentCase) - 1).toString();
        else prevC = $("span[id*=spanCase_]:last")[0].id.split('_')[1];
        setSwitch(prevC);
    }
}

$(document).ready(function() {
    $(document).everyTime("7s", "timer1", function(i) {
        NextCase();
    });
    $("div[id*=divLeaders]").bind("mouseenter", function() {
        $(document).stopTime();
    }).bind("mouseleave", function() {
        $(document).stopTime().everyTime("7s", "timer1", function(i) { NextCase(); });

    });
});