/////////////////////////

var ie;
var ie4;
var ie5;
var ie6;
var ie7;
var saf312;
var mo;
var mo1_7;
var ff;
var ff1_5;
var nn;
var nn7;
var nn8;
var op;
var op5;
var op6;
var op7;
var op8;
var op9;
var saf;
var win;
var mac;
var lin;


/***********************************************************************************************************************/


function detectBrowserAndOS(){
 /*
Script Name: Full Featured Javascript Browser/OS detection
Authors: Harald Hope, Tapio Markula, Websites: http://techpatterns.com/
http://www.nic.fi/~tapio1/Teaching/index1.php3
Script Source URI: http://techpatterns.com/downloads/javascript_browser_detection.php
Version 4.2.2
Copyright (C) 08 July 2005

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

Lesser GPL license text:
http://www.gnu.org/licenses/lgpl.txt

Coding conventions:
http://cvs.sourceforge.net/viewcvs.py/phpbb/phpBB2/docs/codingstandards.htm?rev=1.3
*/

/*************************************************************
Full version, use it if you are pushing css to its functional limits, and/or are using 
specialized javascript.

Remember, always use method or object testing as your first choice, for example, if ( dom ) { statement; };

This browser detection includes all possibilities I think for most browsers.
Let me know if you find an error or a failure to properly detect, or if there
is a relevant browser that has special needs for detection at our tech forum:
http://techpatterns.com/forums/forum-11.html
The main script is septtonarated from the initial netscape 4 detection due to certain bugs in
netscape 4 when it comes to unknown things like d.getElementById. The variable declarations
of course are made first to make sure that all the variables are global through the page, 
otherwise a javascript error will occur because you are trying to use an undeclared variable.

We test for both browser type (ie, op, or moz/netscape > 6) and version number, then place 
the version number into a variable which can be tested for < or > values, such as 
if (moz && nu> 1.1){....statement....;}
This seems quite reliable, especially for Opera and Mozilla, where there is no other
easy way to get the actual version number.

For more in depth discussion of css and browser issues go to:
http://www.nic.fi/~tapio1/Teaching/DynamicMenusb.php#detections
http://www.nic.fi/~tapio1/Teaching/FAQ.php3

***************************************************************/
	//initialization, browser, os detection
	var d, dom, nu='', brow='';
	var ns4, moz, moz_rv_sub, release_date='', moz_brow, moz_brow_nu='', moz_brow_nu_sub='', rv_full=''; 
	var old, ie5mac, ie5xwin, konq;

	d = document;
	n = navigator;
	nav = n.appVersion;
	nan = n.appName;
	nua = n.userAgent;
	old = (nav.substring(0, 1)<4);
	mac = (nav.indexOf('Mac')!= -1);
	win = (((nav.indexOf('Win')!= -1) || (nav.indexOf('NT') != -1)) && !mac) ? true : false;
	lin = (nua.indexOf('Linux')!= -1);

	// begin primary dom/ns4 test
	// this is the most important test on the page
	if(!document.layers){
		dom = (d.getElementById) ? d.getElementById : false;
	}else{
		dom = false; 
		ns4 = true;// only netscape 4 supports document layers
	}
	// end main dom/ns4 test

	op = (nua.indexOf('Opera') != -1);
	saf = (nua.indexOf('Safari') != -1);
	konq = (!saf && (nua.indexOf('Konqueror') != -1) ) ? true : false;
	moz = ( (!saf && !konq ) && ( nua.indexOf('Gecko') != -1 ) ) ? true : false;
	ie = ((nua.indexOf('MSIE') != -1)&&!op);
	if(op){
		str_pos = nua.indexOf('Opera');
		nu = nua.substr((str_pos + 6),4);
		brow = 'Opera';	
	}else if(saf){
		str_pos = nua.indexOf('Safari');
		nu = nua.substr((str_pos + 7),5);
		brow = 'Safari';
	}else if(konq){
		str_pos = nua.indexOf('Konqueror');
		nu = nua.substr((str_pos + 10),3);
		brow = 'Konqueror';
	}
	// this part is complicated a bit, don't mess with it unless you understand regular expressions
	// note, for most comparisons that are practical, compare the 3 digit rv nubmer, that is the output
	// placed into 'nu'.
	else if (moz){ 
		// regular expression pattern that will be used to extract main version/rv numbers
		pattern = /[(); \n]/;
		// moz type array, add to this if you need to
		moz_types = new Array('Firebird', 'Phoenix', 'Firefox', 'Galeon', 'K-Meleon', 'Camino', 'Epiphany', 
		'Netscape6', 'Netscape', 'MultiZilla', 'Gecko Debian', 'rv');
		
		rv_pos = nua.indexOf( 'rv' );// find 'rv' position in nua string
		rv_full = nua.substr( rv_pos + 3, 6 );// cut out maximum size it can be, eg: 1.8a2, 1.0.0 etc
		// search for occurance of any of characters in pattern, if found get position of that character
		rv_slice = ( rv_full.search( pattern ) != -1 ) ? rv_full.search( pattern ) : '';
		//check to make sure there was a result, if not do  nothing
		// otherwise slice out the part that you want if there is a slice position
		( rv_slice ) ? rv_full = rv_full.substr( 0, rv_slice ) : '';
		// this is the working id number, 3 digits, you'd use this for 
		// number comparison, like if nu >= 1.3 do something
		nu = rv_full.substr(0, 3);
		for(i = 0; i < moz_types.length; i++){
			if(nua.indexOf(moz_types[i]) != -1){
				moz_brow = moz_types[i];
				break;
			}
		}

		// if it was found in the array
		if(moz_brow){
			str_pos = nua.indexOf(moz_brow);// extract string position
			moz_brow_nu = nua.substr( (str_pos + moz_brow.length + 1), 3);// slice out working number, 3 digit
			// if you got it, use it, else use nu
			moz_brow_nu = (isNaN( moz_brow_nu )) ? moz_brow_nu = nu: moz_brow_nu;
			moz_brow_nu_sub = nua.substr((str_pos + moz_brow.length + 1), 8);
			// this makes sure that it's only the id number
			sub_nu_slice = (moz_brow_nu_sub.search(pattern) != -1) ? moz_brow_nu_sub.search(pattern) : '';
			//check to make sure there was a result, if not do  nothing
			(sub_nu_slice) ? moz_brow_nu_sub = moz_brow_nu_sub.substr(0, sub_nu_slice) : '';
			//nu=moz_brow_nu;
		}
		if(moz_brow == 'Netscape6'){
			moz_brow = 'Netscape';
		}else if (moz_brow == 'rv' || moz_brow == '')// default value if no other gecko name fit
		{
			moz_brow = 'Mozilla';
		} 
		brow = moz_brow;
		nu = moz_brow_nu;
		
		if(!moz_brow_nu)// use rv number if nothing else is available
		{
			moz_brow_nu = nu;
			moz_brow_nu_sub = nu;
		}
		if(n.productSub){
			release_date = n.productSub;
		}
	}
	else if(ie){
		str_pos = nua.indexOf('MSIE');
		nu = nua.substr((str_pos + 5), 3);
		brow = 'Microsoft Internet Explorer';
	}
	// default to navigator app name
	else{
		brow = nan;
	}

	if(op){
		op5 = (op&&(nu.substring(0,1)==5));
		op6 = (op&&(nu.substring(0,1)==6));
		op7 = (op&&(nu.substring(0,1)==7));
		op8 = (op&&(nu.substring(0,1)==8));
		op9 = (op&&(nu.substring(0,1)==9));
	}else if(saf){ 
		saf312 = ( nu.substring(0,3)==312 ); 
	}else if(ie){ 
		ie4 = (ie&&!dom);
		ie5 = (ie&&(nu.substring(0,1)==5));
		ie6 = (ie&&(nu.substring(0,1)==6));
		ie7 = (ie&&(nu.substring(0,1)==7));
	}else if(brow == 'Netscape'){ 
		nn = true;
		nn7 = (nu.substring(0,1) == 7);
    	nn8 = (nu.substring(0,1) == 8);
	}else if(brow == 'Firefox'){
		ff = true;
		ff1_5 = (nu.substring(0,3) == 1.5);
	}else if(brow == 'Mozilla'){
		mo = true;
		mo1_7 = (nu.substring(0,3) == 1.7);	 
	}
	// default to get number from navigator app version.
	if(!nu){
		nu = nav.substring(0, 1);
	}
	/*ie5x tests only for functionavlity. dom or ie5x would be default settings. 
	Opera will register true in this test if set to identify as IE 5*/
	ie5x = (d.all&&dom);
	ie5mac = (mac&&ie5);
	ie5xwin = (win&&ie5x);
}


