///
/// functions related to videos
///

//
// variables used to associate video index with the actual video url and id
// example: from videos_2003.html we link to showvideo.html?id=200301;
// then in showvideo.html, we look up and find that id 200301 corresponds
// to file chemistrylecture.flv
//
// important: for RTMP streams, the file is the stream, and the id is the
// filename without the .flv
//

// prefix to all file parameters (if they all come from the same stream or server,
// put it here rather than in the array)
var videofile_prefix = "rtmp://18.39.0.27/streams/";

// association between video indices and the video files/ids
// indices of videodata array are the indices passed to this page in the "vid" parameter
// each element in the videodata array is an array with two elements, the file and id
var videodata = new Array();
videodata["2006_austin"] =    new Array("","sept-1-austin-26jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_drennan"] =   new Array("","sept-2-drennan-26jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_koehrer"] =   new Array("","sept-4-koehrer-26jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_minesinger"] = new Array("","sept-5-minesinger-26jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_weigele"] =   new Array("","sept-6-weigele-26jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_lewin"] =     new Array("","sept-7-lewin-26jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_schechter"] = new Array("","sept-8-shechter-27jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_tegmark"] =   new Array("","sept-9-tegmark-27jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_jerison"] =   new Array("","sept-10-jerison-27jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_edelman"] =   new Array("","sept-11-edelman-27jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_behrens"] =   new Array("","sept-12-behrens-27jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_sadoway"] =   new Array("","sept-13-sadoway-28jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_roylance"] =  new Array("","sept-14-roylance-28jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_stellacci"] = new Array("","sept-15-stellacci-28jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_mcgann"] =    new Array("","sept-16-mcgann-28jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_livingston"] = new Array("","sept-17-livingston-28jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_ross"] =      new Array("","sept-18-ross-28jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_cima"] =      new Array("","sept-19-cima-28jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_sodini"] =    new Array("","sept-20-sodini-29jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_winston"] =   new Array("","sept-21-winston-30jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_sussman"] =   new Array("","sept-22-sussman-30jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_coderre"] =   new Array("","sept-23-coderre-30jun2006_SEPT_VP6_384K_480x360_Strm");
videodata["2006_golay"] =     new Array("","sept-24-golay-30jun2006_SEPT_VP6_384K_480x360_Strm");


//
// generalized code to parse get parameters
// results placed in array getparameters[]
// (indices are paremeters, values are parameter values)
//
var getparameters = new Array();
function parse_searchstring() {
  // get search string
  var ss = location.search;
  // remove initial "?" if any
  ss = ss.substring(ss.lastIndexOf("?")+1,ss.length);
  var ssa = ss.split('&');
  for (var i=0; i < ssa.length; i++) {
    var ssa2 = ssa[i].split('=');
    if (ssa2.length == 2) {
      getparameters[decodeURIComponent(ssa2[0])] = decodeURIComponent(ssa2[1]);
      //alert("parameter "+ssa2[0]+", value "+ssa2[1]); // debugging
    }
  }
}
parse_searchstring();

//
// return "file" parameter for video player
// (for rtmp, this is the stream; for progressive downloads, this is the path to the flv)
// called within showvideo.html
//
function getvideofile() {
  var videofile = "";
  var vid = getparameters["vid"];
  if (typeof videodata[vid] == "object") {
    videofile = videofile_prefix + videodata[vid][0];
  }
  //alert(videofile); // debugging
  return videofile;
}
//
// return "id" parameter for video player
// (for rtmp, this is the file, minus the .flv extension; for progressive downloads, this is usually blank)
// called within showvideo.html
//
function getvideoid() {
  var videoid = "";
  var vid = getparameters["vid"];
  if (typeof videodata[vid] == "object") {
    videoid = videodata[vid][1];
  }
  //alert(videoid); // debugging
  return videoid;
}

//
// return "type" parameter for video player
// (makes a reasonable guess; if the id is not blank, returns "rtmp", otherwise returns "flv")
// called within showvideo.html
//
function getvideotype() {
  var videotype = "";
  var vid = getparameters["vid"];
  if (typeof videodata[vid] == "object") {
    videotype = (videodata[vid][1] == "" ? "flv" : "rtmp");
  }
  //alert(videotype); // debugging
  return videotype;
}
//
// open video page in popup - called from page listing videos
//
function openvideopopup(id) {
  if (window.open("showvideo.html?vid="+id,"","width=480,height=380,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no"))
    return false;
  else
    return true;
}


