function load_reel(){

  if (data == null){return true}
  var clipSelect = document.getElementById('clipSelect');

  var html = '';
  var img;
  for (var i = 0; i < data.length; i++ ) {
    var clip = data[i];
    var img_path = clip.img;
    html += '<img class="control" src="' + img_path + '" ';
    html += 'onmouseover=hover_info(' + i + '); ';
    html += 'onmouseout=hover_info(-1); ';
    if ( i == data.length - 1 ) {
      html += 'onload=showme(); ';
    }
    html += 'onclick=play_clip(' + i + ');>';
  }
  clipSelect.innerHTML = html;
  var clip = data[data.length-1];
}

function showme() {

  var player = document.getElementById('player');
  player.style.visibility = 'visible';
  var mywindow = window.setInterval(update_player,1000);

  if ( ( current != null && current != -1 ) ) {
    play_clip(current,false);
  }
  else {
    play_all();
  }
  hover_info(-1);
}

function update_player(){

  // find out if we are at the end of a movie
  if ( document.player == null ) { return true; }

  // get duration and current time and see if we are really close to end
  var status = document.player.GetPluginStatus();
  if ( ( status != "Playable" ) && ( status != "Complete" ) ) { return true };

  var duration = document.player.GetDuration();
  var time = document.player.GetTime();
  if ( duration < time + 500 ) {
    document.player.Stop();
    if ( !playone ) {
      play_clip((current + 1), true);
    }
  }
}

function clip_info(i) {

  if (data == null){return true}
  var clip = data[i];
  if (clip == null){return true}

  // update the clip information
  var product = document.getElementById('clipProduct');
  var title = document.getElementById('clipTitle');
  var editor_name = document.getElementById('editorName');
  var editor_email = document.getElementById('editorEmail');
  var director_name = document.getElementById('directorName');
  var director_title = document.getElementById('directorTitle');
  product.innerHTML = clip.product.toLowerCase();
  title.innerHTML = ('"' + clip.title + '"').toLowerCase();
  editor_name.innerHTML = clip.artist.toLowerCase();
  editor_email.innerHTML = clip.email.toLowerCase();
  editor_email.href = 'mailto:' + clip.email.toLowerCase();

  // clear out director if not set to anything
  if ( clip.director == null ) {
    director_title.innerHTML = '';
    director_name.innerHTML = '';
  }
  else {
    director_title.innerHTML = 'director';
    director_name.innerHTML = clip.director.toLowerCase();
  }
}

function play_clip(i, playall) {

  if (data == null){return true}
  if ( document.player != null ) { document.player.Stop() };

  // update current
  current = i;

  // if user clicked on spot only play that one spot
  if ( playall != true ) {playone = true;}

  // change clip information 
  clip_info(i);

  // change quicktime player movie
  var clip = data[i];
  if (clip == null){return true}
  if (clip.mov == null){return true}
  var qt = get_qt( clip.mov );
  var clipPlay = document.getElementById('clipPlay');
  clipPlay.style.visibility = 'hidden';
  clipPlay.innerHTML = qt;
  clipPlay.style.visibility = 'visible';
}

function play_all() {

  if (data == null){return true}

  // reset current and play first clip
  playone = false;
  current = 0;
  play_clip(0, true);
}

function get_qt(mov) {

   var qt = '';
   qt += '<embed name="player" width="480" height="376 scale="aspect"';
   qt += 'enablejavascript="true" cache="true" kioskmode="true"';
   qt += 'showlogo="false" bgcolor="000000" src="' + mov + '">';
   return qt;
}

function hover_info(i) {

  if (data == null){return true}

  // get heading elements to set
  var product = document.getElementById('hoverProduct');
  var title = document.getElementById('hoverTitle');
  if (i == -1 ) {
    product.innerHTML = '';
    title.innerHTML = '';
  }
  else {
    var clip = data[i];
    product.innerHTML = clip.product.toLowerCase();
    title.innerHTML = ('"' + clip.title + '"').toLowerCase();
  }
}

function download() {

  // stop the movie and download from download.pl on cuttersmedia.com
  document.player.Stop();

  var mov = '' + data[current].mov;
  mov = mov.replace(/^.*[\/\\]/g,'');
  // mov = "http://www.cuttersmedia.com/download.pl?filename=" + mov;
  mov = "http://www.cuttersinc.com/dl?filename=" + mov;
  top.location.href = mov;
}

function podcast() {

  // stop the movie and download podcast from podcast.cgi on cuttersmedia.com
  document.player.Stop();
  var pcp = "itpc://www.cuttersinc.com/pc?name=" + pc;
  top.location.href = pcp;
}

function go_back() {

  // stop the movie and switch to the home page
  document.player.Stop();
  window.location = "http://www.cutters.com/flash_web/main.html";
}

function send_link (){

  // stop the movie and open up the email interface
  document.player.Stop();
  (window.open('http://www.cutters.com/e?a=compose&from=&name=' + name,
               '', 'height=600,width=600')).focus();
}