/*******************************************************************************************************************/





/*
This function will call the media player after 
checking the type of file passed and after 
checking the installed plugins
*/
var custom;
var pluginDetected;
function startVideo(target, w, h, wmv, ram, mov, flash,cap){
	
	
	//alert('Inside StartVideo()');
	//alert("flash:"+flash);
	//alert("captions:"+cap);
	//alert("wmv: "+wmv);
	//alert("ram: "+ram);
	//alert("mov: "+mov);
	custom = false;
    pluginDetected = '';
	detectBrowserAndOS();
		
	//alert('Windows Media ' + Plugin.isInstalled("Windows Media"));
	//alert('QuickTime ' + Plugin.isInstalled("QuickTime"));
	//alert('RealPlayer ' + Plugin.isInstalled("RealPlayer"));
	//alert('FlashPlayer:'+Plugin.isInstalled("Flash"));




    if((wmv != 'undefined' && wmv != eval('') && wmv != null && wmv != '') && Plugin.isInstalled("Windows Media")){   
		this.plugin = "Windows Media";
		pluginDetected = "WindowsMedia";
		h = h + 35;
		Plugin.embed("Windows Media", {width: w, height: h, src: wmv, autoplay:true, autostart:true}, target, custom);
        return false;
    }else if((ram != 'undefined' && ram != eval('') && ram != null && ram != '') && (Plugin.isInstalled("RealPlayer"))){     
		this.plugin = 'RealPlayer';
		pluginDetected = "RealPlayer";
		h = h + 32;
		Plugin.embed("RealPlayer", {width: w, height: h, src: ram, autoplay:true, autostart:true}, target, custom);
       	return false;
     }	else if((mov != 'undefined' && mov != eval('') && mov != null && mov != '') && Plugin.isInstalled("QuickTime")){
		this.plugin = "QuickTime";
		pluginDetected = "QuickTime";
		h = h + 37;
		Plugin.embed("QuickTime", {width: w, height: h, src: mov, autoplay:true, autostart:true}, target, custom);
       	return false;
	}else if((flash != 'undefined' && flash != eval('') && flash != null && flash != '') && Plugin.isInstalled("Flash")){
	  	this.plugin = "Flash";
		pluginDetected = "Flash";
		h = h + 37;
		Plugin.embed("Flash", {width: w, height: h, src: flash,captions:cap, autoplay:true, autostart:true}, target, custom);
       	return false;
	} else{
		window.location = '/mediaplayer/no_plugin.html';
		return false;
	} 
	return;
}





