dojo.require("dojo.parser");
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");

var volume = 1.0;

function showCaptions() {
  var captionArea = dijit.byId("captionArea");
  captionArea.domNode.parentNode.removeChild(captionArea.domNode);
  dijit.byId("main").addChild(captionArea);
  var iframe = dojo.byId("captionFrame");
  iframe.style.width = "100%";
  iframe.style.height = "100%";
  dojo.byId("hideCaptions").style.display = "inline";
  dojo.byId("showCaptions").style.display = "none";
  dojo.body().focus();
}

function hideCaptions() {
  var captionArea = dijit.byId("captionArea");
  dijit.byId("main").removeChild(captionArea);
  dojo.byId("hidden").appendChild(captionArea.domNode);
  dojo.byId("showCaptions").style.display = "inline";
  dojo.byId("hideCaptions").style.display = "none";
  dojo.body().focus();
}

function getChatRecorder() {
  return swfobject.getObjectById("chatrecorder");
}

function showVideo() {
  dojo.byId("videoContainer").style.width = "320px";
  dijit.byId("main")._layoutChildren();
  swfobject.getObjectById("flashvideo").startVideo();
  dojo.byId("hideVideo").style.display = "inline";
  dojo.byId("showVideo").style.display = "none";
  dojo.body().focus();
}

function hideVideo() {
  swfobject.getObjectById("flashvideo").stopVideo();
  dojo.byId("videoContainer").style.width = "8px";
  dijit.byId("main")._layoutChildren();
  dojo.byId("showVideo").style.display = "inline";
  dojo.byId("hideVideo").style.display = "none";
  dojo.body().focus();
}

function hasVideo() {
  window.setTimeout(showVideo, 50);
}

function mute() {
try {
  var media = dojo.byId("presenterMediaHTML5");
  if (media) {
    if (media.muted === false)
      media.muted = true;
    else
      window.alert("no muted property");
  } else
    swfobject.getObjectById("flashvideo").muteAudio();
  dojo.byId("mute").blur();
  dojo.byId("mute").style.display = "none";
  dojo.byId("volumeUp").style.display = "none";
  dojo.byId("volumeDown").style.display = "none";
  dojo.byId("unmute").style.display = "inline";
  dojo.byId("unmute").focus();
} catch (e) { window.alert(e); }
}

function unmute() {
  var media = dojo.byId("presenterMediaHTML5");
  if (media)
    media.muted = false;
  else
    swfobject.getObjectById("flashvideo").unmuteAudio();
  dojo.byId("unmute").blur();
  dojo.byId("unmute").style.display = "none";
  dojo.byId("mute").style.display = "inline";
  if (volume < 1.0)
    dojo.byId("volumeUp").style.display = "inline";
  if (volume)
    dojo.byId("volumeDown").style.display = "inline";
  dojo.byId("mute").focus();
}

function volumeUp() {
  volume += 0.125;
  var media = dojo.byId("presenterMediaHTML5");
  if (media)
    media.volume = volume;
  else
    swfobject.getObjectById("flashvideo").setAudioVolume(volume);
  if (volume >= 1.0) {
    dojo.byId("volumeDown").focus();
    dojo.byId("volumeUp").style.display = "none";
  }
}

function volumeDown() {
  if (volume <= 0.125) {
    mute();
    return;
  }
  volume -= 0.125;
  var media = dojo.byId("presenterMediaHTML5");
  if (media)
    media.volume = volume;
  else
    swfobject.getObjectById("flashvideo").setAudioVolume(volume);
  if (volume < 1.0)
    dojo.byId("volumeUp").style.display = "inline";
}

