var wto;
var lastTab = -1;


function iwOpen() {
  wto = window.setTimeout('iwGetTab()',1000);
}

function iwClose() {
  window.clearTimeout(wto);
  lastTab = -1;
  var vidElement = document.getElementById("video");
  if (vidElement) vidElement.innerHTML = "&nbsp;";
}

function iwGetTab() {
  var at = map.getMap().getInfoWindow().getSelectedTab();
  if (at != lastTab) {
    var activeTab = map.getMap().getInfoWindow().getTabs()[at];
    lastTab = at;
    if(activeTab.label = 'Video') {
      var camera = document.getElementById("cameraid");
      if (camera) {
        var cameraId = camera.value;
        var video = document.getElementById("video");
        if (video) video.innerHTML = build_video_html(cameraId,4);
      }
    }
  }
  wto = window.setTimeout('iwGetTab()',1000);
}