PluginFactory = function()
{
  	// Returns if plugin with identifier name is installed
	// @see Plugin.getInfo
	this.isInstalled = function(name)
	{
    var installStatus = Plugin.getInfo(name).isInstalled; 
	if (installStatus == false)
	{
       return false;
    }
	else if (installStatus == true)
	{
		return true;
	}
    return Plugin.getInfo(name).isInstalled;
    }
  
    // Returns version number of plugin if available
    // @see Plugin.getInfo
   this.getVersion = function(name)
   {
	return Plugin.getInfo(name).version;
   }

   
   
// Returns an Array of plugin identifier names, 
// that can handle this mimeType.
this.getPluginsForMimeType = function(mimeType)
{
	var result = [];
    if(supportsNavigatorPlugins())
	{
		// navigator.mimeTypes
		for (var i=0; i<navigator.mimeTypes.length; i++)
		{
			if (navigator.mimeTypes[i].type.indexOf(mimeType) == 0 && navigator.mimeTypes[i].enabledPlugin)
			{
				var pluginName = (findPluginName(navigator.mimeTypes[i].enabledPlugin.name) || navigator.mimeTypes[i].enabledPlugin.name);
				if (!Array.contains(result, pluginName)) result.push(pluginName);
			}
		}
	}
	else 
	{
		// Code for IE using ActiveX
		for (var pluginName in Plugin.PLUGINS) {
			var mimeTypes = Plugin.PLUGINS[pluginName].acceptedMimeTypes;
			if (!mimeTypes){
				continue;
			}
			for (var j=0; j<mimeTypes.length; j++) {
				if (mimeTypes[j].type.indexOf(mimeType) == 0 && Plugin.isInstalled(pluginName)) {
					if (!Array.contains(result, pluginName)){
						result.push(pluginName);
					}
				}
			}
		}    
	}
	return result;
  }
  
  

  // Returns an Array of plugin identifier names, 
  // that can handle a file with this suffix.
  this.getPluginsForFileSuffix = function(suffix) {
    var result = [];
    if (supportsNavigatorPlugins()) {
      // navigator.mimeTypes
      for (var i=0; i<navigator.mimeTypes.length; i++) {
        if ((","+navigator.mimeTypes[i].suffixes+",").indexOf(","+suffix+",") != -1 && navigator.mimeTypes[i].enabledPlugin) {
          var pluginName = (findPluginName(navigator.mimeTypes[i].enabledPlugin.name) || navigator.mimeTypes[i].enabledPlugin.name);
          if (!Array.contains(result, pluginName)) result.push(pluginName);
        }
      }
    } else {
      // Code for IE using ActiveX
      for (var pluginName in Plugin.PLUGINS) {
        var mimeTypes = Plugin.PLUGINS[pluginName].acceptedMimeTypes;
        if (!mimeTypes) continue;
        for (var j=0; j<mimeTypes.length; j++) {
          if ((","+mimeTypes[j].suffixes+",").indexOf(","+suffix+",") != -1 && Plugin.isInstalled(pluginName)) {
            if (!Array.contains(result, pluginName)) result.push(pluginName);
          }
        }
      }    
    }
    return result;
  }

  
  
  // Returns general information about a plugin.
  // accepts: Acrobat, QuickTime, DivX, Director, 'Windows Media', 
  // Flash, Java, RealPlayer, VLC
  this.getInfo = function(name)
  {
	 		
    var info = Plugin.PLUGINS[name];
    var isInstalled = false;
    var version = null;

    if(supportsNavigatorPlugins())
	{
		var plugin = findNavigatorPluginByName((name == "Real Player") ? "RealPlayer Version Plugin" : name);
		if(plugin){
			isInstalled = true;
			version = getVersionFromPlugin(plugin);
		}
	}
	else
	{
		// Code for IE using ActiveX
		isInstalled = hasActiveXObject(Plugin.PLUGINS[name] && Plugin.PLUGINS[name].progID);
		if(isInstalled){
			if(Plugin.PLUGINS[name].getActiveXVersionInfo){
			version = Plugin.PLUGINS[name].getActiveXVersionInfo();
        }else{
          //assume that the progID contains the version number
          //this is not always correct
          var progID = getProgIdForActiveXObject(Plugin.PLUGINS[name].progID);
          version = getVersionFromPlugin(progID);
        }
      }
    }

    var result = {};
    for(var i in info)
	{
      result[i] = info[i];
    }
    result["isInstalled"] = isInstalled;
    result["version"] = version;
    result["name"] = name;

    return result;
  }

  
/********************************************************************************************************************/  
/**
 * writes an embed or object tag to document.write or target.
 * @param plugin   name of the plugin to be used
 * @param options  options for embed respectivly object tag.
 * .src,.width,.height,.type,.activeXType will get a special treatment
 * all other properties of options will be added to the 
 * embed tag as attributes resp. to the object tag as param(eters).
 * option names should be lower case!
 * @param target   optional (id of) container element for the embed/object tag
 */
  this.embed = function(plugin, options, target, custom){
    var options = options || {};

    var embedOptions = Object.extend({}, options);
    var src = embedOptions.src;
    delete embedOptions.src;
	var captions = embedOptions.captions;
    delete embedOptions.captions;
	var id = embedOptions.id;
    delete embedOptions.id;
    
	var id='javademo';
	var name='javademo';
	
    delete embedOptions.name;
    var width = embedOptions.width;
    delete embedOptions.width;
    var height = embedOptions.height;
    delete embedOptions.height;
    var type = embedOptions.type || (Plugin.PLUGINS[plugin] && Plugin.PLUGINS[plugin].mimeType) || "";
    delete embedOptions.type;
    var activeXType = embedOptions.activeXType || (Plugin.PLUGINS[plugin] && Plugin.PLUGINS[plugin].activeXType) || type;
    delete embedOptions.activeXType;
    var forceEmbedTag = (Plugin.PLUGINS[plugin] && Plugin.PLUGINS[plugin].forceEmbedTag == true) ? true : false;

    var embedOptions = Object.extend(((Plugin.PLUGINS[plugin] && Plugin.PLUGINS[plugin].standardEmbedAttributes) || {}), embedOptions);
    switch (plugin) {
      case "QuickTime":
        if (!options.activeXType) {
          activeXType = null;
        }
		break;

      case "DivX":
        // get space for controlls
        if ((height+"").indexOf("%") == -1) {
          if (embedOptions.mode == "mini") height += 20;
          else if (embedOptions.mode == "large") height += 65;
          else if (embedOptions.mode == "full") height += 90;
        }
        break;

      case "Windows Media":
        break;

      case "Flash":
        // flash wants the src to be named "movie" if passed as object param
        /*if (!supportsNavigatorPlugins()) {
          embedOptions.movie = src;
          src = null;
        }*/
        break;

      case "VLC":
        // VLC wants the src to be named "target"
        if (supportsNavigatorPlugins()) {
          embedOptions.target = src;
          src = null;
        }
        break;

      case "RealPlayer":
        break;        

      default: 
        // do nothing
        break;
   }

   
    // prepare html code
    var html = "";
 
 //alert("plugin detected:"+ pluginDetected);
 // alert("width:"+width);
 //alert("captions:"+captions);
 // alert("src:"+src);
 // alert("height:"+height);
   
   //embed tag for Flash
   if (pluginDetected == 'Flash')
    {
	
	//target.innerHTML="";
	document.getElementById('NASATV').innerHTML="<div id='jw_player'><p>You\'re missing some plugins needed to view the videos, Please enable <a href='http://www.nasa.gov/home/How_to_enable_Javascript.html'>Javascript</a> or install Flash Player <a href='http://www.adobe.com/products/flashplayer/'>Plug-in</a></p></div>";
    
	
	    var params =
      {
        allowfullscreen:      'true',
        allowscriptaccess:    'always'
      }
	  
	   var attributes =
      {
        id:                   'flash_player',
        name:                 'flash_player'
      }
	  
	if (captions != undefined && captions != null && captions != '' && captions !=eval(''))
	{
		 
		/*var so =new SWFObject('http://staging.cms.nasa.gov/templateimages/redesign/flash_player/swf/4.3/player.swf', 'flashplayer', width, height, '9');
      so.addParam('allowfullscreen', 'true');
      so.addParam('allowscriptaccess', 'always');
      so.addParam('flashvars', 'file='+src+'&captions='+captions+'&plugins=accessibility-1&autostart=true&lightcolor=99CCFF&backcolor=000000&frontcolor=FFFFFF&screencolor=000000&menu=false');
      so.write('NASATV');*/
	  
	  var flashvars =
      {
        file:src,
        captions:captions, 		
        lightcolor:"99CCFF",
        backcolor:"000000",
        frontcolor:"FFFFFF",
        screencolor:"000000",
        quality:"true",
		autostart:"true",
		menu:"false",
        plugins:"accessibility-1"
      }
	  
	   
	  swfobject.embedSWF("/templateimages/redesign/flash_player/swf/4.3/player.swf", "jw_player", width, height, "9.0.115", false, flashvars, params, attributes);
	  
	 }
	  else
     {
		  
	  var flashvars =
      {
        file:src,
        lightcolor:"99CCFF",
        backcolor:"000000",
        frontcolor:"FFFFFF",
        screencolor:"000000",
        quality:"true",
		menu:"false",
		autostart:"true"
       }
	
	  swfobject.embedSWF("/templateimages/redesign/flash_player/swf/4.3/player.swf", "jw_player", width, height, "9.0.115", false, flashvars, params, attributes);
		
	      }

    }								  
    //embed tag for real player 
	
    else  if(pluginDetected == 'RealPlayer' && custom == false)
	{
	
	//alert("in real player");
	height=height-20;
	heightControls=25;
	
	html+='<object id="nolplayer1" name="nolplayer1" classid="CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA" width="'+width+'" height="'+height+'" border="0">';
	html+='<param name="autostart" value="true"><param name="src" value="'+src+'"><param name="center" value="true"><param name="controls" value="ImageWindow"><param name="console" value="av"><embed name="nolplayer" id="nolplayer" border="0" center="true" src="'+src+'" width="'+width+'" height="'+height+'" autostart="true" controls="ImageWindow" console="av" type="audio/x-pn-realaudio-plugin"></embed></object>';
    html+='<object id="nolplayer3" name="nolplayer3" classid="CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA" width="'+width+'" height="'+heightControls+'" border="0"><param name="center" value="true"><param name="autostart" value="true"><param name="src" value="'+src+'"><param name="controls" value="ControlPanel"><param name="console" value="av"><embed name="nolplayer3" id="nolplayer3" src="'+src+'" width="'+width+'" height="'+heightControls+'"  center="true" controls="ControlPanel" console="av" type="audio/x-pn-realaudio-plugin"></embed></object>';
	
	}
	else
   	{ 
	//alert("in movie or asx");
	
		html += '<object classid="clsid:'+(Plugin.PLUGINS[plugin] && Plugin.PLUGINS[plugin].classID)+'"';
		html += getAttributeHtml("id", id)  + getAttributeHtml("width", width) + getAttributeHtml("height", height) + getAttributeHtml("codebase", (Plugin.PLUGINS[plugin] && Plugin.PLUGINS[plugin].codeBase)) + getAttributeHtml("type", activeXType) + '>';
		html += (src) ? '<param name="src" value="'+src+'" />' : '';
		html += (src) ? '<param name="scale" value="1" />' : '';
		if(mac)
		{
			html += (src) ? '<param name="ShowCaptioning" value="true"/>' : '';
		}
		html += (src) ? '<param name="CaptioningID" value="CapText"/>' : '';
	    html += (src) ? '<param name="DisplaySize" value="0" />' : '';
		html += (src) ? '<param name="fullScreen" value="true" />' : '';
		html += (src) ? '<param name="bgcolor" value="#000000" />' : '';
		html += (src) ? '<param name="filename" value="'+src+'" />' : '';
		
		for(var i in embedOptions)
		{
			embedOptions.controls="All";
			embedOptions.showcontrols="1";
			embedOptions.controller="true";
			html += '<param name="'+i+'" value="'+embedOptions[i]+'" />';
		}
		html += '<embed' + getAttributeHtml("src", src)  + getAttributeHtml("name", name) + getAttributeHtml("width", width) + getAttributeHtml("height", height) + getAttributeHtml("pluginspage", Plugin.PLUGINS[plugin] && Plugin.PLUGINS[plugin].pluginsPage) + getAttributeHtml("type", type);
      
		for(var i in embedOptions)
		{
			//alert('in embed options '+i);
		    embedOptions.controls="All";
			embedOptions.showcontrols="1";			  
			embedOptions.controller="true";
			if(mac){ //alert(' inside mac ');
				embedOptions.ShowCaptioning="true";
			}
			html += ' '+i+'="'+embedOptions[i]+'"';
		 // alert('interim html '+html);
		}

		html += '></embed>';
		html += '</object>'; 
		if(pluginDetected == 'WindowsMedia' && !mac){
			html+="<div id='CapText' class='captioning'></div>";
		}
		//alert('html '+html);
		//document.channelform.temp.value=html;
	}
	
	

    if(document.getElementById('NASATV'))
	{
	  	if(typeof target == "string")
		{
			target = document.getElementById(target);
	    }
		if (pluginDetected != 'Flash')
		{
		document.getElementById('NASATV').innerHTML = html+"<div id='jw_player'></div>";
		}
    }
	else
	{
		document.write(html);
	}
  }

  
  var getAttributeHtml = function(name, value) {
    return (value) ? (" " + name + "=\"" + value + "\"") : "";
  }

  //Info about known plugins
  this.PLUGINS = {
    "Acrobat": {
      description: "Adobe Acrobat Plugin",
      progID: ["PDF.PdfCtrl.7", "PDF.PdfCtrl.6", "PDF.PdfCtrl.5", "PDF.PdfCtrl.4", "PDF.PdfCtrl.3", "AcroPDF.PDF.1"],
      classID: "CA8A9780-280D-11CF-A24D-444553540000",
      pluginsPage: "http://www.adobe.com/products/acrobat/readstep2.html",
      acceptedMimeTypes: [
        { type: "application/pdf", suffixes: "pdf" },
        { type: "application/vnd.fdf", suffixes: "fdf" },
        { type: "application/vnd.adobe.xfdf", suffixes: "xfdf" },
        { type: "application/vnd.adobe.xdp+xml", suffixes: "xdp" },
        { type: "application/vnd.adobe.xfd+xml", suffixes: "xfd" }
      ]
    },
    "QuickTime": {
      description: "QuickTime Plug-in",
      progID: ["QuickTimeCheckObject.QuickTimeCheck.1", "QuickTime.QuickTime"],
      classID: "02BF25D5-8C17-4B23-BC80-D3488ABDDC6B",
      pluginsPage: "http://www.apple.com/quicktime/download/",
      codeBase: "http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0",
      mimeType: "video/quicktime",
      standardEmbedAttributes: {
        
		autoplay: "true" ,EnableJavaScript:"true", scale:"1", controller:"false"
      },
      // embedInfo: http://www.apple.com/quicktime/tutorials/embed.html 
      //            http://developer.apple.com/quicktime/compatibility.html
      getActiveXVersionInfo: function() { 
        var progID = getProgIdForActiveXObject(Plugin.PLUGINS["QuickTime"].progID); 
        var obj = new ActiveXObject(progID);
        var version = (obj && obj.QuickTimeVersion) ? obj.QuickTimeVersion.toString(16) : "";
        return version.substring(0,1) + '.' + version.substring(1,2) + '.' + version.substring(2,3);
      },
      acceptedMimeTypes: [
        { type: "image/tiff", suffixes: "tif,tiff" },
        { type: "image/x-tiff", suffixes: "tif,tiff" },
        { type: "video/x-m4v", suffixes: "m4v" },
        { type: "image/x-macpaint", suffixes: "pntg,pnt,mac" },
        { type: "image/pict", suffixes: "pict,pic,pct" },
        { type: "image/x-pict", suffixes: "pict,pic,pct" },
        { type: "image/x-quicktime", suffixes: "qtif,qti" },
        { type: "image/x-sgi", suffixes: "sgi,rgb" },
        { type: "image/x-targa", suffixes: "targa,tga" },
        { type: "audio/3gpp", suffixes: "3gp,3gpp" },
        { type: "video/3gpp2", suffixes: "3g2,3gp2" },
        { type: "audio/3gpp2", suffixes: "3g2,3gp2" },
        { type: "video/sd-video", suffixes: "sdv" },
        { type: "application/x-mpeg", suffixes: "amc" },
        { type: "video/mp4", suffixes: "mp4" },
        { type: "audio/mp4", suffixes: "mp4" },
        { type: "audio/x-m4a", suffixes: "m4a" },
        { type: "audio/x-m4p", suffixes: "m4p" },
        { type: "audio/x-m4b", suffixes: "m4b" },
        { type: "video/mpeg", suffixes: "mpeg,mpg,m1s,m1v,m1a,m75,m15,mp2,mpm,mpv,mpa" },
        { type: "audio/mpeg", suffixes: "mpeg,mpg,m1s,m1a,mp2,mpm,mpa,m2a" },
        { type: "audio/x-mpeg", suffixes: "mpeg,mpg,m1s,m1a,mp2,mpm,mpa,m2a" },
        { type: "video/3gpp", suffixes: "3gp,3gpp" },
        { type: "audio/x-gsm", suffixes: "gsm" },
        { type: "audio/AMR", suffixes: "AMR" },
        { type: "audio/aac", suffixes: "aac,adts" },
        { type: "audio/x-aac", suffixes: "aac,adts" },
        { type: "audio/x-caf", suffixes: "caf" },
        { type: "video/x-mpeg", suffixes: "mpeg,mpg,m1s,m1v,m1a,m75,m15,mp2,mpm,mpv,mpa" },
        { type: "audio/aiff", suffixes: "aiff,aif,aifc,cdda" },
        { type: "audio/x-aiff", suffixes: "aiff,aif,aifc,cdda" },
        { type: "audio/basic", suffixes: "au,snd,ulw" },
        { type: "audio/mid", suffixes: "mid,midi,smf,kar" },
        { type: "audio/x-midi", suffixes: "mid,midi,smf,kar" },
        { type: "audio/midi", suffixes: "mid,midi,smf,kar" },
        { type: "audio/vnd.qcelp", suffixes: "qcp" },
        { type: "application/sdp", suffixes: "sdp" },
        { type: "application/x-sdp", suffixes: "sdp" },
        { type: "application/x-rtsp", suffixes: "rtsp,rts" },
        { type: "video/quicktime", suffixes: "mov,qt,mqv" },
        { type: "video/flc", suffixes: "flc,fli,cel" },
        { type: "audio/x-wav", suffixes: "wav,bwf" },
        { type: "audio/wav", suffixes: "wav,bwf" }
      ]
    },
    "DivX": {
      description: "DivX Browser Plugin",
      progID: ["npdivx.DivXBrowserPlugin.1", "npdivx.DivXBrowserPlugin"],
      classID: "67DABFBF-D0AB-41fa-9C46-CC0F21721616",
      codeBase: "http://go.divx.com/plugin/DivXBrowserPlugin.cab",
      pluginsPage: "http://go.divx.com/plugin/download/",
      mimeType: "video/divx",
      standardEmbedAttributes: {
        mode: "mini",
        autoplay: "false"
      },
      // embedInfo: Beta1: http://labs.divx.com/archives/000072.html
      //            SDK&Doc: http://download.divx.com/labs/Webmaster_SDK.zip
      getActiveXVersionInfo2: function() {
        var progID = getProgIdForActiveXObject(Plugin.PLUGINS["DivX"].progID); 
        return "0.9.0"; // that's the only currently available
      },
      acceptedMimeTypes: [
        { type: "video/divx", suffixes: "dvx,divx" }
      ]
    },
    "Director": {
      description: "Macromedia Director",
      progID: ["SWCtl.SWCtl.11","SWCtl.SWCtl.10","SWCtl.SWCtl.9","SWCtl.SWCtl.8","SWCtl.SWCtl.7","SWCtl.SWCtl.6","SWCtl.SWCtl.5","SWCtl.SWCtl.4"],
      classID: "166B1BCA-3F9C-11CF-8075-444553540000",
      pluginsPage: "http://www.macromedia.com/shockwave/download/",
      codeBase: "http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0",
      mimeType: "application/x-director"
    },         
    "Flash": {
      description: "Macromedia Shockwave Flash",
      progID: ["ShockwaveFlash.ShockwaveFlash.9", "ShockwaveFlash.ShockwaveFlash.8.5", "ShockwaveFlash.ShockwaveFlash.8", "ShockwaveFlash.ShockwaveFlash.7", "ShockwaveFlash.ShockwaveFlash.6", "ShockwaveFlash.ShockwaveFlash.5", "ShockwaveFlash.ShockwaveFlash.4"],
      classID: "D27CDB6E-AE6D-11CF-96B8-444553540000",
      pluginsPage: "http://www.macromedia.com/go/getflashplayer",
      codeBase: "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0",
      mimeType: "application/x-shockwave-flash",
      standardEmbedAttributes: {
        quality: "high"
      },
      // embedInfo: http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_4150
      //            http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_12701
      acceptedMimeTypes: [
        { type: "application/x-shockwave-flash", suffixes: "swf" },
        { type: "application/futuresplash", suffixes: "spl" }
      ]
    }, 
    "VLC": {
      description: "VLC multimedia plugin",
      progID: [],
      classID: "",
      pluginsPage: "http://www.videolan.org/doc/play-howto/en/ch02.html#id287569",
      codeBase: "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0",
      mimeType: "application/x-vlc-plugin",
      standardEmbedAttributes: {
        quality: "high",
        autoplay: "no"
      },
      // embedInfo: http://www.videolan.org/doc/vlc-user-guide/en/ch07.html
      acceptedMimeTypes: [
        { type: "audio/mpeg", suffixes: "mp2,mp3,mpga,mpega" },
        { type: "audio/x-mpeg", suffixes: "mp2,mp3,mpga,mpega" },
        { type: "video/mpeg", suffixes: "mpg,mpeg,mpe" },
        { type: "video/x-mpeg", suffixes: "mpg,mpeg,mpe" },
        { type: "video/mpeg-system", suffixes: "mpg,mpeg,vob" },
        { type: "video/x-mpeg-system", suffixes: "mpg,mpeg,vob" },
        { type: "video/mpeg4", suffixes: "mp4,mpg4" },
        { type: "audio/mpeg4", suffixes: "mp4,mpg4" },
        { type: "application/mpeg4-iod", suffixes: "mp4,mpg4" },
        { type: "application/mpeg4-muxcodetable", suffixes: "mp4,mpg4" },
        { type: "video/x-msvideo", suffixes: "avi" },
        { type: "video/quicktime", suffixes: "mov,qt" },
        { type: "application/x-ogg", suffixes: "ogg" },
        { type: "application/x-vlc-plugin", suffixes: "*" },
        { type: "video/x-ms-asf-plugin", suffixes: "asf,asx,*" },
        { type: "video/x-ms-asf", suffixes: "asf,asx,*" },
        { type: "application/x-mplayer2", suffixes: "dvx,divx,ivx,xvid,ivf,*" },
        { type: "video/x-ms-wmv", suffixes: "wmv,*" },
        { type: "application/x-google-vlc-plugin", suffixes: "*" }      
      ]
    },
    "Windows Media": {
      description: "Windows Media Player Plug-in Dynamic Link Library",
      progID: ["WMPlayer.OCX", "MediaPlayer.MediaPlayer.1"],
      classID: "22D6F312-B0F6-11D0-94AB-0080C74C7E95", // WMP7+
      pluginsPage: "http://www.microsoft.com/windows/windowsmedia/",
      //codeBase: "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902",
      mimeType: "application/x-mplayer2",
      activeXType: "application/x-oleobject",
      standardEmbedAttributes: {
        ShowCaptioning:"false" ,CaptioningID:"CapText" ,autoplay: "true",  showcontrols: "0" , fullScreen: "true" , DisplaySize: "0"
      },
      // embedInfo: http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples/internet/imedia/netshow/crossbrowserembed/default.asp
      getActiveXVersionInfo: function() { 
        var progID = getProgIdForActiveXObject(Plugin.PLUGINS["Windows Media"].progID); 
        var obj = new ActiveXObject(progID);
        return (obj && obj.versionInfo) ? obj.versionInfo : "";
      },
      acceptedMimeTypes: [
        { type: "application/asx", suffixes: "*" },
        { type: "video/x-ms-asf-plugin", suffixes: "*" },
        { type: "application/x-mplayer2", suffixes: "dvx,divx,ivx,xvid,ivf,*" },
        { type: "video/x-ms-asf", suffixes: "asf,asx,*" },
        { type: "video/x-ms-wm", suffixes: "wm,*" },
        { type: "audio/x-ms-wma", suffixes: "wma,*" },
        { type: "audio/x-ms-wax", suffixes: "wax,*" },
        { type: "video/x-ms-wmv", suffixes: "wmv,*" },
        { type: "video/x-ms-wvx", suffixes: "wvx,*" }
      ]
    },
    "Java": {
      description: "Java Virtual Machine",
      progID: [],
      classID: "08B0E5C0-4FCB-11CF-AAA5-00401C608500",
      pluginsPage: "http://www.java.com/de/download/manual.jsp",
      acceptedMimeTypes: [
        { type: "application/x-java-applet", suffixes: "" },
        { type: "application/x-java-bean", suffixes: "" },
        { type: "application/x-java-vm", suffixes: " " }
      ]
    },          
    "RealPlayer": {
      description: "RealPlayer Version Plugin",
      progID: ["RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)", "RealVideo.RealVideo(tm) ActiveX Control (32-bit)", "rmocx.RealPlayer G2 Control"],
      classID: "CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA",
      mimeType: "audio/x-pn-realaudio-plugin",
      pluginsPage: "http://www.real.com/freeplayer/?rppr=rnwk",
      forceEmbedTag: true,
      standardEmbedAttributes: {        controls: "ImageWindow",
        nojava: "true",
        autostart: "true" , center: "true"
      },
      // embedInfo: http://service.real.com/help/library/guides/realone/ProductionGuide/HTML/realpgd.htm?page=htmfiles/embed.htm
      // couldn't find any info about the object tag!
      getActiveXVersionInfo: function() { 
        var progID = getProgIdForActiveXObject(Plugin.PLUGINS["RealPlayer"].progID); 
        var obj = new ActiveXObject(progID);
       // var version = (obj) ? obj.GetVersionInfo() : "";
	   var version="";
        return version;
      },
      acceptedMimeTypes: [
        { type: "audio/x-pn-realaudio-plugin", suffixes: "rpm" },
        { type: "application/vnd.rn-realplayer-javascript", suffixes: "rpj" }
      ]
    }
  }

  var supportsNavigatorPlugins = function(){
    return (navigator.plugins && (navigator.plugins.length > 0));
    //return true;
  }

  var supportsActiveX = function(){
    return ((typeof 'ActiveXObject' != 'undefined') && (navigator.userAgent.indexOf('Win') != -1));
  }

  var findNavigatorPluginByName = function(name){
    if (supportsNavigatorPlugins()) {
      for(var i=0;i<navigator.plugins.length;++i){
        var plugin = navigator.plugins[i];
        if (plugin.name.indexOf(name) != -1){
          return plugin;
        }
      }
    }
    return null;
  }

  var findPluginName = function(str){
    for (var pluginName in Plugin.PLUGINS){
      if (str.indexOf(pluginName) != -1){
        return pluginName;
      }
    }
    return null;
  }

  var getIEClientCaps = function(){
    var clientcaps = document.getElementById("__Plugin_ClientCaps");
    if(!clientcaps){
      var clientcaps = document.createElement("DIV");
      clientcaps.id = "__Plugin_ClientCaps";
      if(clientcaps.addBehavior){
        clientcaps.addBehavior("#default#clientCaps");
        document.body.appendChild(clientcaps);
      }
      clientcaps = document.getElementById("__Plugin_ClientCaps");
    }
    return clientcaps;    
  }

  var getActiveXPluginByClassId = function(classID){
    if (!classID) return;
    if (!classID.match(/{[^}]+}/)) classID = "{" + classID + "}";
    var clientcaps = getIEClientCaps();
    try {
      return clientcaps.getComponentVersion(classID, "ComponentID");  	
    } catch (err) { }
    return;
  }

  var hasActiveXObject = function(progID){
    var progID = getProgIdForActiveXObject(progID);
    return (progID != null);
  }

  var getProgIdForActiveXObject = function(progID) {
    if (!progID) return;
    for (var i=0; i<progID.length; i++) {
      try {
        var obj = new ActiveXObject(progID[i]);
        return progID[i];
      }
      catch(e) { }
    }
    return null;
  }

  // accepts plugin or string
  var getVersionFromPlugin = function(plugin) {
    if (!plugin.name) plugin = { name: plugin, description: name };
    var matches = /[\d][\d\.]*/.exec(plugin.name);
    if (matches && plugin.name.indexOf("Java") == -1) return matches[0];
    matches = /[\d\.]+/.exec(plugin.description);
    return matches ? matches[0] : "";
  }
  
};

