/** version: Update Jan 14, 2008. b */

var	octo_embed_height, octo_embed_width;
var	octo_embed_wait_image, octo_embed_wait_height, octo_embed_wait_width;
var	octo_external_wait_popup, octo_external_wait_height, octo_external_wait_width;
var	octo_plugin_error, octo_plugin_missing;
var	octo_install_popup, octo_install_popup_features;
var octo_install_function;

var octo_player_div = 'dummy';
var octo_embed_has_been_called = false;
var octo_disabled = new Array();
var octo_startup_popup;
var octopv_wmpold = true;

// if this is 999, then everything is normal.
// else we will use it to override the result variable in the play_rec function
var octoPrivate = 999;
var octo_group = "";	// default epsilon group
var octoDebugDiv = false;		// if this is set (to a divID name) we display debug in the div.

// IE 4 fix. The global variable 'undefined' is not defined in  older IE browsers, so we define it here. 
this.undefined = this.undefined;

// If this returns false, octoshape is not installed, or not installed correctly
// Do not call this from the head section of a document, as the mime type function (used in firefox) adds a div to the body section
function octoOK(){
	if (octoNoBrowserPlugin()){ return false; }
	if (octoLowLevelCheck(octoLowLevelGet())){ return true; }
	return octoInstalledWithoutBrowserPlugin();
}

function octoDisable(octoLink){
	octo_disabled[octo_disabled.length] = octoLink;
}

function octoUsingProtocol(){
	return (octoNoBrowserPlugin() || octoInstalledWithoutBrowserPlugin());
}


// dummy function to be overwritten
function octoInstalledWithoutBrowserPlugin(){ return false; }
function octoNoBrowserPlugin(){
	var text = navigator.userAgent.toLowerCase();
	if (text.indexOf("opera") >= 0 || octopv_activexdisabled()) { 
		return true;
	}
	return false;
}


/***************************** PLAY FUNCTIONS *******************************/

// This will place an embedded media player in the div with the ID playerDIV_ID,
//  any previus content of the div will be discarded.
// Remember to place an install link on all pages where the play-link is, 
// since this function might show an alert asking the user to perform an install or re-install.
// The argument is the unique octolink you got from Octoshape
// player width and height are the video diplay area: there will be added 46 pixles to the height for the controls
// If we are on the mac and there is no windows media browser plug-in we call octoPlayExternal.
// returns true if we start to play imidiatly or we are starting up and then we are going to play
//         false if: disabled or we are on the mac or there was some error with the plug-in.
function octoPlayEmbedded(arg_octolink, playerDIV_ID, arg_player_width, arg_player_height){
	octopv_debug('we were asked to play embedded link: '+arg_octolink, arguments.callee);

	if (octopv_disabled(arg_octolink)){return false;}

	if (octoUsingProtocol()){
		window.location.href='OCTOSHAPE'+octo_group+':'+arg_octolink;
		return false;
	}
	
	if (octopv_isOSX() && !octopv_has_mime_wmplugin()){
		return octoPlayExternal(arg_octolink);
	}
	
	octo_player_div = playerDIV_ID;
	octo_embed_width=arg_player_width;
	octo_embed_height=arg_player_height;
	
	octo_embed_has_been_called=true;

	if(octopv_isOSX()){
		// we append the name of the player plugin to the octolink we give to the octoshape browser plugin.
		// this ensures that we get a working link back.
		var playerName = octopv_asf_plugin_name();
		if(playerName != ""){
			arg_octolink=arg_octolink+";"+playerName;
		}
	}	
	
	return octopv_play_rec_init(arg_octolink, false);
}

// returns true if we start to play imidiatly or we are starting up and then we are going to play
//         false if: disabled or there was some error with the plug-in.
function octoPlayExternal(OctoLink){
	if (octopv_disabled(OctoLink)){return false;}

	if (octoUsingProtocol()){
		window.location.href='OCTOSHAPE'+octo_group+':'+OctoLink;
		return false;
	}	
	return octopv_play_rec_init(OctoLink,true);
}

