//-------------------------------------------------------------------
// If you change this document please email developer@mustardlab.com so I can offer the changes to be downloaded 
// at http://www.mustardlab.com/developer/flash/standards/
//-------------------------------------------------------------------

//-----------------------------------------------
// Edit version number to prompt download in IE
//-----------------------------------------------
var flash_version = "6,0,79,0"
var shockwave_version = "8,5,1,0"
var mediaplayer_version = "5,1,52,701"
var quicktime_version = "6,0,2,0"

//-------------------------------------------------
// The catchall value defines which plugin to use for non-proprietary formats like mp3 streams
// Allowable value must be a string representation of an object in the translation table
// The default is set to "mediaplayer" because all windows users are likely to have Windows Media Player installed
//-------------------------------------------------
var catchall = "mediaplayer"


//---------DO NOT EDIT BELOW THIS LINE UNLESS YOU NEED TO DEFINE A NEW PLUGIN-----------
/*
The translation table below contains objects with data that defines what types of data are associated to it and what to serve out to IE when dynamically writing a new object tag. 
There is no specific format for naming objects, use whatever you want, just make sure the variables inside that object meet the following criteria.
type: an array of mime types that will associate that plugin to a specific media format, remember to add the semicolon on the end of each media type
dataparam: the name attribute inside the <param> tag that normally defines the src of the data. (Example: Flash usually defines external data as <param name="movie" value="myfile.swf" />, so the dataparam value is "movie").
classid: the classid that will initialize the appropriate activex control
codebase(optional): url of a cab file that IE can prompt the user for download if they don't have the plugin necessary to display the media type, please keep version number as a seperate variable above so normal users don't have to dig through the translation table to define versions.
*/
var translation = {}
translation.flash = {}
translation.flash.type = ["application/x-shockwave-flash;"]
translation.flash.dataparam = "movie"
translation.flash.classid = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
translation.flash.codebase = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="+flash_version
translation.shockwave = {}
translation.shockwave.type = ["application/x-director;"]
translation.shockwave.dataparam = "src"
translation.shockwave.classid = "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
translation.shockwave.codebase = "http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version="+shockwave_version
translation.mediaplayer = {}
translation.mediaplayer.type = ["application/x-oleobject;", "video/avi;"]
translation.mediaplayer.dataparam = "fileName"
translation.mediaplayer.classid = "clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95"
translation.mediaplayer.codebase = "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version="+mediaplayer_version
translation.quicktime = {}
translation.quicktime.type = ["video/quicktime;"]
translation.quicktime.dataparam = "src"
translation.quicktime.classid = "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
translation.quicktime.codebase = "http://www.apple.com/qtactivex/qtplugin.cab#version="+quicktime_version
translation.real = {}
translation.real.type = ["application/smil;", "application/streamingmedia;", "application/vnd.rn-realmedia;", "application/vnd.rn-realplayer;", "application/vnd.rn-realsystem-rjs;", "application/vnd.rn-realsystem-rjt;", "application/vnd.rn-realsystem-rmj;", "application/vnd.rn-realsystem-rmx;", "application/vnd.rn-rn_music_package;", "application/vnd.rn-rsml;", "audio/vnd.rn-realaudio;", "audio/x-realaudio;", "audio/x-pn-realaudio;", "audio/x-pn-realaudio-plugin;", "audio/x-realaudio;", "image/vnd.rn-realflash;", "image/vnd.rn-realpix;", "text/vnd.rn-realtext;", "text/vnd.rn-realtext3d;", "video/vnd.rn-realvideo;"]
translation.real.dataparam = "src"
translation.real.classid = "clsid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA"





//--------------------------DO NOT EDIT BELOW THIS LINE----------------------------------


//----------------------------
// Attribute Functions
//----------------------------
function indexOfFirst(str, arr, offset){
	var i,found,out = str.length;
	if(!offset) offset = 0;
	for(i in arr){
		var pos = str.indexOf(arr[i], offset);
		if(pos > -1 && pos < out){
			out = pos;
			found = true;
		}
	}
	if(found == true) return out;
	else return -1;
}
function stripObjAttr(str, remove){
	str += " ";
	var st = str.indexOf(remove+"=");
	var en = str.indexOf(" ", st);
	if(st == -1){
		return str;
	}else{
		return str.substring(0, st) + str.substr(en);
	}
}
function getObjAttr(str, find){
	var len = find.length+1;
	var st = str.indexOf(find+"=");
	var en = indexOfFirst(str, [" ", ">"], st);
	if(st > -1 && en > -1 ){
		return str.substring(st+len, en);
	}else{
		return str;
	}
}
function inArray(arr, find){
	for(var i in arr){
		if(arr[i] == find) return true;
	}
	return false;
}

//-------------------------
// Build New Media Objects
//-------------------------
function switchobject(refobj){
	var i, plugobj = false;
	
	//-----------------------
	// Find Object Type
	//-----------------------
	for(i in translation){
		if(inArray(translation[i].type, refobj.type)) plugobj = translation[i];
	}
	if(!plugobj && translation[catchall]) plugobj = translation[catchall];
	
	if(plugobj){
		//-----------------------
		// Build Param Tags
		//-----------------------
		var params = refobj.childNodes;
		var paramwrite = "";
		for(var i in params){
			if(typeof(params[i]) == "object"){
				paramwrite += params[i].outerHTML;
			}
		}
		paramwrite += '<param name="'+plugobj.dataparam+'" value="'+getObjAttr(refobj.outerHTML, "data")+'" />';
		//alert(paramwrite);
		
		//-----------------------
		// Overwrite Object Tag
		//-----------------------
		var currentAttrs = refobj.outerHTML.substring(refobj.outerHTML.indexOf("<")+1, refobj.outerHTML.indexOf(">")).toLowerCase();
		var newAttrs = stripObjAttr(currentAttrs, "data");
		newAttrs = stripObjAttr(newAttrs, "type");
		newAttrs = stripObjAttr(newAttrs, "codetype");
		newAttrs = stripObjAttr(newAttrs, "noexternaldata");
		refobj.outerHTML = '<object '+newAttrs+' classid="'+plugobj.classid+'" codebase="'+plugobj.codebase+'">'+paramwrite+'</object>';
	}
}