// Video.js Copyright (c) 2005, 2007 by Gary L. Bradshaw.  All rights reserved

function qTVideoChoice ()
	{ top.videoType = 1;
	  setCookie("videoType","1");
	  window.location.reload();
	}
function wmVideoChoice ()
  {	top.videoType = 2;
	setCookie("videoType","2");
	window.location.reload();
  }

function showQuickTime(qtc, w, h)
  {	document.writeln('<div align="center">');
  	document.writeln('<OBJECT classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="'+w+'" height="'+h+'" codebase="http://www.apple.com/qtactivex/qtplugin.cab">');
    document.writeln('<param name="src" value="'+qtc+'">');
    document.writeln('<param name="autoplay" value="true">');
    document.writeln('<param name="controller" value="true">');
    document.write('<embed src="'+qtc+'" width="'+w+'" height="'+h+'" autoplay="true"'); 
    document.writeln('controller="true" pluginspage="http://www.apple.com/quicktime/download/">');
	document.writeln('</embed></object>');
  }

function showVideo(quickTimeClip, windowsMediaClip, width, height)
  { var qth = height+16;
  	var wmh = height+44;
	  if (top.videoType == 0) // The browser doesn't know what they they want to see
  	  {	if (getCookieValue("videoType") == null) // This information is not stored in a browser, either
	  		{ document.writeln('<div align="center"><p>Which type of video media do you prefer?</p>');
			  document.write('<form name="videoForm"><input type="button" value="QuickTime Video" onclick="qTVideoChoice();">');
			  document.write(' or <input type="button" onclick="wmVideoChoice();" value="Windows Media"></form></div>');
			}
		 else  // We found a cookie with the type information.  Set the browser variable and load the correct formmat
		 	{ top.videoType = getCookieValue("videoType"); // This sets the video type from the cookie
			  if (top.videoType == 1) showQuickTime(quickTimeClip, width, qth);
			  else	document.writeln('<embed src="'+windowsMediaClip+'" width="'+width+'" height="'+wmh+'"></embed>');
			}
	  }
	else if (top.videoType == 1)
	  {	showQuickTime(quickTimeClip, width, qth);	  }
	else
	  {	document.writeln('<embed src="'+windowsMediaClip+'" width="'+width+'" height="'+wmh+'"></embed>');
	  }
	//alert("we are in function showVideo!");

  }
  
function correctVideo()
  {	if (top.videoType == 1)
  	  {	top.videoType = 2; setCookie("videoType",2); }
	else { top.videoType = 1; setCookie("videoType", 1); }
	window.location.reload();
  }
 
 function videoChoice()
   { if (top.videoType != 0) 
	 	document.writeln('<div align="center"><form name="changeVideoForm"><input type="button" onclick="correctVideo();" value="Switch video type"></form></div>');
   }
  
 // If we had our act together, we would not have to define these here.  But it's difficult in a multi-frame situation to ensure everything is loaded properly,
 // so we put up with some redundancy.
  
function getCookieValue (cookieName)
  { var allCookies = document.cookie;
    var cookieStartsAt = allCookies.indexOf(" " + cookieName + "=");
    if (cookieStartsAt == -1)
      { cookieStartsAt = allCookies.indexOf(cookieName + "=");
      }
    if (cookieStartsAt == -1)
      { var cookieValue = null;
      }
    else
     { cookieStartsAt = allCookies.indexOf("=", cookieStartsAt) + 1;
       var cookieEndsAt = allCookies.indexOf(";", cookieStartsAt);
       if (cookieEndsAt == -1)
         { cookieEndsAt = allCookies.length;
	 }

       var cookieValue = unescape (allCookies.substring(cookieStartsAt, cookieEndsAt));
     }
    return cookieValue;
  }

function setCookie (cookieName, cookieValue)
  { // We set the cookie to expire one year from now
    var nextYear = new Date();
    nextYear.setFullYear(nextYear.getFullYear()+1);
    var cookieExpires = "; expires="+nextYear.toGMTString();

    // Set the path to refer to any page on this server
    var cookiePath = '; path=/';

    var cookieString = cookieName + "=" + cookieValue + cookieExpires + cookiePath
    document.cookie = cookieString;
    if (getCookieValue(cookieName) == null)
      { alert("Cookies must be enabled in order to save your page and return to it later!");
      }
  }   
