(function($){
    // plugin initialization
    $.fn.videoplayer = function(o){
        var videoplayer = this;
        if (videoplayer.length==0) { return videoplayer; }
        
        // Loading...
        videoplayer.html('<div style="text-align:center;padding-top:20%;"><img src="'+$.imageUrl('/img/tsclock.gif')+'" style="width:32px;display:block;margin:10px auto 0 auto;" /></div>');
        
        // Initialize options for this call
        videoplayer.options = $.extend({
            url : null,
            autoPlay : false,
            type : 'flowplayer',
            height: '100%',
            width: '100%',
            data: null
        },o);
        
        var flashUrl, flashVars;
        switch (videoplayer.options.type) {
            case 'flowplayer':
                case 'flowplayer':
                    flashUrl = $.flashUrl('/flash/flowplayer/flowplayer.commercial.fb-3.1.1.swf');
                    flashVars = "config={'key':'#$a0f13e4bb1cfa884de2','canvas':{'backgroundColor':'#000000'},'clip':{'url':'"+videoplayer.options.url+"','autoPlay':"+videoplayer.options.autoPlay+",'autoBuffering':true,'scaling':'fit','accelerated':true},'plugins':{'controls':{'url':'flowplayer.controls-3.1.1.swf'}}}";
                break
            case 'brightcove': 
                var data = videoplayer.options.data;
                flashUrl = "http://c.brightcove.com/services/viewer/federated_f9/"+data.playerid+"?isVid=1&isUI=true&publisherID="+data.accountid+"&autoStart=false";//+videoplayer.options.autoPlay;
                flashVars = "lineupId="+data.lineupid+"&videoId="+data.titleid+"&playerID="+data.playerid+"&domain=embed";
            break;
            case 'theplatform':
                // Do Nothing
            break;
            default:
                flashUrl = videoplayer.options.url;
                flashVars = null;
            break;
        }
        
        videoplayer.css("textAlign","center");
        embedCode = '<object type="application/x-shockwave-flash" data="'+flashUrl+'" width="'+videoplayer.options.width+'" height="'+videoplayer.options.height+'">';
        embedCode += '<param name="movie" value="'+flashUrl+'"/>';
        embedCode += '<param name="wmode" value="opaque"/>';
        embedCode += '<param name="allowFullScreen" value="true"/>';
        embedCode += '<param name="allowNetworking" value="all"/>';
        embedCode += '<param name="allowScriptAccess" value="never"/>';
        embedCode += '<param name="flashVars" value="'+flashVars+'"/>';
        embedCode += '<embed src="'+flashUrl+'" ';
        embedCode += 'width="'+videoplayer.options.width+'" height="'+videoplayer.options.height+'" type="application/x-shockwave-flash" ';
        embedCode += 'pluginspage="http://www.macromedia.com/go/getflashplayer" ';
        embedCode += 'wmode="opaque" allowNetworking="all" allowScriptAccess="never" ';
        embedCode += 'flashVars="'+flashVars+'">';
        embedCode += '</embed>';
        embedCode += '</object>';
        
        setTimeout(function(){videoplayer.html(embedCode);},300);
        
        return videoplayer;
    };
    
})(jQuery);