if (!window.Plugin) {
  var Plugin = new Object();
}

// helper functions
// for usage without prototype.js
if (!Object.extend) {
  Object.extend = function(destination, source) {
    for (property in source) {
      destination[property] = source[property];
    }
    return destination;
  }
}

// Array functions
Array.contains = function(arr, el) {
  return Array.indexOf(arr, el) != -1;
}

Array.indexOf = function(arr, el) {
  for (var i=0; i<arr.length; i++) {
    if (arr[i] == el) return i;
  }
  return -1;
}

Object.extend(Plugin, (new PluginFactory()));

String.encode =
String.prototype.encode = function() {
  var str = this;
  str = str.replace("&", "&amp;");
  str = str.replace("<", "&lt;");
  str = str.replace(">", "&gt;");
  str = str.replace("\"", "&quot;");
  str = str.replace("\n", "");
  return str;
}




var wmv;
var ram;
var mov;
var wmvCcStatus;
var ramCcStatus;
var movCcStatus;
var numChannel;

function GetSelectedChannel()
{
	wmvCcStatus = false;
	ramCcStatus = false;
	movCcStatus = false;
	this.widthPlayer = 320;
	this.heightPlayer = 235;
		
    numChannel = document.channelform.channel.length
    i = 0
    chosen = "none";
	for(i = 0; i < numChannel; i++){
		if(document.channelform.channel[i].selected){
			chosen = document.channelform.channel[i].value
		}
	}
	format = chosen.split('|');
	wmv = format[0];
	ram = format[1];
	mov = format[2];
	 
	var numElements = document.channelform.numElements.value;

	for(var x = 1; x <= numElements; x++){  
		var channelname = document.getElementById('channelname'+x); 
		var channeldesc = document.getElementById('channeldesc'+x); 
		var channelPromo = document.getElementById('channelpromo'+x); 
		if(channelname != null && channelname != '' && channeldesc != null && channeldesc != '' && channelPromo != null && channelPromo != ''){
			if(eval(x) == eval(format[6])){  
				channelname.style.display='inline';
			    channelname.style.visibility='visible';
				channeldesc.style.display='inline';
			    channeldesc.style.visibility='visible';
				channelPromo.style.display='inline';
			    channelPromo.style.visibility='visible';
			}else{  
				 channelname.style.display='none';
			     channelname.style.visibility='hidden';
				 channeldesc.style.display='none';
			     channeldesc.style.visibility='hidden';
				 channelPromo.style.display='none';
			     channelPromo.style.visibility='hidden';
			}
		}
                 
	}
	startVideo('NASATV', this.widthPlayer, this.heightPlayer, wmv, ram, mov);
}



