// Utility functions for playlist implemented with jquery.scrollable.js
// Requires createWMVPlayer() utils.js

$(function() {
    var scrollableAPI;
    if (typeof ($("div.strip").scrollable) == 'function') {
        scrollableAPI = $("div.strip").scrollable();
    }

    // Set style for selected item, and unset for other items
    function setSelectedStyle(obj) {
        if (scrollableAPI) {
            if (typeof (scrollableAPI.getConf) == 'function') {
                var aclass = scrollableAPI.getConf().activeClass;
                obj.parent().siblings().removeClass(aclass);
                obj.parent().addClass(aclass);
            }
        }
    }

    // Mark the first item as selected
    var objFirstVideo = $("div.strip a.play:first");
    setSelectedStyle(objFirstVideo);

    // Initialize player with first item
    createWMVPlayer('playerholder', objFirstVideo.attr("href"), null, null, 'false');

    function initWMVPlayer(theFile) {
        $("#playerholder object").remove();
        createWMVPlayer('playerholder', theFile, null, null, 'true');
    }

    // Set onclick events for playlist
    $.each($(this).find('div.strip a.play'), function() {
        $(this).click(function() {
            setSelectedStyle($(this));
            initWMVPlayer($(this).attr("href"));
            return false;
        });
    });

    // Set mouseover, mouseout for nextPage
    var nextInterval;
    function seeNext() { scrollableAPI.next(); };
    $("a.nextPage").hover(
    function() { nextInterval = setInterval(seeNext, 600); seeNext(); },
    function() { clearInterval(nextInterval); }
  );

    // Set mouseover, mouseout for prevPage
    var prevInterval;
    function seePrev() { scrollableAPI.prev(); };
    $("a.prevPage").hover(
    function() { prevInterval = setInterval(seePrev, 600); seePrev(); },
    function() { clearInterval(prevInterval); }
  );
});


