//function to detect installed version of flash plug-in 
function DetectFlashV() {
  var cookiedomain='.glaucoma.org';
  var flashv = 0;
  // check if we have already detected flash version
  var pos = document.cookie.indexOf('flashv=');
  if (pos != -1) {
    pos+=7;
    flashv = parseInt(document.cookie.substr(pos,1));
  } 
  else {
    // check for netscape plugins. navigator.plugins exists but is empty in IE
    if (navigator.plugins && (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"])) {
      var words = navigator.plugins["Shockwave Flash"].description.split(" ");
      flashv = parseInt(words[2]);
    } 
    else if ((navigator.appVersion.indexOf("MSIE") != -1) && (navigator.appVersion.indexOf("Windows") != -1)) {
      document.writeln('<SCR'+'IPT LANGUAGE=VBScript\>');
      document.writeln('Private i, x');
      document.writeln('On Error Resume Next');
      document.writeln('MM_FlashControlInstalled = False');
      document.writeln('For i = 7 To 1 Step -1');
      document.writeln('Set x = CreateObject("ShockwaveFlash.ShockwaveFlash." & i)');
      document.writeln('MM_FlashControlInstalled = IsObject(x)');
      document.writeln('If MM_FlashControlInstalled Then');
      document.writeln('MM_FlashControlVersion = CStr(i)');
      document.writeln('Exit For');
      document.writeln('End If');
      document.writeln('Next');
      document.writeln('</SCR'+'IPT\>');
     flashv = parseInt(MM_FlashControlVersion);
    } 
  }
  // set flash version into cookie
  if (flashv >= 2) { 
    document.cookie='flashv='+flashv+';path=/;domain='+cookiedomain; 
  }
  else { 
    flashv = 0;
    document.cookie='flashv='+flashv+';path=/;domain='+cookiedomain; 
  }
  return (flashv);
}
var flash_version = DetectFlashV();
// called by flash movie to resize containing div 
function newSize(datoX,datoY,theId) {
  if ((theId == null) || (theId == undefined)) {
    theId = 'vidctrl';
  }
  if (document.all && !document.getElementById) {
    document.all[theId].style.pixelWidth = datoX;
    document.all[theId].style.pixelHeight = datoY;
  }
  else {
    document.getElementById(theId).style.width = datoX+'px';
    document.getElementById(theId).style.height = datoY+'px';
  }
}
//launch help window popup
function launchHelp() {
  var x = window.open('/about/video_help.html','glaucomahelp','width=300,height=400,scrollbars=yes');
}
//writes out flash object
function insertVideoClip(video_url, video_title, video_length, wrapper_id) {
  if ((wrapper_id == null) || (wrapper_id == undefined)) {
    wrapper_id = 'vidctrl';
  }
  var prelength='This video is ', postlength=' long.', video_base='/videos/';
  var video_help = 'javascript:launchHelp()';
  if (flash_version >= 7) {
    var flashString = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="100%" height="100%" id="glaucoma" align="top"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="'+video_base+'vidctrl_v4.swf" /><param name="quality" value="high" /><param name="scale" value="noscale" /><param name="salign" value="rt" /><param name="wmode" value="transparent" /><param name="FlashVars" value="vurl='+escape(video_url)+'&vtitle='+escape(video_title)+'&vprelength='+escape(prelength)+'&vlength='+escape(video_length)+'&vpostlength='+escape(postlength)+'&vhelp='+escape(video_help)+'&wrapid='+wrapper_id+'">';
    flashString += '<embed src="'+video_base+'vidctrl_v4.swf" FlashVars="vurl='+escape(video_url)+'&vtitle='+escape(video_title)+'&vprelength='+escape(prelength)+'&vlength='+escape(video_length)+'&vpostlength='+escape(postlength)+'&vhelp='+escape(video_help)+'&wrapid='+wrapper_id+'" quality="high" scale="noscale" salign="rt" wmode="transparent" bgcolor="#ffffff" width="100%" height="100%" name="glaucoma" align="top" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	document.getElementById(wrapper_id).innerHTML = flashString;
  } 
}
