﻿
var t = n = count = 0;
$(function()
{
    count = $("#play_list a").size();
    if (count < 2)
    {
        return;
    }
    $("#play_list a:not(:first-child)").hide();

    $("#play_info").html($("#play_list a:first-child").find("img").attr('alt'));
    $("#play_text li:first-child").css({ "background": "#fff", 'color': '#000' });
    $("#play_info").click(function() { window.open($("#play_list a:first-child").attr('href'), "_self") });

    $("#play_text li").click(function()
    {
        var i = $(this).text();
        n = i;
        if (i >= count) return;

        var projectInfoString = $("#play_list a").eq(i).find("img").attr('alt');
        var projectLinkUrl = $("#play_list a").eq(i).attr('href');

        $("#play_info").html(projectInfoString);
        $("#play_info").unbind();
        $("#play_info").parent().attr('href', projectLinkUrl);


        var currentShownImage = $("#play_list a").filter(":visible");
        var nextShownImage = currentShownImage.parent().children().eq(i);

        currentShownImage.fadeOut(500);
        nextShownImage.fadeIn(1000);

        $(this).css({ "background": "#fff", 'color': '#000' }).siblings().css({ "background": "#000", 'color': '#fff' });
    });


    var projectCarouselInterval = parseInt($("#hidProjectCarouselInterval").val());
    t = setInterval("showAuto()", projectCarouselInterval);
    $("#play").hover(function() { clearInterval(t) }, function() { t = setInterval("showAuto()", projectCarouselInterval); });
})

function showAuto()
{
    n = parseInt(n);

    n = n >= (count - 1) ? 0 : n + 1;
    $("#play_text li").eq(n).trigger('click');
}

function previousClick()
{
    n = parseInt(n);
    
    n = n >= 1 ? n - 1 : (count - 1);
    $("#play_text li").eq(n).trigger('click');
}

function nextClick()
{
    n = parseInt(n);

    n = n >= (count - 1) ? 0 : n + 1;
    $("#play_text li").eq(n).trigger('click');
}


