//check for quicktime
var hasQuicktime = false;
if (navigator.plugins) {
  for (i=0; i < navigator.plugins.length; i++ ) {
    if (navigator.plugins[i].name.indexOf("QuickTime") >= 0) {
      hasQuicktime = true;
    }
  }
}
function openCurrentEpisode(show) {
  if (shows[show]["recordCount"] > 0) {
    myURL = shows[show]['mediaURL'][1];
    showVideo('myVideo',myURL);
  } else {
    alert('There are no episodes for this show just yet... Check back soon though!');
  }
}
function openEpisode(show,episode) {
  if (shows[show]["recordCount"] > 0) {
    myURL = shows[show]['mediaURL'][episode];
    showVideo('myVideo',myURL);
  } else {
    alert('There are no episodes for this show just yet... Check back soon though!');
  }
}
function showVideo(windowName,videoURL) {
  //video sizes: 352x288
  var myWindow = window.open('',windowName,'width=380,height=425,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0');
  myWindow.document.clear();
  myWindow.document.open();
  myWindow.document.write("<html><head><title>Video Preview</title>

	</head><body bgcolor='#000000'>");
  myWindow.document.write("<div align='center'><embed width='352' height='314' bgcolor='#000000' src='" + videoURL + "' ");
  if (hasQuicktime) {
    myWindow.document.write("autoplay='true' autostart='true' controller='true' type='video/quicktime' border='0' pluginspage='http://www.apple.com/quicktime/download/'>");
  } else {
    myWindow.document.write("autoplay='true' autostart='true' controller='true' type='video/quicktime' border='0' pluginspage='http://www.real.com/'>");
  }
  myWindow.document.write("<p style='color: #ffffff; font-family: verdana; font-size: 10px;'>If the video doesn't load<br>please install the latest QuickTime.<br>");
  myWindow.document.write("<a href='http://www.apple.com/quicktime/download/' target='_blank'><img src='/shared/grphx/qtbanner.jpg' width='88' height='31' border='0' vspace='5'></a></p>");
  myWindow.document.write("</div></body></html>");
  myWindow.document.focus();
}
function printEpisodes(show,sort) {
  document.write("<br><p class='headline'>Archive:</p>");

  //write the episodes out
  if (shows[show]["recordCount"] == 0) {
    document.write("<p><em>There are no episodes for this show just yet... Check back soon though!</em></p>");
  } else {
    document.write("<ul>");
    for (i = 1; i <= shows[show]["recordCount"]; i++) {
      document.write('  <li><a href="#" onClick="openEpisode(\'' + show + '\',' + i + ');"><strong>' + shows[show]["title"][i] + '</strong></a><br>');
      document.write(shows[show]["subTitle"][i] + "<br>");
      document.write(shows[show]["airDate"][i] + "<br>&nbsp;</li>");
    }
    document.write("</ul>");
  }
}
