document.write('<script language="JavaScript1.1" src="http://i.a.cnn.net/nascar/.element/js/2.0/global.js" type="text/javascript"><\/script>') /* 02/01/07 Site redesign */

function TPVidModuleUI(sFeed, sNameID)
{
	this.m_feed = sFeed;
    this.STATIC_IMAGE_PATH = "http://i.cnn.net/nascar/.element/img/1.1/sect/video/noflash_image.gif"; // TODO
	// this.COOKIE_DOMAIN="turner.com"; // needed if using on site runs on multiple domain names
    //this path needs to be changed -- jw
    this.NAME = sNameID;
    this.VERSION = 1;
    this.SWF_PATH = "http://i.cnn.net/nascar/.element/1.0/img/swf/trackpass_main.swf"; // TODO;
    //this path needs to be changed -- jw
}


TPVidModuleUI.prototype.logSession = function()
{
	// no expiration is set so the cookie is transient
	document.cookie = this.NAME + "=exists; path=/;"; //+ " domain=."+this.COOKIE_DOMAIN;
}


TPVidModuleUI.prototype.doesSessionExist = function()
{
	return ( document.cookie.indexOf(this.NAME + "=exists") != -1 );
}


// Not being used. 
// We are using Macromedia's getFlashVersion() code instead -- kd
TPVidModuleUI.prototype.getSWFPlayerVersion = function() 
{
    var version;
    // TODO :: INSERT CODE HERE
    return version; // integer
}


TPVidModuleUI.prototype.isAolBrowser = function()
{
    return (navigator.userAgent.toLowerCase().indexOf("aol") != -1); // boolean
}


TPVidModuleUI.prototype.getSWFParams = function(sFilePath, fVersion)
{
    var s = "";
    s+='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
    s+='codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
    s+='width="196" height="199" id="' + this.NAME + '">';
	s+='<param name="movie" value="' + sFilePath + '?NASCAR_version='+fVersion+'">'; 
    s+='<param name="quality" value="low">';
	s+='<param name="menu" value="true">';
    s+='<param name="FlashVars" value="NASCAR_feed='+this.m_feed+'&NASCAR_sessionExists='+(this.doesSessionExist() ? "true" : "false" )+'">';
	s+='<param name="bgcolor" value="#000000">';
    s+='<embed src="'+sFilePath +'?NASCAR_version='+fVersion+'" quality="high" menu="false" name="' + this.NAME + '" swLiveConnect="true"';
    s+='bgcolor="#000000" width="196" height="199" type="application/x-shockwave-flash" ';
	s+='FlashVars="NASCAR_feed='+this.m_feed+'&NASCAR_sessionExists='+(this.doesSessionExist() ? "true" : "false" )+'" ';
    s+='pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
    s+='</embed></object>';
    return s;
}


TPVidModuleUI.prototype.getControl = function(){

	var control;
	if (navigator.appName.indexOf ("Microsoft") !=-1) 
	{
		control = window[ this.NAME ];
	}	
	else 
	{
		control = document[ this.NAME ];
	}
	return control;
}

TPVidModuleUI.prototype.setSoundEnabled = function(bIsSoundEnabled){

	this.getControl().SetVariable("NASCAR_isSoundOn", (bIsSoundEnabled) ? "true" : "false");
}


TPVidModuleUI.prototype.getImageParams = function(){
    
    // TODO :: wrap image with link tags to go get flashplayer or
    //whatever usecase defines
    var s = '<a href="http://www.macromedia.com/go/getflashplayer" target="new"><img src="' + this.STATIC_IMAGE_PATH+ '" width="196" height="199" border="0" alt=""><\/a>';
    return s;
}


TPVidModuleUI.prototype.embed = function(){

    var embedCode;
    if ( (!this.isAolBrowser() && getFlashVersion() >= 6) || (this.isAolBrowser() && getFlashVersion() > 6) )
    {
       // embed swf
       embedCode = this.getSWFParams(this.SWF_PATH, this.VERSION);

    } else {
        // embed static image file
		embedCode = this.getImageParams();
    }

    document.write(embedCode);

	// log module has been created once
	this.logSession();
}


	var flashVersion = 0;
// -- Macromedia Flash javaScript
function getFlashVersion() {

	var agent = navigator.userAgent.toLowerCase(); 
	
   // NS3 needs flashVersion to be a local variable
   if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) {
      flashVersion = 0;
   }
   
	// NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if (typeof flashPlugin == 'object') { 
			if (flashPlugin.description.indexOf('9.') != -1) flashVersion = 9;
			else if (flashPlugin.description.indexOf('8.') != -1) flashVersion = 8;
			else if (flashPlugin.description.indexOf('7.') != -1) flashVersion = 7;
			else if (flashPlugin.description.indexOf('6.') != -1) flashVersion = 6;
			else if (flashPlugin.description.indexOf('5.') != -1) flashVersion = 5;
			else if (flashPlugin.description.indexOf('4.') != -1) flashVersion = 4;
			else if (flashPlugin.description.indexOf('3.') != -1) flashVersion = 3;
		}
	}

	// IE4+ Win32:  attempt to create an ActiveX object using VBScript
	else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
		document.write('<scr' + 'ipt language="VBScript"\> \n');
		document.write('on error resume next \n');
		document.write('dim obFlash \n');
		document.write('set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.7") \n');
		document.write('if IsObject(obFlash) then \n');
		document.write('flashVersion = 7 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.6") end if \n');
		document.write('if flashVersion < 7 and IsObject(obFlash) then \n');
		document.write('flashVersion = 6 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.5") end if \n');
		document.write('if flashVersion < 6 and IsObject(obFlash) then \n');
		document.write('flashVersion = 5 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.4") end if \n');
		document.write('if flashVersion < 5 and IsObject(obFlash) then \n');
		document.write('flashVersion = 4 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.3") end if \n');
		document.write('if flashVersion < 4 and IsObject(obFlash) then \n');
		document.write('flashVersion = 3 \n');
		document.write('end if');
		document.write('</scr' + 'ipt\> \n');
  }
		
	// WebTV 2.5 supports flash 3
	else if (agent.indexOf("webtv/2.5") != -1) flashVersion = 3;

	// older WebTV supports flash 2
	else if (agent.indexOf("webtv") != -1) flashVersion = 2;

	// Can't detect in all other cases
	else {
		flashVersion = flashVersion_DONTKNOW;
	}

	return flashVersion;
}

