﻿function setUpVideo(uniqueId, names, descriptions, videos, flowplayerKey, widths, heights) {

    var tabPanel = jQuery("#" + uniqueId + "_buttons");
    var tabs = tabPanel.find((".video-select-button"));

    var descriptionParagraph = jQuery("#" + uniqueId + "_description");
    var videoPlayer = uniqueId + "_player";

    // loop over de tabs
    tabs.each(function (index, tab) {
        var videoData = {
            tabs: tabs,
            videoPlayer: videoPlayer,
            descriptionParagraph: descriptionParagraph,
            name: names[index],
            description: descriptions[index],
            video: videos[index],
            key: flowplayerKey,
            width: widths[index],
            height: heights[index]
        }

        VideoSelector_addClickHandler(tab, videoData);
        if (index == 0) {
            jQuery(tab).find(".arrow-down").css("display", "block");
            jQuery(tab).addClass("video-select-button-active");

            var player = jQuery('#' + videoData.videoPlayer)
            player.attr("href", videoData.video);
            player.css("width", videoData.width + "px");
            player.css("height", videoData.height + "px");

            flowplayer(videoData.videoPlayer, 
                {
                    src: "/App_Themes/ConferenceSite/swf/flowplayer.commercial-3.2.7.swf",
                    wmode: 'opaque' 
                }, 
                {
                    clip: { autoPlay: false, autoBuffering: true },
                    key: videoData.key
                });




            jQuery(videoData.descriptionParagraph).html(videoData.description);
        } else {
            jQuery(tab).find(".arrow-down").css("display", "none");
            jQuery(tab).removeClass("video-select-button-active")
        }
    });


}

function VideoSelector_addClickHandler(tab, videoData) {

    jQuery(tab).click(function (e) {

        //verberg arrows
        jQuery(videoData.tabs).each(function (index, tab) {
            jQuery(tab).find(".arrow-down").css("display", "none");
            jQuery(tab).removeClass("video-select-button-active")
        })

        jQuery(tab).find(".arrow-down").css("display", "block");
        jQuery(tab).addClass("video-select-button-active")

        //jQuery(videoData.videoPanel).html(videoData.embedcode);
        jQuery(videoData.descriptionParagraph).html(videoData.description);

        var player = jQuery('#' + videoData.videoPlayer)
        player.attr("href", videoData.video);
        player.css("width", videoData.width + "px");
        player.css("height", videoData.height + "px");

        flowplayer(videoData.videoPlayer,
        {
            src: "/App_Themes/ConferenceSite/swf/flowplayer.commercial-3.2.7.swf",
            wmode: 'opaque'
        }, 
        {
            key: videoData.key 
        });

    });

}