// IE: 		stops player (can be started again via the controls below the viewing area)
// Firefox: removes the player object, leaving the PlayerDIV empty.
function octoStopEmbedded() {
	if(!octo_embed_has_been_called) { return; }
	
	try  { document.octoPlayerObjectID.stop(); } 
	catch (e) 	{ 
		try { document.getElementById(octo_player_div).innerHTML = ''; } 
		catch (e2) { /* if there was no divmplayer we do nothing */ }
	}
}

function octopv_stop_embedded(obj){
	try 				{ obj.stop(); return true; } 
	catch (exception) 	{ return false; }
}

/*********************** CUSTOMIZING FUNCTIONS *******************************/

function octoSetAlertTexts(noPlugInText, errorPlugInText){
	octo_plugin_missing = (noPlugInText==null)? 	octoConfig.OCTO_ST_PLUGIN_MISSING	: noPlugInText;
	octo_plugin_error 	= (errorPlugInText==null)? 	octoConfig.OCTO_ST_PLUGIN_ERROR		: errorPlugInText;
}

function octoSetStartupPage(startupPage, startupWidth, startupHeight){
	octo_external_wait_popup 	= (startupPage==null)? 			octoConfig.OCTO_ST_EXTERNAL_WAIT_POPUP	: 	startupPage;
	octo_external_wait_height	= (startupHeight==null)?		octoConfig.OCTO_ST_EXTERNAL_WAIT_HEIGHT	: 	startupHeight;
	octo_external_wait_width	= (startupWidth==null)?			octoConfig.OCTO_ST_EXTERNAL_WAIT_WIDTH	:	startupWidth;

}

function octoSetStartupImage(startupImage, playerWidth, playerHeight){
	octo_embed_wait_image 	= (startupImage==null)? 		octoConfig.OCTO_ST_EMBED_WAIT_IMAGE		: startupImage;
	octo_embed_wait_height 	= (playerHeight==null)? 		octoConfig.OCTO_ST_EMBED_WAIT_HEIGHT	: playerHeight;
	octo_embed_wait_width 	= (playerWidth==null)? 			octoConfig.OCTO_ST_EMBED_WAIT_WIDTH		: playerWidth;
}


function octoSetInstallPopup(installPage, installPageFeatures){
	octo_install_popup 			= installPage;
	octo_install_popup_features = (installPageFeatures==null)? 	octoConfig.OCTO_ST_INSTALL_POPUP_FEATURES	: installPageFeatures;
}

function octoSetInstallFunction(javaScriptFunction){
	octo_install_function = (javaScriptFunction==null)? octoConfig.OCTO_ST_INSTALL_FUNCTION:javaScriptFunction;
}


function octoSetEmbedDisplay(show){
	octopv_set_param("showdisplay", show);
}


function octoSetEmbedStatusBar(show){
	octopv_set_param("showstatusbar", show);
}


function octoSetEmbedControls(play, audio){
	octopv_set_param("showcontrols", play);
	var aud = (typeof(audio) != "boolean")? play: audio;
	octopv_set_param("showaudiocontrols", aud);
}

function octoSetEmbedImageResize(resize){
	if(resize){
		octopv_embed_params["DisplaySize"] = 4;
	}else{
		octopv_embed_params["DisplaySize"] = 0;
	}
}

function octoUseWmp7Embedded(){
	octopv_wmpold = false;
}

/***************************************************************************************/
/********************************** PRIVATE FUNCTIONS *******************************/


var octopv_embed_params = new Object;
function octopv_set_param(paramname, value){
	if ((typeof(value))!="boolean"){ alert("The funtion octopv_set_param only accepts boolean values as second argument."); }
	else { octopv_embed_params[paramname.toLowerCase()] = value;  }
}

