// JavaScript Document
window.onload = initAll;
var videoDiv;
var dayDiv;
var titleDiv;
var width;
var height;

var dateArray=["May 17, 2008", "May 17, 2008","May 18, 2008","May 19, 2008", "May 20, 2008", "May 21, 2008","May 22, 2008",
			   "May 23, 2008","May 24, 2008","May 25, 2008","May 26, 2008","May 27, 2008","May 28, 2008","May 29, 2008",
			   "May 30, 2008", "May 31, 2008", "June 1, 2008", "June 2, 2008", "June 3, 2008", "June 4, 2008",
			   "June 5, 2008", "June 6, 2008", "June 7, 2008", "June 8, 2008", "June 9, 2008", "June 10, 2008",
			   "June 11, 2008", "June 12, 2008", "June 13, 2008", "June 14, 2008", "June 15, 2008", "June 16, 2008"];

var titleArray = ["Opening Ceremony", "Two extremes and the middle path", "Avoiding the two extremes with the three trainings",
                  "Realizing the Dhamma, one sees the Buddha.", "Buddha's answers to Upaka's questions", "Buddha, the conqueror of all",
				  "Dhammacakka", "To be true sons and daughters of the Buddha  ", "Good in the beginning, middle and the end. ",
				  "Without practice, one does not see the Buddha", "Developing eight fold noble path with satipatthana",
				  "Sati of good quality", "Characteristic, function, manifestation and proximate cause of sati",
				  "Pamada and 8 kinds of madness", "To be free from enmity and danger", "Gross form of pamada", "Gross and medium pamada",
				  "Letting oneself go freely on sensual objects", "Unique happiness that surpasses the worldly happiness",
				  "Talk by Sayadaw Ashin Nandasiri", "Cutting the currents", "Dana Perfection", "Systematic dana opens the path of morality",
				  "Observing Sila, one protects others from being hurt", "Factors that determine the class of one's sila",
				  "Avoiding refined form of pamada", "Kilesabhumi", "Hidden meaning of Dhamma", "Two at a blow"];
var videoDivCSSHide = "display:none;";
//var videoDivCSSShow = "position:absolute;display:inline;width:320px;height:240px;padding:10px;background-color:white;border:gray 1px solid;color:black;border:none;background-image:white320-300.gif";
var videoDivCSSShow =" display:inline;width:450px;height:380px;padding:10px;border:none;"
var currentIndex = -1;



function initAll(){
   MM_CheckFlashVersion('8,0,0,0','Content on this page requires a newer version of Adobe Flash Player. Do you want to download it now?');
  //titleDiv = document.getElementById("titleDiv");
  width = 320;
  height = 240;

}

function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}

function callNext(flashFile){
  var flashDiv = document.getElementById("flashDiv");
  flashDiv.removeChild(flashDiv.firstChild);
  flashFile = "Flash/"+flashFile;
  var str = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='";
  str += "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+width+"' height='"+height+"' id='FLVPlayer'>";
  str += "<param name='movie' value='FLVPlayer_Progressive.swf' />";
  str += "<param name='salign' value='lt' />";
  str += "<param name='quality' value='high' />";
  str += "<param name='scale' value='noscale' />";
  str += "<param name='FlashVars' value='&MM_ComponentVersion=1&skinName=Clear_Skin_3&streamName="+flashFile+"&autoPlay=true&autoRewind=false' />";
  str += "<embed src='FLVPlayer_Progressive.swf' flashvars='&MM_ComponentVersion=1&skinName=Clear_Skin_3&streamName="+flashFile+"&autoPlay=true&autoRewind=false'";
  str += " quality='high' scale='noscale' width='"+width+"' height='"+height+"' name='FLVPlayer' salign='LT' type='application/x-shockwave-flash'";
  str += " pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' />";
  str += "</object>";
  //var text = document.createTextNode(str);
  //flashDiv.appendChild(text);
  flashDiv.innerHTML = str;
  //alert("str = " + str);
}

function setVisibility(flashFile, partNum){
 var videoDiv = document.getElementById("videoDiv");
 setDateDiv(partNum);
 setTitleDiv();
 videoDiv.style.cssText =videoDivCSSShow;
 callNext(flashFile);
}

function setNoVisibility(e){
  var object=(window.event)?window.event.srcElement:this;
  var target=(window.event)?window.event.toElement:e.relatedTarget;
  var id = object.id;
  if (target != videoDiv)
    videoDiv.style.cssText = videoDivCSSHide;
}

function setDateDiv(partNum){
  var dateDiv = document.getElementById("dateDiv");
  if (dateDiv.lastChild)
     dateDiv.removeChild(dateDiv.lastChild);
  text = document.createTextNode(dateArray[currentIndex]+" - Part "+partNum);
  dateDiv.appendChild(text);
  //dateDiv.innerHTML = dateArray[currentIndex];
}

function setTitleDiv(){
  var titleDiv = document.getElementById("titleDiv");	
  if (titleDiv.lastChild)
    titleDiv.removeChild(titleDiv.lastChild);
  text = document.createTextNode(titleArray[currentIndex]);
  titleDiv.appendChild(text);
  //titleDiv.innerHTML = titleArray[currentIndex];
}

function part(partNum){
 var talkDate = dateArray[currentIndex];
 
 if (currentIndex > 10)
   day = currentIndex;
 else
   day='0'+currentIndex;
 setVisibility(day+"Spring08-"+partNum, partNum);
}


function watchVideoSize(id, w, h){
  width = w;
  height = h;
  currentIndex = id;
  part(1);
}

function watchVideo(id){
  width = 320;
  height = 240;
  currentIndex = id;
  part(1);
}

