var s_flvBase = "http://www.employeeuniversity.com/previews/full/"; //Common FLV location

var s_flvPlayer = "/Code/flowplayer/static/swf/flowplayer.commercial-3.2.2.swf";
var s_flvPlayerControls = "/Code/flowplayer/static/swf/flowplayer.controls-tube-3.2.1.swf";

var b_Skip240WidthWarning = false; //true if image placed above

$(document).ready(function(){
    $("div.flvPlayer").each(function(n_index) {
        $(this).attr("id", "flvPlayer" + n_index);
        f_flvPlayer(this);
    });
});

function f_flvPlayer(object) {
    var o_id = $(object).attr("id");
    //var a_playlist = f_playlist($(object).html());
    var a_playlist = f_playlist($(object).attr("title"));
    $(object).attr("title", "");
    var n_length = a_playlist.length;

    if (n_length > 0) {
        var b_controll = false;
        if (n_length > 1) {
            b_controll = true;
        }
    } else {
        return false;
    }

    $f(o_id, {src: s_flvPlayer, wmode: "transparent"}, {
        key: '#$44a729dd1ada7171ea2',
        logo: null,
        playlist: a_playlist,
        plugins:  {
            controls: {
                playlist: b_controll,
                url: s_flvPlayerControls,
                timeColor: "#ffffff",
                borderRadius: "0px",
                bufferGradient: "none",
                slowForward: true,
                backgroundColor: "rgba(0, 0, 0, 0.5)",
                volumeSliderGradient: "none",
                slowBackward: false,
                timeBorderRadius: 0,
                progressGradient: "none",
                time: true,
                height: 18,
                tooltips: {
                    marginBottom: 5,
                    scrubber: true,
                    volume: true,
                    buttons: false
                },
                fastBackward: false,
                opacity: 1,
                border: "0px",
                volumeSliderColor: "#ffffff",
                bufferColor: "#000000",
                buttonColor: "#ffffff",
                mute: true,
                autoHide: {
                    enabled: true,
                    hideDelay: 500,
                    hideStyle: "fade",
                    mouseOutDelay: 500,
                    hideDuration: 400,
                    fullscreenOnly: true
                },
                backgroundGradient: [0.5,0.2,0],
                width: "100pct",
                display: "block",
                buttonOverColor: "#FF0000",
                fullscreen: false,
                timeBgColor: "#000000",
                scrubberBarHeightRatio: 0.4,
                bottom: 0,
                stop: true,
                zIndex: 1,
                sliderColor: "#9e9e9e",
                scrubberHeightRatio: 0.7,
                tooltipTextColor: "#D00000",
                sliderGradient: "none",
                timeBgHeightRatio: 0.99,
                volumeSliderHeightRatio: 0.4,
                name: "controls",
                volumeBarHeightRatio: 0.2,
                left: "50pct",
                tooltipColor: "#C9C9C9",
                durationColor: "#ff2929",
                play: true,
                fastForward: true,
                timeBorder: "1px solid rgba(0, 0, 0, 0.3)",
                progressColor: "#ffffff",
                volumeBorderRadius: 0,
                scrubberBorderRadius: 0,
                scrubber: true,
                volume: true,
                builtIn: false
            }
        },
        clip:  {
            autoPlay: false,
            autoBuffering: true,
            baseUrl: s_flvBase,
            onStart: function() {
                var s_Class = $(object).attr('class').split('Skip');
                var n_skip = parseInt(s_Class[1]);
                if (!isNaN(n_skip)) {
                    this.seek(n_skip);
                }
                if ($(object).hasClass("small") && b_Skip240WidthWarning) return;
                $(object).prepend($("div.message").html());
                $("div.HeadWarn").fadeTo(30000, 0).click(function(){
                    $(this).hide();
                });
            }
        }
    });
};

function f_playlist(a_comment) {
    var a_temp, s_url;
    var n_duration = 0;
    var a_playlist =[];
    //var a_comment = a_comment.replace(/(\<\!\-\-)?(\-\-\>)?/g, "").split(",");
    var a_comment = a_comment.split(",");
    for (var i in a_comment) {
        a_temp = $.trim(a_comment[i]).split("|");
        s_url = a_temp[0];
        if (typeof(a_temp[1]) !== "undefined") {
            n_duration = a_temp[1];
        }
        a_playlist[i] = {url: s_url, duration: n_duration};
        n_duration = 0;
    }
    return a_playlist;
};