function ocvtopv_embed_calculate_height(){
	var ret = 0;
	if (octopv_embed_params["showcontrols"])	{ 
		ret += 26; 
		if (octopv_embed_params["showtracker"])	{ ret += 19; }
	}
	if (octopv_embed_params["showstatusbar"])	{ ret += 24; }
	
	if (octopv_embed_params["showgotobar"])		{ ret += 29; }
	if (octopv_embed_params["showdisplay"])		{ ret += 74; }
	if (octopv_embed_params["showcaptioning"])	{ ret += 89; }
	
	return ret;
}

function ocvtopv_embed_calculate_height_fx(){
	var ret = 0;
	if (octopv_embed_params["showcontrols"])	{ 
		ret += 27; 
		if (octopv_embed_params["showtracker"])	{ ret += 19; }
		if (octopv_embed_params["showstatusbar"]){ ret += 26; }
	} else if (octopv_embed_params["showstatusbar"]) { ret += 24; }
	
	if (octopv_embed_params["showgotobar"])		{ ret += 29; }
	if (octopv_embed_params["showdisplay"])		{ ret += 74; }
	if (octopv_embed_params["showcaptioning"])	{ ret += 89; }
	
	return ret;
}

function ocvtopv_embed_calculate_height_mac(){
	if(octopv_uses_flip4mac()){ 
		// The heigt of the controls in Flip4Mac browser plugin (they are always present but may be invisible).
		return 16; 
	}
	var ret = 0;
	if (octopv_embed_params["showcontrols"])	{ 
		ret += 27; 
		if (octopv_embed_params["showtracker"])	{ ret += 19; }
		if (octopv_embed_params["showstatusbar"]){ ret += 26; }
	} else if (octopv_embed_params["showstatusbar"]) { ret += 24; }

	if (octopv_embed_params["showdisplay"])		{ ret += 74; }

	return ret;
}
	


// cunstructor for the config object
function octopv_config(){
	// constants, dont change them.
	this.OCTO_ST_EMBED_HEIGHT			= octo_embed_height 			= 135;
	this.OCTO_ST_EMBED_WIDTH			= octo_embed_width				= 240;
	
	this.OCTO_ST_EMBED_WAIT_IMAGE 		= octo_embed_wait_image 		= "http://www.octoshape.com/images/upstart_16_9.GIF";
	this.OCTO_ST_EMBED_WAIT_HEIGHT		= octo_embed_wait_height		= 135;
	this.OCTO_ST_EMBED_WAIT_WIDTH		= octo_embed_wait_width			= 240;

	this.OCTO_ST_EXTERNAL_WAIT_POPUP 	= octo_external_wait_popup		= "http://www.octoshape.com/play/startup_popup.asp";
	this.OCTO_ST_EXTERNAL_WAIT_HEIGHT	= octo_external_wait_height		= 300;
	this.OCTO_ST_EXTERNAL_WAIT_WIDTH	= octo_external_wait_width		= 400; 

	this.OCTO_ST_PLUGIN_ERROR 			= octo_plugin_error				= "An error occurred while trying to play an Octoshape stream. \nPlease re-install the plug-in. ";
	this.OCTO_ST_PLUGIN_MISSING 		= octo_plugin_missing 			= "Please get the Octoshape Plug-In to play.";

	//this.OCTO_ST_INSTALL_POPUP 		= ="http://www.octoshape.com/download/external_install.asp";
	this.OCTO_ST_INSTALL_POPUP 			= octo_install_popup			= null;
	this.OCTO_ST_INSTALL_POPUP_FEATURES	= octo_install_popup_features	= 'height=400,width=520';
	this.OCTO_ST_INSTALL_FUNCTION		= octo_install_function			= octoDummy;
	
	octopv_set_param("showcontrols", true);
	octopv_set_param("showaudiocontrols", true);
	octopv_set_param("ShowPositionControls", false);
	octopv_set_param("ShowTracker", false);
	octopv_set_param("showdisplay", false);
	octopv_set_param("showcaptioning", false);
	octopv_set_param("showgotobar", false);
	octopv_set_param("ShowStatusBar", true);
	octopv_set_param("AutoSize", false); // AutoSize true will resize the PLAYER to fit the defualt content size. 
	
	octoSetEmbedImageResize(true);
	
}