// Main Method For the On Demand  Video Logic on NASA Portal
function GetSelectedChannelDemandVideo(media,title)
{
	
	var captions='';
	document.channelform.selectedVideo.value = media;
	var pos = media.lastIndexOf('|');
	if (media.substring(pos + 1).indexOf(".xml") > -1)
	{
	captions=media.substring(pos + 1);
	media=media.substring(0,pos);
	}
    //alert("captions parameter:"+ captions);			
	//alert("media parameter:"+ media);
	
	
	if(title != null && title != 'undefined' && title != eval(''))
	{
		var titlediv = document.getElementById('titlediv');
		if(titlediv != null && titlediv != 'undefined')
		{
			titlediv.className='videotitle';
			var temp1 = '<h3>Now Playing: ';
			temp1 = temp1 + title;
			temp1 = temp1 + '</h3><p><img src="/templateimages/redesign/modules/main_video/playlist.jpg"/><a href="javascript:addToPlayListTop()" class="bookmarkbutton1">Add to My Playlist</a></p>';
			titlediv.innerHTML = temp1;
		}
	}
	
	
	
	
	//Identify the Operating System.
	detectBrowserAndOS();
	//alert('AFTER ::WINDOWS: '+win+' ::LINUX: '+lin+' ::MAC: '+mac);

	
	
	var sQuery = null;
	//alert('sQueryy after nullifying '+sQuery);
	sQuery = document.location.search;
	//alert('squery '+sQuery);
    sQuery = sQuery.replace(/.*param=([0-9]+).*/i,'$1');
	//alert('squery1 '+sQuery);
	var pos = sQuery.indexOf('=');
	var val = sQuery.substring(pos + 1);
	//alert('val '+val);
	//alert('media '+media);
	
    
	
	
	
	//Check the plug in status -  Identify which plugins are already installed.		
	var windowsPlayerStatus = Plugin.isInstalled("Windows Media");
    var qtPlayerStatus = Plugin.isInstalled("QuickTime");
	var flashPlayerStatus= Plugin.isInstalled("Flash");
	var realPlayerStatus;
    if(Plugin.isInstalled("Real Player") || Plugin.isInstalled("RealPlayer"))
	{
		realPlayerStatus = true;
    }
	else
	{
		realPlayerStatus = false;
	}
	 
	// alert('FlashPlayerStatus::'+flashPlayerStatus+':: windowsPlayerStatus :: '+ windowsPlayerStatus+' ::qtPlayerStatus:: '+qtPlayerStatus+ ' ::realPlayerStatus:: '+realPlayerStatus+' :: 	document.channelform.continueFlag.value :: '+document.channelform.continueFlag.value);
   
	
	
	//Set the height and width of the player in the window.
	this.widthPlayer = 478;
	this.heightPlayer = 345;

	
	//div that holds the player
	var target = document.getElementById("NASATV");
        
	
	//If there is no plugin installed	   
	if(!(flashPlayerStatus && windowsPlayerStatus && qtPlayerStatus && realPlayerStatus) && document.channelform.continueFlag.value == 'F' )
	{
	
         var html ='<table height="150" width="320" valign="top" ><tr></td><h5>You\'re missing some plugins needed to view all videos in this collection.';
		
	
		if((media != 'undefined' &&  media != null && media != eval('') && media != '') || (val != 'undefined' &&  val != null && val != eval('') && val != ''))
	{
		
		if(document.channelform.selectedVideoTitle != null && document.channelform.selectedVideoTitle != 'undefined')
		{
				html+=' <br/><br/><a href="javascript:GetSelectedChannelDemandVideo(document.channelform.selectedVideo.value,document.channelform.selectedVideoTitle.value)">Click Here</a> to continue viewing the video you selected ';
		}
		else
		{
		html+=' <br/><br/><a href="javascript:GetSelectedChannelDemandVideo(document.channelform.selectedVideo.value)">Click Here</a> to continue viewing the video you selected ';
		}
			html+=' or download the plugins here : </br></h5>';
	
	}
	else
	{
			html+='<br/><br/>Please choose a video from the list at right or download the plugins here :<br/>';
	}
	
	

		if(!windowsPlayerStatus){
			html+='</br><a href="http://www.microsoft.com/windows/windowsmedia/" target="_blank">Download Windows Media Player</a>';
		}		
		if(!realPlayerStatus){
			html+='</br><a href="http://www.real.com/freeplayer/?rppr=rnwk" target="_blank">Download Real Player</a>';
		}		
		if(!qtPlayerStatus){
			html+='</br><a href="http://www.apple.com/quicktime/download/" target="_blank">Download Quick Time</a>';
		}
		
		if(!flashPlayerStatus){
			html+='</br><a href="http://get.adobe.com/flashplayer/" target="_blank">Download Adobe Flash Player</a>';
		}
		
		
		html+='</td></tr></table>';
		target.innerHTML = html;
		//Make the continueFlag 'true'.
		document.channelform.continueFlag.value = 'T';
	//If there is no plugin installed and no video selected to play and continueflagis 'true'.
	}
	
	
	else if(!(flashPlayerStatus && windowsPlayerStatus && qtPlayerStatus && realPlayerStatus) && document.channelform.continueFlag.value == 'T' && (media == 'undefined' ||  media == null || media == eval('') || media == '') && (val == 'undefined' ||  val == null || val == eval('') || val == ''))
	{
	
		
		//added to show "play most recent video" button on load of video gallery page
		if (typeof(document.getElementById('play_button').getElementsByTagName("p")[1].getElementsByTagName("a")[0]) != "undefined"){	
						
				target.innerHTML='<div style="position:relative;top:175px;left:145px;width:200px;">'+document.getElementById('play_button').getElementsByTagName("p")[1].innerHTML+'<div style="float:left;width:200px;text-align:center;font-size:11px;">or choose another video from the list</div></div>';
				document.getElementById("NASATV").getElementsByTagName("div")[0].getElementsByTagName("a")[0].innerHTML="Play  Most  Recent Video";
				document.getElementById("NASATV").getElementsByTagName("a")[0].style.position="relative";
				document.getElementById("NASATV").getElementsByTagName("a")[0].style.width="160px";
				document.getElementById("NASATV").getElementsByTagName("a")[0].style.left="18px";
				
			}
            else
            {
			 	target.innerHTML='<div style="position:relative;top:175px;left:145px;width:200px;text-align:center;font-size:11px;">Please choose a video from the list</div>';
		    }	

	
	//If there is any of the plugins installed.
    }
	else
	{
		
		//If 'media' has more than one type of file - assign this value to 'val'.
		if((media != 'undefined' && media != eval('') && media != null && media != '' && media.lastIndexOf('|') > 0)){
			val = media;
		}
		
		//If 'val' has some value and 'media' is empty OR 'media' has more than one type of file.
		if(((val != 'undefined' && val != eval('') && val != null && val != '') && (media == 'undefined' ||  media == null || media == eval('') || media == '' )) || (media != 'undefined' && media != eval('') && media != null && media != '' && media.lastIndexOf('|') > 0)) 
		{
			
		
            var videostreams = val.split('|');
			//alert('videostreamlength '+videostreams.length);
			//alert('videostreams[0] '+videostreams[0]);
			//alert('videostreams[1] '+videostreams[1]);
			//alert('videostreams[2] '+videostreams[2]);
			var windowMediaFile;
			var rpFile;
			var qtFile;
			var flvFile;
			
			
			//Checking the file type
			for(var i = 0; i < videostreams.length; i++)
			{
				var posdot = videostreams[i].lastIndexOf('.');
				var mediatype = videostreams[i].substring(posdot + 1);
				//alert('mediatype '+videostreams[i] +' ::: '+mediatype);
				
				if(mediatype == 'asf' || mediatype == 'asx' || mediatype == 'wmv' || mediatype == 'wma'){
					windowMediaFile = videostreams[i];
				}
				else if(mediatype == 'ram' || mediatype == 'rpm' || mediatype == 'rm'){
					rpFile = videostreams[i];
				}
				else if(mediatype == 'mpg' || mediatype == 'mov' || mediatype == 'qtl'){
					qtFile = videostreams[i];
				}
				else if(mediatype == "flv"){
				    flvFile= videostreams[i];
				}
			} //end of for loop

			
			//To check the appropriate combination of media file and plugins available. This code has preference order of media file types. Windows is 1 Real Media 2 and Quick time 3. Eg. If windows media file/plugin is not available code will check for next file/plugin combination and will play the video. 
			//Also if non of these combinations are true - show message to download appropriate plugin based on media file type and operating system.
			
			if(windowMediaFile && windowsPlayerStatus)
			{

				startVideo('NASATV', this.widthPlayer, this.heightPlayer, windowMediaFile, null, null, null,null);
			}else if(rpFile && realPlayerStatus)
			{

				startVideo('NASATV', this.widthPlayer, this.heightPlayer, null, rpFile, null, null,null);				
			}else if(qtFile && qtPlayerStatus)
			{
                startVideo('NASATV', this.widthPlayer, this.heightPlayer, null, null, qtFile, null,null);
			}else if (flvFile && flashPlayerStatus)
			{
			   startVideo('NASATV', this.widthPlayer, this.heightPlayer, null, null, null, flvFile,captions);
			}
			else
			{

				var html ='<table height="150" width="320" valign="top" ><tr></td><h5>You\'re missing some plugins needed to view all videos in this collection.';
				if(document.channelform.selectedVideoTitle != null && document.channelform.selectedVideoTitle != 'undefined')
				{
					html+=' <br/><br/><a href="javascript:GetSelectedChannelDemandVideo(document.channelform.selectedVideo.value,document.channelform.selectedVideoTitle.value)">Click Here</a> to continue viewing the video you selected ';
				}
				else
				{
					html+=' <br/><br/><a href="javascript:GetSelectedChannelDemandVideo(document.channelform.selectedVideo.value)">Click Here</a> to continue viewing the video you selected ';
				}
				html+=' or download the plugins here : </br></h5>';
			
     			if(!windowsPlayerStatus){
					html+='</br><a href="http://www.microsoft.com/windows/windowsmedia/" target="_blank">Download Windows Media Player</a>';
				}				
				if(!realPlayerStatus){
					html+='</br><a href="http://www.real.com/freeplayer/?rppr=rnwk" target="_blank">Download Real Player</a>';
				}				
				if(!qtPlayerStatus){
					html+='</br><a href="http://www.apple.com/quicktime/download/" target="_blank">Download Quick Time</a>';
				}
		        
                if(!flashPlayerStatus){
			html+='</br><a href="http://get.adobe.com/flashplayer/" target="_blank">Download Adobe Flash Player</a>';
		        }				
				
				html+='</td></tr></table>';
				target.innerHTML = html;
				//Make the continueFlag 'true'.
				document.channelform.continueFlag.value = 'F';
			}
		//If 'val' is empty OR 'media' is empty OR has only one type of file specified.
		}else{

			if (media == 'undefined' ||  media == null || media == eval('')){
                  
				//added to show "play most recent video" button on load of video gallery page  
				if (typeof(document.getElementById('play_button').getElementsByTagName("p")[1].getElementsByTagName("a")[0]) != "undefined"){	
				
				target.innerHTML='<div style="position:relative;top:175px;left:145px;width:200px;">'+document.getElementById('play_button').getElementsByTagName("p")[1].innerHTML+'<div style="float:left;width:200px;text-align:center;font-size:11px;">or choose another video from the list</div></div>';
				document.getElementById("NASATV").getElementsByTagName("div")[0].getElementsByTagName("a")[0].innerHTML="Play  Most  Recent Video";
				document.getElementById("NASATV").getElementsByTagName("a")[0].style.position="relative";
				document.getElementById("NASATV").getElementsByTagName("a")[0].style.width="160px";
				document.getElementById("NASATV").getElementsByTagName("a")[0].style.left="18px";
				
			}
            else
            {
			 	target.innerHTML='<div style="position:relative;top:175px;left:145px;width:200px;text-align:center;font-size:11px;">Please choose a video from the list</div>';
				
		    }	

     		}else{

				var posdot = media.lastIndexOf('.');
				var mediatype = media.substring(posdot + 1);
				var var1;
				var var2;
				var var3;
				var var4;
				
	          //alert("mediatype:"+mediatype);			
				if(mediatype == 'flv')
				{

					 if(!flashPlayerStatus)
					 {

						var html ='<table height="150" width="320"><tr></td><h5>Sorry, you don\'t have the Adobe Flash Player plugin needed to view this video. Please download it here : </h5>';
						html+='</br><a href="http://get.adobe.com/flashplayer/" target="_blank">Download Adobe Flash Player</a>';
						html+='</td></tr></table>';
						target.innerHTML = html;
					}
					else
					{
						var4 = media;
					}
				}else if(mediatype == 'asf' || mediatype == 'asx' || mediatype == 'wmv' || mediatype == 'wma'){

					 if(!windowsPlayerStatus){

						var html ='<table height="150" width="320"><tr></td><h5>Sorry, you don\'t have the Windows Media plugin needed to view this video. Please download it here : </h5>';
						html+='</br><a href="http://www.microsoft.com/windows/windowsmedia/" target="_blank">Download Windows Media Player</a>';
						html+='</td></tr></table>';
						target.innerHTML = html;
					}else{
						var1 = media;
					}
				}else if(mediatype == 'ram' || mediatype == 'rpm' || mediatype == 'rm'){

					if(!realPlayerStatus){

						var html ='<table height="150" width="320"><tr></td><h5>Sorry, you don\'t have the Real Player plugin needed to view this video. Please download it here : </h5>';
						html+='</br><a href="http://www.real.com/freeplayer/?rppr=rnwk" target="_blank">Download Real Player plugin</a>';
						html+='</td></tr></table>';
						target.innerHTML = html;
					}else{
						var2 =	media;
					}
				}else if(mediatype == 'mpg' || mediatype == 'mov' || mediatype == 'qtl'){

					if(!qtPlayerStatus){

						var html ='<table height="150" width="320"><tr></td><h5>Sorry, you don\'t have the Quick Time  plugin needed to view this video. Please download it here : </h5>';
						html+='</br><a href="http://www.apple.com/quicktime/download/" target="_blank">Download Quick Time Plugin</a>';
						html+='</td></tr></table>';
						target.innerHTML = html;
					}else{
						var3 =	media;
					}
				}
				
				if(var1 != null || var2 != null || var3 != null || var4 != null){

					startVideo('NASATV', this.widthPlayer, this.heightPlayer, var1, var2, var3, var4,captions);
				}
			}
		}
	}
}




