var player;

function playerReady(obj) {
	player = jQuery('#'+obj["id"])[0];
};

jQuery.fn.createPlayer = function (movie_url, options) {
    var settings = jQuery.extend({
        autoplay: false,
        width: this.width(),
        height: this.height(),
        allowFullScreen: true,
        thumb_url: "", 
        showControls: true,
        skin: "",
        player: "" 
    }, options);
    
    function vs(v) { return v.major + '.' + v.minor + '.' + v.rev; };
    
    return this.each(function() {
        var flashvars = {
            file: movie_url,
            bufferlength: 4,
            icons: false,
            repeat: "list",
            width: settings.width,
            height: settings.height,
            lightcolor: "339900",
            backcolor: "000000",
            frontcolor: "AAAAAA",
            skin: settings.skin,
            autostart: settings.autoplay
        };
        var params = {
            allowFullScreen: settings.allowFullScreen,
            allowScriptAccess: "always",
            wmode: "transparent"
        };
        var attributes = {};
        if (settings.thumb_url) {
            flashvars.image = settings.thumb_url;
        }
        if (settings.showControls) {
            flashvars.controlbar = "over";
        } else {
            flashvars.controlbar = "none";
        }
        if (settings.autoplay) {
            flashvars.autostart = true;
        }
        var player_url = settings.player;
        flash_version = swfobject.getFlashPlayerVersion();
        ver = flash_version.major + "." + flash_version.minor + "." + flash_version.release;
        swfobject.embedSWF(player_url, this.id, settings.width, settings.height, ver,"expressInstall.swf", flashvars, params, attributes);
    });
};