function octoDummy(){}
var octoConfig = new octopv_config();

function octopv_disabled(octoLink){
	//	alert("testing: "+ octoLink);
	for (i=0;i<octo_disabled.length;i++){
		if (octoLink == octo_disabled[i]){
			alert("The stream is temporarily disabled.\n   Try again later.");
			return true;
		}
	}
	return false;
}

// If the octoshape plug-in is running, we play the link,
// if not, we start up the plugin, display a wait message to the user, waits in 2 seconds, and then start over agian.
// The default setting in the plug-in is to start up when the computer starts up, so most likely it will be running.
//	The player URL is set in case 1 and 2.
// returns 	true if we play or we are starting up
// 			false if: force install
function octopv_play_rec_init(octolink, externalplay){
	octopv_octolink = octolink;
	octopv_externalplay = externalplay;
	if(octopv_recursive_waiting){
		octopv_numRecur=0;
		octopv_oldStatus = 999;
		octopv_debug('not starting second recursive call. octolink is now: '+octopv_octolink, arguments.callee);
	}else{
		return octopv_play_rec();
	}
}

// JavaScript does has strange behavier when recursing with arguments, 
// to be on the safe side we have set the arguments as global variables before this call
var octopv_oldStatus;
var octopv_numRecur;
var octopv_plugin_instance;
var octopv_octolink;
var octopv_externalplay;
var octopv_recursive_waiting = false;

