(function($){
	var FlashObj = function(){}
	FlashObj.prototype.movie = "";
	FlashObj.prototype.width = "0";
	FlashObj.prototype.height = "0";
	FlashObj.prototype.minversion = "8";
	FlashObj.prototype.parameters = new Array();
	
	
	function parseVersionFromCodebase(codebase){
		var retval = 8;
		if(typeof(codebase) == 'string'){
			var parts1 = codebase.split("#version=");
			if(typeof(parts1) == 'object' && parts1.length > 1){
				var parts2 = parts1[1].split(",");
				if(typeof(parts2) == 'object' && parts2.length > 1){
					retval = parseInt(parts2[0]);
				}
			}
		}
		return "" + retval;
	}
	
	
	$.fn.swfalt = function(userOpts){
		var opts = {bgcolor: "#FFFFFF"};
		if(typeof(userOpts) == 'object'){
			$.extend(opts, userOpts);
		}
		
		var obj = $(this).find("object:first");
		
		var flash = new FlashObj();
		
		flash.width = "" + (($(obj).attr("width") != '') ? $(obj).attr("width") : 0);
		flash.height = "" + (($(obj).attr("height") != '') ? $(obj).attr("height") : 0);
		flash.minversion = parseVersionFromCodebase($(obj).attr("codebase"));
		
		$(this).find(".flashContent param").each(function(){
			if(flash.movie == "" && $(this).attr("name") == "movie"){
				flash.movie = $(this).attr("value");
			}
			else if($(this).attr("name") != "width" && $(this).attr("name") != "height"){
				flash.parameters[$(this).attr("name")] = $(this).attr("value");
			}
		});
		
		$(this).remove("object");
		$(this).append("");
		
		
		// swfUrlStr, replaceElemIdStr, widthStr, heightStr, swfVersionStr, xiSwfUrlStr, flashvarsObj, parObj, attObj, callbackFn
		swfobject.embedSWF(flash.movie, $(this).attr("id"), flash.width, flash.height, flash.minversion, null, null, flash.parameters);
		
		
		flash = null;
	}
})(jQuery);