function GetSelectedChannelDemand(videourl,title,imageName,assetid)
{
    if(document.channelform.selectedVideo != null && document.channelform.selectedVideo != 'undefined')
	{
		document.channelform.selectedVideo.value = videourl;
	}

	if(document.channelform.selectedVideoTitle != null && document.channelform.selectedVideoTitle != 'undefined')
	{
		document.channelform.selectedVideoTitle.value=title;
	}

	if(document.channelform.selectedVideoAssetId != null && document.channelform.selectedVideoAssetId != 'undefined')
	{
		document.channelform.selectedVideoAssetId.value=assetid;
	}

	if(document.channelform.selectedVideoImage != null && document.channelform.selectedVideoImage != 'undefined')
	{
		document.channelform.selectedVideoImage.value=imageName;
	}
    GetSelectedChannelDemandVideo(videourl,title);
}


function getSelectedVideoChannel()
{
    var selectedVideoTitle;
	var selectedVideoAssetId;
	var selectedVideoImage;
	var selectedVideo;
	

	// get the current URL
	var url = window.location.toString();
	//get the parameters
	url.match(/\?(.+)$/);
	var params = RegExp.$1;
	// split up the query string and store in an
	// associative array
	var params = params.split("&");
	var queryStringList = {};
	
	
	var tmp = params[0].split("=");
	selectedVideo = unescape(tmp[1]);

	
    
	for(var i=0;i<params.length;i++)
	{
		var tmp = params[i].split("=");
		
		//queryStringList[tmp[0]] = unescape(tmp[1]);
		
		if(tmp[0] != null && tmp[0] != 'undefined' && tmp[0] != eval('') ) 
		{
			if(tmp[0] == "_title")
			{
				selectedVideoTitle = unescape(tmp[1]);
			}
			else if(tmp[0] == "_id")
			{
				selectedVideoAssetId = unescape(tmp[1]);
			}
			else if(tmp[0] == "_tnimage")
			{
				selectedVideoImage = unescape(tmp[1]);
			}
		}
		
	}
	
	/*for(var i in queryStringList)
	{
		alert(queryStringList[i]);
	}*/
		
    if(selectedVideo != null || selectedVideo != eval('') || selectedVideo != 'undefined')
	{
		document.channelform.selectedVideo.value = selectedVideo;
		document.channelform.continueFlag.value = 'T';
	}

	if(document.channelform.selectedVideoTitle != null && document.channelform.selectedVideoTitle != 'undefined')
	{
		document.channelform.selectedVideoTitle.value=selectedVideoTitle;
	}

	if(document.channelform.selectedVideoAssetId != null && document.channelform.selectedVideoAssetId != 'undefined')
	{
		document.channelform.selectedVideoAssetId.value=selectedVideoAssetId;
	}

	if(document.channelform.selectedVideoImage != null && document.channelform.selectedVideoImage != 'undefined')
	{
		document.channelform.selectedVideoImage.value=selectedVideoImage;
	}
	
    GetSelectedChannelDemandVideo(selectedVideo,selectedVideoTitle);
}