//var theOctoshapeClient;
function octopv_play_rec(){

	octopv_debug('recursiv play begin', arguments.callee);

	/*************************  PRIVATE FUNCTIONS  **************************/
	function insert_embedded_player(src, width, arg_height){
		var height = arg_height;
		if(height == null){
			octoSetEmbedStatusBar(false);
		} else if ((typeof height) != "number"){
			var num = parseInt(height, 10); 
			if (isNaN(num))	{ alert("The player height is not a number. \n\nPlayer height: " + height); }
			else 			{ height = num; }
		}
		var html  = "";
		
		if(octopv_isOSX() && !octoUsingProtocol()){
			var h = height + ocvtopv_embed_calculate_height_mac();
			html += "<embed ";
			html += " 	type=\"application/x-mplayer2\" ";
			html += " 	filename=\""+src+"\" ";
        	html += " 	src=\""+src+"\" ";
			html += "	name=\"octoPlayerObjectID\" ";
			html += "	kioskmode=\"true\" ";
			html += "	autoplay=\"true\" ";
			html += "	autostart=\"True\" ";
	        html += "	width=" + width+ " ";
        	html += "	height="+(h)+" ";
			for (var i in octopv_embed_params){
				html += " "+i+"=";
				var value = octopv_embed_params[i];
				if ((typeof(value))=="boolean"){ 
					html += (value)? "1 ": "0 "; 
				}else{
					html += value; 
				}
			}
    		html += "></embed>";
		}else{
			var clsid = octopv_wmpold? "22D6F312-B0F6-11D0-94AB-0080C74C7E95":"6BF52A52-394A-11D3-B153-00C04F79FAA6";
			
			html += "	<OBJECT ID=\"octoPlayerObjectID\" height=\""+(height + ocvtopv_embed_calculate_height())+"\" width=\""+width+"\"";
			html += "			classid=\"CLSID:"+clsid+"\"";
			html += "           STANDBY=\"Loading Octoshape plugin and client\"";
			html += "           pluginspage=\"http://microsoft.com/Windows/MediaPlayer/\" ";
			html += "			codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112\""; // checks if wmp is installed, if not it is installed automaticly 
			html += "           type=\"application/x-oleobject\">";
		
			for (var i in octopv_embed_params){ html += "<param name=\""+i+"\" value=\""+octopv_embed_params[i]+"\">"; }
		
			html += "           <param name=\"Loop\" value=\"0\">";
			html += "           <param name=\"Repeat\" value=\"false\">";
			html += "	        <param name=\"rate\" value=\"True\">";
			html += "	        <param name=\"defaultFrame\" value=\"\">";
			html += "	        <param name=\"playCount\" value=\"False\">";
			html += "	        <param name=\"mute\" value=\"False\">";
			html += "	        <param name=\"enableErrorDialogs\" value=\"False\">";	
			html += "           <param name=\"autostart\" value=\"true\">";
			html += "           <param name=\"PlayCount\" value=\"1\">";
			html += "           <param name=\"AutoRewind\" value=\"false\">";
			html += "	        <param name=\"URL\" value=\""+src+"\">";
			html += "	        <param name=\"src\" value=\""+src+"\">";

			html += "<embed ";
			html += " 	type=\"application/x-mplayer2\" ";
			html += " 	pluginspage=\"http://microsoft.com/Windows/MediaPlayer/\" ";
			html += " 	filename=\""+src+"\" ";
        	html += " 	src=\""+src+"\" ";
			html += "	name=\"octoPlayerObjectID\" ";
			for (var i in octopv_embed_params){
				html += " "+i+"=";
				var value = octopv_embed_params[i];
				if ((typeof(value))=="boolean"){ 
					html += (value)? "1 ": "0 "; 
				}else{
					html += value; 
				}
			}
			var h = (height + ocvtopv_embed_calculate_height_fx());
        	html += "	width=\"" + width + "\" ";
        	html += "	height=\""+h+"\" >";
    		html += "</embed>";
			html += "</OBJECT>";
		}
  		var divmplayer = document.getElementById(octo_player_div);
		divmplayer.innerHTML = html;
	}

	function do_install(){
		if (octo_install_popup != null){
			window.open(octo_install_popup, "install_popup", octo_install_popup_features);
		}
		octo_install_function();
	}
	
	// from -4 to 2: answer from octoclient
	// -10: no octoclient present
	// -20: octoclient had no getStatus function
	// -30: we had special error case where browser plug-in first answered 'starting up' and then was not installed
	// This function might throw an exception (?)
	// NB: IF octoPrivate < 100, this will overrule anything else (used in web setup pages only)
	function getStatus(){
		var status = -10;
		
		octopv_debug('getting the status', arguments.callee);
		
		if (!octoLowLevelCheck(octopv_plugin_instance)){ 
			octopv_debug('in getStatus() octoLowLevelCheck was false', arguments.callee);
			octopv_plugin_instance = octoLowLevelGet();
		}
		if (octoPrivate < 100){ return octoPrivate; }
		
		if (octoLowLevelCheck(octopv_plugin_instance)){ 
			// We query the activeX object to se what status the octoshape program is in
			// The parameter indicates whether we want the octoshape program to begin starting up, if it is not already running ...
			
			octopv_debug('calling client.getStatus(true) ', arguments.callee);
			
			status = octopv_plugin_instance.getStatus(true);

			
		}else{
			status = octoLowLevelCheckErrorCode;
		}

		// some users have experienced that when plugin installed but closed then:
		// pressing play the user gets 'octoshape is starting up' (status 1), 
		// but after a while the user gets 'please install' (status -10) and no music is played. 
		// solution: if we get -10 after we have gotten 2, we wait a while to see if we get something other than -10
		if (octopv_oldStatus == 1 && (status == -10 || status == -20)) {
			octopv_numRecur++;
			if (octopv_numRecur < 4){ 
				return 1;
			}else{
				// we have waited 8 seconds with no success
				return -30;
			}
		} 
				
		octopv_numRecur=0;
		octopv_oldStatus = status;
		return status;	
	}
	
	
	/*************************  END PRIVATE FUNCTIONS  **************************/
	try {
		var result = getStatus();
		
		octopv_recursive_waiting = false;
		octopv_debug('getStatus result: '+result, arguments.callee);
		
		switch (result){
			case -100:	octoPrivate = 999; return false; 	// do nothing: for web integration pages
			case -30:	// special error case 
				alert("An error occurred while trying to play an Octoshape stream.\nTry to refresh your browser window and play again.\n(error -30)");
				return false;	
			case -20:	// octoclient has no getStatus
				if(octo_plugin_missing != ""){
					alert(octo_plugin_missing+" (error -20)");
				}
				do_install();
				return false;	
 			case -10:	// no octoclient
				if(octo_plugin_missing != ""){
					alert(octo_plugin_missing);
				}
				do_install();
				return false;
				// case 0 will not happen since we call getStatus with true
	 		case 1:
	 			// octoshape is starting up, so we show some message to the user while s/he waits

	 			octopv_debug("starting up", arguments.callee);

				if (octopv_externalplay){
	
					if (octo_startup_popup == undefined){
						var features = "height="+octo_external_wait_height+",width="+octo_external_wait_width;
						octo_startup_popup = window.open(octo_external_wait_popup, "octo_popup", features);
					}
					
				} else {
					if (octopv_isFirefox()){
						var html = "<img src='"+octo_embed_wait_image+"' height='"+octo_embed_wait_height+"px' width='"+octo_embed_wait_width+"px'>";
						var divmplayer = document.getElementById(octo_player_div);
						divmplayer.innerHTML = html;
					}else{
						insert_embedded_player(octo_embed_wait_image, octo_embed_wait_width, octo_embed_wait_height);
					}
				}
	
				// we call our self again in 2000 milli-seconds
				setTimeout("octopv_play_rec();",2000);
				octopv_recursive_waiting = true;
	 			return true;
			case 2:
				// octoshape is already started up, so we just play the link

	 			octopv_debug("should begin to play", arguments.callee);
				
				// We get the link to play from the activeX object. The second parameter indicates whether we want to play in an external player.
				var playlink = 'OCTOSHAPE'+octo_group+':'+octopv_octolink;
				
				if (octopv_externalplay){
					octoStopEmbedded();
					if (octo_startup_popup != undefined){
						if(!octo_startup_popup.closed){
							octo_startup_popup.close();
						}
						octo_startup_popup = undefined;
					}
					
					window.location.href=playlink;
				}else {
					//embeddedPlay(octopv_plugin_instance.getLink(playlink,false));
					insert_embedded_player(octopv_plugin_instance.getLink(playlink,false), octo_embed_width, octo_embed_height);
				}
				
	 			return true;
	 		default:
				// there was an error from the octoshape plug-in, we need to ask the user to re-install
	 			alert(octo_plugin_error + "\n\nError number: " + result);
	 			do_install();
	 			
	 			return false;
		 }
	}
	catch (exception) {
		// This should really not happen, but just in case something went completely un-expectedly wrong, 
		// we must present the user with some form of crash recover help message.
		if(!octopv_debug("Exception occcered: "+exception, arguments.callee)){
			alert("An un-expected error occured while trying to start up the Octoshape plug-in. \n"+
				"Please try to shut down the plug-in and then press play again. \n" + 
				"To shut down: right click the system tray icon and choose exit. \n" + 
				"\n\n\nFunction getStatus response was: " + result + 
				"\nStartup link Exception:" + exception.description);
			do_install();
		}
		return false;
	}
}


