// -- CNN javaScript
var agt		= navigator.userAgent.toLowerCase();
var versInt	= parseInt(navigator.appVersion);
var is_aol	= (agt.indexOf("aol") != -1);


// -- Macromedia Flash javaScript
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
function myFlash_DoFSCommand(command, args){
  var myFlashObj = InternetExplorer ? myFlash : document.myFlash;
  
  var str = args.substring(24,args.lastIndexOf("'")); 
  var argArr = str.split("','");
  LaunchVideo(argArr[0],argArr[1]);
  
}
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
  document.write('<SCRIPT LANGUAGE=VBScript\> \n');
  document.write('on error resume next \n');
  document.write('Sub myFlash_FSCommand(ByVal command, ByVal args)\n');
  document.write(' call myFlash_DoFSCommand(command, args)\n');
  document.write('end sub\n');
  document.write('</SCRIPT\> \n');
} 


// -- Skylab javaScript
function VideoTeaseGUI(sFeed){

    this._$feed = sFeed;
    this._$STATIC_IMAGE_PATH = "/.element/img/1.1/sect/video/noflash_image.gif"; // TODO
    //this path needs to be changed -- jw

    this._$IMAGE_SWF_VERSION = 1;
    this._$IMAGE_SWF_PATH = "http://i.cnn.net/cnn/video/videopage/ImageApp1.swf"; // TODO
    //this path needs to be changed -- jw

    this._$VIDEO_SWF_VERSION = 1;
    this._$VIDEO_SWF_PATH = "http://i.cnn.net/cnn/video/videopage/VideoApp1.swf"; // TODO
    //this path needs to be changed -- jw
}

VideoTeaseGUI.prototype.$inRealPlayer = function(){
	var inReal = false;

    // Using CNN code
	if ( canDetectPlugins() ) {
		if ( detectRealOne() ) {
			if ( agt.indexOf( "(r1 " ) != -1 ) {
				inReal = true;
			}
		} else {
			inReal = false;
		}
	}

	return inReal;
}

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


VideoTeaseGUI.prototype.$isAolBrowser = function(){

    // Using CNN code
    return (navigator.userAgent.toLowerCase().indexOf("aol") != -1); // boolean
}


VideoTeaseGUI.prototype.$isDialup = function(){

    var speed = WM_readCookie( "bitrate" );
    // read from video preferences cookie
    return (speed == 'low'); // boolean
}

VideoTeaseGUI.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="530" height="269" id="myFlash"><param name="movie" value="'; //kd: added id=myFlash
    s+=sFilePath + '?CNN_version='+fVersion+'" name="myFlash" swLiveConnect="true"> ';
    s+='<param name="quality" value="high"><param name="menu" value="false">';//kd: added name="myFlash" swLiveConnect="true"
    s+='<param name="FlashVars" value="CNN_feed='+this._$feed+'"><param name="bgcolor" value="#000000">';
    s+='<embed src="'+sFilePath +'?CNN_version='+fVersion+'" quality="high" menu="false" ';
    s+='bgcolor="#000000" width="530" height="269" type="application/x-shockwave-flash" FlashVars="CNN_feed='+this._$feed+'" ';
    
    s+='pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
    s+='</embed></object>';
    return s;
}

VideoTeaseGUI.prototype.$getImageParams = function(){
    
    // TODO :: wrap image with link tags to go get flashplayer or
    //whatever usecase defines
    var s = '<img src="' + this._$STATIC_IMAGE_PATH+ '" width="530" height="269" border="0" alt="" />';
    return s;
}

VideoTeaseGUI.prototype.embed = function(){

    var embedCode;

    if ( (this.$inRealPlayer()  && getFlashVersion() >= 6)
         || (getFlashVersion() == 6 && !this.$isAolBrowser())
         || (getFlashVersion() > 7 && this.$isDialup())
        )
   {
       // embed image sequence swf
       embedCode = this.$getSWFParams(this._$IMAGE_SWF_PATH, this._$IMAGE_SWF_VERSION);

    } else if (getFlashVersion() >= 7) //else if (getFlashVersion() > 7)
    {
       // embed video swf
       embedCode = this.$getSWFParams(this._$VIDEO_SWF_PATH, this._$VIDEO_SWF_VERSION);

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

    document.write(embedCode);
}

// -- Macromedia Flash javaScript
var flashVersion = 0;
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('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;
}



