﻿//
// create closure
//
(function ($) {
    jQuery.fn.video = function (options) {
        var defaults = {
            id: '',
            url: '',
            firstFrameUrl: '',
            width: '',
            height: '',
            topOffset: '',
            leftOffset: '',
            autoPlayback: false,
            scriptsFolder: ''
        };
        var opts = $.extend(defaults, options);

        return this.each(function () {
            // current object
            var _this = this;
            var $this = $(this);
            var cdnUrl = 'mp4:';
            //var cdnUrl = 'http://cdn.enterdraw.com/';

            $this.append($("<div class='player' id='player_" + opts.id + "'></div>"));
            flowplayer("player_" + opts.id, opts.scriptsFolder + "/flowplayer-3.2.5.swf", {      // supply the configuration
                //log: { level: "debug", filter: 'org.flowplayer.rtmp.*' },
                playlist: [
                    {
                        url: opts.firstFrameUrl,
                        scaling: 'orig'
                    },
                    {
                        provider:"rtmp",
                        //autoPlay: opts.autoPlayback,
                        autoPlay: false,
                        autoBuffering: false,
                        url: cdnUrl + opts.url
                    }
                ],
                screen: { height: opts.height, width: opts.width, top: opts.topOffset, left: opts.leftOffset },
                plugins: {
                    rtmp: {
                        url: opts.scriptsFolder + '/flowplayer.rtmp-3.2.3.swf',
                        netConnectionUrl: 'rtmp://cdns.enterdraw.com/cfx/st'
                    },
                    controls: {
                        borderRadius: "0px",
                        timeColor: "#ffffff",
                        bufferGradient: "none",
                        slowForward: true,
                        backgroundColor: "rgba(0, 0, 0, 0)",
                        volumeSliderGradient: "none",
                        slowBackward: false,
                        timeBorderRadius: 20,
                        progressGradient: "none",
                        time: true,
                        height: 26,
                        volumeColor: "#4599ff",
                        tooltips: {
                            marginBottom: 5,
                            scrubber: true,
                            volume: true,
                            buttons: false
                        },
                        fastBackward: false,
                        opacity: 1,
                        timeFontSize: 12,
                        bufferColor: "#a3a3a3",
                        border: "0px",
                        volumeSliderColor: "#ffffff",
                        buttonColor: "#ffffff",
                        mute: true,
                        autoHide: {
                            enabled: true,
                            hideDelay: 500,
                            mouseOutDelay: 500,
                            hideStyle: "fade",
                            hideDuration: 400,
                            fullscreenOnly: false
                        },
                        backgroundGradient: "none",
                        width: "100pct",
                        display: "block",
                        sliderBorder: "1px solid rgba(128, 128, 128, 0.7)",
                        buttonOverColor: "#ffffff",
                        fullscreen: true,
                        timeBgColor: "rgb(0, 0, 0, 0)",
                        scrubberBarHeightRatio: 0.2,
                        bottom: 0,
                        stop: false,
                        zIndex: 1,
                        sliderColor: "#000000",
                        scrubberHeightRatio: 0.6,
                        tooltipTextColor: "#ffffff",
                        sliderGradient: "none",
                        timeBgHeightRatio: 0.8,
                        volumeSliderHeightRatio: 0.6,
                        name: "controls",
                        timeSeparator: " ",
                        volumeBarHeightRatio: 0.2,
                        left: "50pct",
                        tooltipColor: "rgba(0, 0, 0, 0)",
                        playlist: false,
                        durationColor: "#b8d9ff",
                        play: true,
                        fastForward: true,
                        timeBorder: "0px solid rgba(0, 0, 0, 0.3)",
                        progressColor: "#4599ff",
                        scrubber: true,
                        volume: true,
                        builtIn: false,
                        volumeBorder: "1px solid rgba(128, 128, 128, 0.7)"
                    }
                }
            });
        });
    };
    //
    // end of closure
    //
})(jQuery);