/***************************************************************************************/
/********************************** LOW LEVEL FUNCTIONS *******************************/

var octoLowLevelPlayHelperObject = new Array(2);
function octoDummy(){}

function octopv_octoLowLevelPlayReset(){
	octoLowLevelPlayHelperObject.play=octoDummy;
	octoLowLevelPlayHelperObject.status=octoDummy;
}

octopv_octoLowLevelPlayReset();

// theOctoshapeClient is assumed to be a valid octoshape browser plug-in. 
// playfunction must be a function taking a link to be played.
function octoLowLevelPlay(theOctoshapeClient, fullOctoLink, getExternalLink, playfunction){
	octoLowLevelPlayHelperObject.play = function(){
		if(getExternalLink){
			playfunction(fullOctoLink);
		}else{
			var link = theOctoshapeClient.getLink(fullOctoLink, getExternalLink);
			playfunction(link);
		}
	};
	
	octoLowLevelPlayHelperObject.status = function(){
		return theOctoshapeClient.getStatus(true);
	}
	
	try {
		return octopv_octoLowLevelPlayRepeat();
	}
	catch (exception) {
		return -6;
	}
}



function octopv_octoLowLevelPlayRepeat(){
	var result = octoLowLevelPlayHelperObject.status();
		
	switch (result){
 		case 1:
			// we call our self again in 2000 milli-seconds
			var id = setTimeout("octopv_octoLowLevelPlayRepeat();",2000);
			return result;
		case 2:
			// octoshape is already started up, so we just play the link
			
			octoLowLevelPlayHelperObject.play();
			octopv_octoLowLevelPlayReset();
 			return result;
 		default:
 			return result;
	 }
}

