﻿var fading = false, active = false, animating = false, zOver = false, mouseover = false, time = 650, $tv_side, size_count = 0, size = 10, color;
function tvClick(id) {
    zOver = true;
    if(active == false && animating != true) {
            $tv_side.css("z-index","50");
            animating = true; active = true;
            $tv_side.animate({ marginLeft: '0', width: '490' }, { duration: time, complete: function() { animating = false; }
        });
    } 
    else if(active == true && animating != true)
    {
        animating = true; active = false;
        $tv_side.animate({ marginLeft: '465', width: '10' }, { duration: time, 
            complete: function() { 
                animating = false; 
                if(mouseover == false) { zOver = false;$tv_side.css("z-index","-30"); } else { zOver = false;$tv_side.css("z-index","50"); }
            } });
    }
    if(id){
        if($("dl.tvlist dd:nth-child("+id+")").length > 0) {
            var timeout = window.setTimeout(function(){play(id);},750);
        }
        else
        {
            alert("Error: No video with that ID was found");
        }
    }
}

function play(id) {
    $("dl.tvlist").ytplaylist({addThumbs:true,thumbSize:"small",playerWidth:420,playerHeight:300,autoPlay: true,autoPlayNthChild:id});
    $("#scroller").scrollTo("dl.tvlist dd:nth-child("+id+")", 800);
}

$(document).ready(function() {
    $("#selectskype").tooltip({ effect: "fade" });
    $tv_side = $("#tv_side");
    if ($tv_side.length > 0) {
        $('.tv_grip')
        .mouseenter(function() { $tv_side.css("z-index", "50"); mouseover = true; })
        .mouseleave(function() { mouseover = false; if (zOver == false) { $tv_side.css("z-index", "-30"); } })
        .click(function() {
            tvClick()
        });

        $("dl.tvlist").ytplaylist({ addThumbs: true, thumbSize: "small", playerWidth: 420, playerHeight: 300, autoPlay: false });

        var config = { over: function() { $(this).find(".title").hide(); $(this).find(".description").show(); },
            timeout: 700,
            out: function() { $(this).find(".title").show(); $(this).find(".description").hide(); }
        };

        $("dl.tvlist dd").hoverIntent(config);

        var scrolltimer
        $("#scroll_right")
            .mouseenter(function() {
                scrolltimer = window.setInterval(function() {
                    $("#scroller").scrollTo("+=12px", 80);
                }, 80);
            })
            .mouseleave(function() {
                window.clearInterval(scrolltimer);
            });
        $("#scroll_left")
            .mouseenter(function() {
                scrolltimer = window.setInterval(function() {
                    $("#scroller").scrollTo("-=12px", 80);
                }, 80);
            })
            .mouseleave(function() {
                window.clearInterval(scrolltimer);
            })
    }
});

