// This file needs to be present on http://files.kudda.com/javascripts/ along with jquery and swfobject

$(document).ready(function() {
  $('#clinics').change(function() {setPlaylist('mediaplayer', this)});
  $('#videos').change(function() {setVideo('mediaplayer', this)});
})

var play_after_update = false;
function setPlaylist(id, select) {
  var clinic_id = select.options[select.selectedIndex].value;
  var url = playlist_urls[clinic_id];
  play_after_update = true;
  populateOptions(document.getElementById('videos'), clinic_id);
  player(id).loadFile({file:url});
}
function getUpdate(type,pr1,pr2,swf) {
  if (type == 'state' && pr1 == 0 && play_after_update) {
    window.setTimeout(function() {player(swf).sendEvent('playpause');}, 500);
    play_after_update = false;
  }
}

function setVideo(id, select) {
  player(id).sendEvent('playitem', select.selectedIndex);
}

function player(id) {
  return document.getElementById(id)
}
function populateOptions(select, clinic_id) {
  select.options.length = 0;
  var videos = playlist_videos[clinic_id];
  for(var i=0; i < videos.length; ++i) {
    select.options[i] = new Option(videos[i],videos[i]);
  }
}