var octoLowLevelCheckErrorCode=0;	// 0: all ok; -10: no plugin; -20 missing getStatus.

/* Getting the activeX object */
function octoLowLevelCheck(octoobject){
	if (typeof(octoobject) == "undefined"){
		octoLowLevelCheckErrorCode = -10;
		octopv_debug('octoobject is typeof undefined', arguments.callee);
		return false;
	}
	if (typeof(octoobject.getStatus) == "undefined") {
		octoLowLevelCheckErrorCode = -20;
		octopv_debug('octoobject.getStatus is typeof undefined', arguments.callee);
		return false;	
	}
	octoLowLevelCheckErrorCode = 0;
	octopv_debug('octoobject is fine', arguments.callee);
	return true;
}


// Get the octoshape activeX object with this function
// If we fail and have Firefox, we refresh the plug-ins, and try once more
function octoLowLevelGet(){
	// Do not call this directly, use octoLowLevelGet()
	// Do not call this from the head section of a document.
	
	octopv_debug('calling octoLowLevelGet', arguments.callee);
	
	function octopv_get_octoclient_sub(){
	
		// Do not call this from the head section of a document.
		function octopv_get_octoclient_mimetype() {
			var octomime = "application/x-octoshapeplugin"+octo_group+"-client";
			
			if (navigator && navigator.mimeTypes && navigator.mimeTypes.length) {
				var mimetype = navigator.mimeTypes[octomime];

				if (!mimetype) {
					octomime = octomime.toLowerCase();
					mimetype = navigator.mimeTypes[octomime];
				}

				if (mimetype) {
				var oDiv = document.createElement("DIV");
					document.body.appendChild(oDiv);
					
					/*
					oDiv.innerHTML = "<embed name=octoshapeclientobject id=octoshapeclientobject type=\""+octomime+"\" hidden=\"true\"></embed>";
					var octoshape = document.embeds["octoshapeclientobject"]; 
					if (octoLowLevelCheck(octoshape)) {
						octopv_debug("Client loaded using mimeTypes:" + octomime, arguments.callee);
						return octoshape;
					}*/
					
					if(octopv_isOSX()){
						oDiv.innerHTML = "<embed id=octoshapeclientobject type=\""+octomime+"\" hidden=\"true\"></embed>";
					}else{
						oDiv.innerHTML = "<object id=octoshapeclientobject type=\""+octomime+"\" hidden=\"true\"></object>";
					}
					var octoshape = document.getElementById('octoshapeclientobject');
					if (octoLowLevelCheck(octoshape)) {
						octopv_debug("Client loaded using mimeTypes:" + octomime, arguments.callee);
						return octoshape;
					}
				} 
			}
			return undefined;
		}

		try {
			if (window.ActiveXObject) {
				try {
					var octoshape = new ActiveXObject("octoshapeplugin"+octo_group+".client");
					if  (octoLowLevelCheck(octoshape)){ return octoshape; }
				} catch(exception) {}
			}
		
			if (window.GeckoActiveXObject) {
				try {
					var octoshape = new GeckoActiveXObject("octoshapeplugin"+octo_group+".client");
					if  (octoLowLevelCheck(octoshape)){ return octoshape; }
				} catch(exception) {}
			}

			// Crashes opera
			if (false && navigator && navigator.plugins && navigator.plugins.length) {
				var octoshape = navigator.plugins["application/x-octoshapeplugin"+octo_group+".client"];
				if  (octoLowLevelCheck(octoshape)){ return octoshape; }
			}		
		
			if (navigator && navigator.mimeTypes && navigator.mimeTypes.length) {
				var octoshape = octopv_get_octoclient_mimetype();
				if  (octoLowLevelCheck(octoshape)){ return octoshape; }
			}
			octopv_debug("Client loading failed all together.", arguments.callee);
			return undefined;
		} catch (exception) {
			return octopv_get_octoclient_mimetype();
		}
	}


	var obj = octopv_get_octoclient_sub();
	if (octoLowLevelCheck(obj)){
		return obj;
	}
	else {
		if(navigator.plugins){
			navigator.plugins.refresh(false);
			return (octopv_get_octoclient_sub());
		}
		return obj;
	}
}