function addToPlayListTop()
{
	var captionurl='';
	var videourl=document.channelform.selectedVideo.value;
	var pos = videourl.lastIndexOf('|');
	if (videourl.substring(pos + 1).indexOf(".xml") > -1)
	{
	captionurl=videourl.substring(pos + 1);
	videourl=videourl.substring(0,pos);
	}
	//alert("caption_url:"+captionurl);
	//alert("videourl:"+videourl);
	
	var myname = 'MyNASA';
	var w = 800;
    var h = 600;
	
	var param= '?playlist_title=' + document.channelform.selectedVideoTitle.value;
	param = param + '&playlist_url=' + videourl;
	param = param + '&playlist_label=' + document.channelform.selectedVideoAssetId.value;
	param = param + '&image_url=' + document.channelform.selectedVideoImage.value;
	param = param + '&caption_url=' + captionurl;
	
	
	var mypage = 'http://mynasa.nasa.gov/portal/playlists/PlaylistServlet' + param;
	//alert("in addToPlayListTop()");
	//alert(mypage);
	var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    var winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable=yes';
	win = window.open(mypage, myname, winprops);

}


function addToPlayList(videourl,title,imageurl,assetid)
{
    var captionurl='';
	var pos = videourl.lastIndexOf('|');
	if (videourl.substring(pos + 1).indexOf(".xml") > -1)
	{
	captionurl=videourl.substring(pos + 1);
	videourl=videourl.substring(0,pos);
	}
	//alert("caption_url:"+captionurl);
	//alert("videourl:"+videourl);
	
	var myname = 'MyNASA';
	var w = 800;
    var h = 600;
	var param= '?playlist_title=' + title;
	param = param + '&playlist_url=' + videourl;
	param = param + '&playlist_label=' + assetid;
	param = param + '&image_url=' + imageurl;
	param = param + '&caption_url=' + captionurl;

	var mypage = 'http://mynasa.nasa.gov/portal/playlists/PlaylistServlet' + param;
	//alert("in addToPlayList()");
	//alert(mypage);
	var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    var winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable=yes';
	win = window.open(mypage, myname, winprops);
}





