﻿(function ($) {
    $.fn.PlayList = function (playlist, options) {
        var defaults = {
            'flashplayerlocation': '/Scripts/JQuery/JWPlayer/player.swf',
            'wmode': "opaque",
            'allowscriptaccess': "always",
            'allownetworking': "all",
            'allowfullscreen': "true",
            'volume': "80",
            'bufferlength': "5",
            'quality': "false",
            'hidelogo': "false",
            'shuffle': "false",
            'width': 475,
            'height': 575,
            link: true,
            "controlbar": "bottom",
            'playlistposition': 'bottom',
            playlistheight: 250,
        };
        var options = $.extend(defaults, options);
        return this.each(function () {
            if ((options.height == null) || (options.height < 575)) {
                options.height = 575;
            }
            if (options.height > 575) {
                options.playlistheight = options.height - 325;
            }
            var flashVars = {
                'flashplayer': options.flashplayerlocation,
                'wmode': options.wmode,
                'allowscriptaccess': options.allowscriptaccess,
                'allownetworking': options.allownetworking,
                'allowfullscreen': options.allowfullscreen,
                'volume': options.volume,
                'bufferlength': options.bufferlength,
                'quality': options.quality,
                'logo.hide': options.hidelogo,
                'shuffle': options.shuffle,
                'width': options.width,
                'height': options.height,
                "link": options.link,
                "controlbar": options.controlbar,
                'playlist.position': options.playlistposition,
                'playlist.size': options.playlistheight,
                'playlist': playlist
            };
            flashVars["plugins"] = {
                "captions-2": {
                    file: options.captionsfile,
                    fontsize: "14"
                },
                "sharing-3": {
                    link: window.location.href
                }
            };
            jwplayer($(this).attr("id")).setup(flashVars);
        });
    };
})(jQuery);
