﻿
var t = n = count = 0;
$(function() {
    $("#play_list a:not(:first-child)").hide();
    var homeCarouselInterval = parseInt($("#hidHomeCarouselInterval").val());
    count = $("#play_list a").size();
    $("#play_info").html($("#play_list a:first-child").find("img").attr('alt'));
    $("#play_title").html($("#play_list a:first-child").find("img").attr('title'));
    $("#play_subtitle").html($("#play_list a:first-child").find("input").attr('value'));
    $("#playlink").attr("href", $("#play_list a:first-child").find("input").attr('name'));
    $("#play_text a:first-child").css({ "color": "white" });
    Cufon.replace(".playerControler a", { fontFamily: 'Steelfish', fontSize: '17px', hover: true });
    $("#play_info").click(function() { window.open($("#play_list a:first-child").attr('href'), "_blank") });
    fontReplace();
    $("#play_text a").click(function() {
        var i = $(this).text() - 1;
        var oldNumber = n;

        $("#play_text a").eq(oldNumber).css({ "color": "#ABC32B" });
        Cufon.replace(".playerControler a", { fontFamily: 'Steelfish', fontSize: '17px', hover: true });


        n = i;
        if (i >= count) return;
        $("#play_info").html($("#play_list a").eq(i).find("img").attr('alt'));
        $("#play_title").html($("#play_list a").eq(i).find("img").attr('title'));
        $("#play_subtitle").html($("#play_list a").eq(i).find("input").attr('value'));
        $("#playlink").attr("href", $("#play_list a").eq(i).find("input").attr('name'));
        $("#play_info").unbind().click(function() { window.open($("#play_list a").eq(i).attr('href'), "_blank") })
        $("#play_list a").filter(":visible").fadeOut(1500);
        $("#play_list a").eq(i).fadeIn(1500);


        $(this).css({ "color": "white" }).siblings().css({ "color": "#ABC32B" });
        fontReplace();
    });

    t = setInterval("showAuto()", homeCarouselInterval);
    $("#play").hover(function() { clearInterval(t) }, function() { t = setInterval("showAuto()", homeCarouselInterval); });

})

    function showAuto() {
        n = n >= (count - 1) ? 0 : n + 1;
        $("#play_text a").eq(n).trigger('click');
        fontReplace();
        Cufon.replace(".playerControler a", { fontFamily: 'Steelfish', fontSize: '17px', hover: true });
    }

    function previousClick() {
        n = n >= 0 ? n - 1 : (count - 1);
        $("#play_text a").eq(n).trigger('click');
        fontReplace();
        Cufon.replace(".playerControler a", { fontFamily: 'Steelfish', fontSize: '17px', hover: true });
    }

    function nextClick() {
        n = n >= (count - 1) ? 0 : n + 1;
        $("#play_text a").eq(n).trigger('click');
        fontReplace();
        Cufon.replace(".playerControler a", { fontFamily: 'Steelfish', fontSize: '17px', hover: true });
    }

