
function initListTable(){
  var listTable = document.getElementById("listTable");
  var items = listTable.getElementsByTagName("TR");
  for (var item, i=0, l = items.length; i<l; i++){
    item = items.item(i);
    
    item.onmouseover = function(){
      if (this.className != "active"){
        this.className = "over";
      }
    }
    item.onmouseout = function(){
      if (this.className == "over"){
        this.className = "";
      }
    }
    item.onclick = function(){
      showVideo(this.getAttribute("flv"));
      
      unsetActiveListItem()

      this.className = "active";
    }
  }
}

function unsetActiveListItem(){
  var listTable = document.getElementById("listTable");
  var items = listTable.getElementsByTagName("TR");
  for (var i=0, l = items.length; i<l; i++){
    items.item(i).className = "";
  }
}

function showVideo(flv){

  var c = document.getElementById("c");

  var oldVideo = document.getElementById("video");
  if (oldVideo) {
    if (oldVideo.flv == flv){
      return;
    }
    c.removeChild(oldVideo);
  }


  var video = document.createElement("div");
  video.id = "video";
  video.flv = flv;
  c.appendChild(video);

  var header = document.createElement("div");
  header.id = "video_header";
  video.appendChild(header);

  var closeBtn = document.createElement("div");
  closeBtn.innerHTML = "Close";
  closeBtn.id = "closeBtn";
  closeBtn.onclick = function(){
    document.getElementById("c").removeChild(document.getElementById("video"));
    unsetActiveListItem();
  }
  header.appendChild(closeBtn);

  var video_c = document.createElement("div");
  video_c.id = "video_c";
  video_c.setAttribute("href", '../'+document.body.className + '_flv/' + flv);
  video.appendChild(video_c);

  flowplayer("video_c", "/films/flowplayer.swf", {
    clip:  {
        autoPlay: true,
        baseUrl: location.href
    },
    /*
    onLoad: function() {
      this.setVolume(5);
    },
    */
    plugins: {
      controls: {

          url: '/films/flowplayer.controls.swf',
          
          play:true,
          volume:true,
          mute:true,
          time:false,
          stop:false,
          playlist:false,
          fullscreen:true,
          scrubber:true,

          backgroundColor:'#bdb5af',
          backgroundGradient: [0.2,0.5,0.3,0],

          buttonColor:"#787f75",
          buttonOverColor:"#ef4029",

          progressColor:"#565b54",
          progressGradient:"medium",
          
          bufferColor:"#787f75",
          bufferGradient:"none",

          volumeSliderColor:"#787f75",
          volumeSliderGradient:"none",

          tooltipColor: '#787f75',
          tooltipTextColor:"#ffffff",

          tooltips: {
            buttons:true,
            play:null,
            pause:null,
            mute:null,
            unmute:null,
            stop:null,
            fullscreen: "Enter fullscreen mode",
            fullscreenExit: "Leave fullscreen mode"
          }

      }
    }
  });

}