var so;

function selPodItem(sel) {
  if ($('matflag').value == "1" && $('matcontent').style.display != 'block') {
   return false;
  } 

  var mediaurl = podcastitems[sel][0];
  var mediatype = podcastitems[sel][1];
  
  for (i=0; i<podcastitems.length; i++) {
    $('med_'+i+'_1').style.backgroundColor = podcastitems[i][2];
    $('med_'+i+'_2').style.backgroundColor = podcastitems[i][2];
    $('med_'+i+'_3').style.backgroundColor = podcastitems[i][2];    
    $('med_'+i+'_1').style.color = "#4B4B4B";
    $('med_'+i+'_2').style.color = "#4B4B4B";
    $('med_'+i+'_3').style.color = "#4B4B4B";
  } 
  $('med_'+sel+'_1').style.backgroundColor = "#2071C9";
  $('med_'+sel+'_1').style.color = "#ffffff";
  $('med_'+sel+'_2').style.backgroundColor = "#2071C9";
  $('med_'+sel+'_2').style.color = "#ffffff";  
  $('med_'+sel+'_3').style.backgroundColor = "#2071C9";
  $('med_'+sel+'_3').style.color = "#ffffff";


  // alert(mediaurl);  
  // prompt("",mediaurl);
  // alert(mediatype);
  
  
  if (mediatype == "flv" || mediatype == "mp3") {
    so = new SWFObject("/swf/player.swf", "video", "540", "405", "8", "#ffffff");
    so.useExpressInstall('/swf/expressinstall.swf');
    so.addParam("allowFullScreen","true");
    so.addVariable("autoplay","true");    
    so.addVariable("bcolor","2071c9");
    so.addVariable("src", mediaurl);    
    so.write("podcontent");  
  }      
  else if (mediatype == "wmv" || mediatype == "avi") {
    $('podcontent').innerHTML = getHtmlWMV(mediaurl);
  } 
  else if (mediatype == "mov" || mediaurl.indexOf("redirect.mp4") > -1) {
    $('podcontent').innerHTML = getHtmlMOV(mediaurl);
  }     
  else {
    $('podcontent').innerHTML = getHtmlMOV(mediaurl); 
  } 
}

function podcastPlay() {
  if (podcastitems != undefined && podcastitems.length > 0) {
    selPodItem(0); 
  }
  else {
    alert("Sorry, no episodes to play");
  }
}



function getHtmlWMV(url) {
  var r = "<OBJECT width=\"540\" height=\"405\" CLASSID=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\" type=\"application/x-oleobject\">";
  r += "<PARAM NAME=\"URL\" VALUE=\""+url+"\">";
  r += "<PARAM NAME=\"AutoStart\" VALUE=\"true\">";
  r += "<PARAM name=\"uiMode\" value=\"none\">";
  r += "<PARAM name=\"stretchToFit\" value=\"true\">";
  r += "<PARAM name=\"volume\" value=\"50%\">";
  r += "<param name=\"showgotobar\" value=\"0\" />";
  r += "<PARAM name=\"enableContextMenu\" value=\"false\">";
  r += "<PARAM name=\"showControls\" value=\"false\">";
  r += "<embed type=\"application/x-mplayer2\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\" width=\"540\" height=\"405\" autostart=\"1\" showcontrols=\"0\" showstatusbar=\"1\" enablecontextmenu=\"0\" volume=\"50%\" src=\""+url+"\"></embed>";
  r += "</OBJECT>";
  
  return r;  
}
function getHtmlMOV(url) {
  var r = "<OBJECT width=\"540\" height=\"405\" CLASSID=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" type=\"video/quicktime\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\">\n";
  r += "<PARAM NAME=\"SRC\" VALUE=\""+url+"\">\n";
  r += "<PARAM NAME=\"AUTOSTART\" VALUE=\"true\">\n";
  r += "<PARAM NAME=\"scale\" VALUE=\"toFit\">\n";
  r += "<param name=\"type\" value=\"video/quicktime\" width=\"540\" height=\"405\">\n";
  r += "<EMBED SRC=\""+url+"\" width=\"540\" height=\"405\" autostart=\"true\" type=\"video/quicktime\" scale=\"toFit\" pluginspage=\"http://www.apple.com/quicktime/download/\"></embed>\n";
  r += "</OBJECT>\n";
  return r;
}