/***************************************************************************************/
/********************************** UTILITY FUNCTIONS *******************************/

function octopv_activexdisabled(){
	var text = navigator.userAgent.toLowerCase();
	if (text.indexOf("msie") >= 0){ 
		try{
			var test = new ActiveXObject("Scripting.Dictionary");
		}catch(e){
			return true;
		}
	}
	return false;
}

function octopv_uses_flip4mac(){
	if(navigator && navigator.mimeTypes && navigator.mimeTypes.length){
		var mimeID = "video/x-ms-asf";
		var mime =  navigator.mimeTypes[mimeID];
		if(mime){
			var text  = mime.enabledPlugin.name.toLowerCase();
			return (text.indexOf("flip4mac") >=0);
		}
	}
	return false;
}


// returns true if there is a plug-in installed that can handle the video/x-ms-asf mime-type
function octopv_has_mime_wmplugin(){
	if(navigator && navigator.mimeTypes && navigator.mimeTypes.length){
		var mimeID = "video/x-ms-asf";
		var mime =  navigator.mimeTypes[mimeID];
		if(mime && mime.enabledPlugin){
			return true;
		}
	}
	return false;
}


function octopv_asf_plugin_name(){
	if(navigator && navigator.mimeTypes && navigator.mimeTypes.length){
		var mimeID = "video/x-ms-asf";
		var mime =  navigator.mimeTypes[mimeID];
		if(mime && mime.enabledPlugin){
			return mime.enabledPlugin.name;
		}
	}
	return "";
}

function octopv_isOSX(){
	var text = navigator.userAgent.toLowerCase();
	if (text.indexOf("mac os x") >= 0){ 
		return true;
	}
	return false;
}

function octopv_isFirefox(){
	var text = navigator.userAgent.toLowerCase();
	if (text.indexOf("firefox") >= 0){ 
		return true;
	}
	return false;
}

/* returns true if we are in debug mode. use: 
octopv_debug('', arguments.callee);
*/
function octopv_debug(str, func){
	if(typeof(octoDebugDiv) == 'boolean' && !octoDebugDiv){ return;  }
	try{
		var	div = document.getElementById(octoDebugDiv);
		if(div){
			var begin = div.innerHTML; 
			var index = begin.indexOf("</table>");
			if(index >=0){
				begin = begin.substring(0,index);
			}else{
				begin = "<table>";
			}
			var end = "</table>";
			
 			if( arguments.length == 1 ) {
 				div.innerHTML = begin + "<TR><TD>[unknown]<TD>|<TD>" + str+"</TR>"+end;
 				return true;
 			}else if(arguments.length == 2){
 				var funcStr = '' + func;
 				var a = funcStr.indexOf("{");
 				if(a>0){
	 				funcStr = funcStr.substring(0,a);
 				}
				div.innerHTML = begin  + "<TR ><TD>[" + funcStr + "]<TD>|<TD>" + str + "</TR>"+end;
 				return true;
	 		}
		}
	}catch (exception) { 
	}
	return false;
}
