var current_video_playing = false;
function ShowAutoBigVideo(video_file,suffix){
  //this allows a prefix like this '__4__' at the beginning of the file if the same video occurs multiple times on the one page.
  video_file_original = video_file; 
  video_file = video_file.replace(/^__[0-9]+__/,'');
  
  var fo = new SWFObject("/images/flowplayer-3.0.0-rc3.swf", "FlowPlayer", "320", "264", "7", "#FFFFFF", true);
  fo.addParam("allowScriptAccess", "always");
  fo.addParam("allowFullScreen", "true");

  // fo.addParam("flashVars", "config={videoFile: 'http://video.thetourspecialists.com/videos/" + video_file + suffix + "', configFileName: 'scripts/videoDefaults.js',autoPlay: true }");
  fo.addVariable("config", "{'clip':'http://video.thetourspecialists.com/videos/" + video_file + suffix + "'}");
  fo.write("vid-holder-"+video_file_original);
}		

function ID(id){
 return document.getElementById(id);
}

function generate_minimal_controls(video_file){
  
  var control_text = ' <a class="vid-close" onClick="closeVideo(\''+video_file+'\'); return false;">[close]</a> ';
  ID('controls-'+video_file).innerHTML = control_text;
  
}

function generate_controls(video_file){
  
  var control_text = 'Choose Quality:';
	control_text += ' <a class="vid-close" onClick="closeVideo(\''+video_file+'\'); return false;">[close]</a> ';
  control_text += '<a href="javascript:show_low(\''+video_file+'\');" id="show_low-'+video_file+'">256k</a> | ';
	control_text += '<a href="javascript:show_high(\''+video_file+'\');" id="show_high-'+video_file+'">512k</a>';
  ID('controls-'+video_file).innerHTML = control_text;
  
}
//Use this if you want to show the 256k(low-speed) version of the video
function show_low(video_file){
  generate_controls(video_file);
  ShowAutoBigVideo(video_file,'-256k.flv');
  ID('show_low-'+video_file).style.fontWeight = 'bold';
  ID('show_high-'+video_file).style.fontWeight = 'normal';
  ID('thumb-image-'+video_file).style.display='none';
  ID('video-wrapper-'+video_file).style.display='';
  
}
//Use this if you want to show the 512k(high-speed) version of the video
function show_high(video_file){
  if(video_file != current_video_playing && current_video_playing != false)
    closeVideo(current_video_playing);
  current_video_playing = video_file;
  generate_controls(video_file);
  ShowAutoBigVideo(video_file,'-512k.flv');
  ID('show_low-'+video_file).style.fontWeight = 'normal';
  ID('show_high-'+video_file).style.fontWeight = 'bold';
  ID('thumb-image-'+video_file).style.display='none';
  ID('video-wrapper-'+video_file).style.display='';
}
//Use this only if you have access to a thumbnail version of the video
function show_stretched_thumb(video_file){
  generate_minimal_controls(video_file);
  ShowAutoBigVideo(video_file,'-thumb.flv');
  ID('thumb-image-'+video_file).style.display='none';
  ID('video-wrapper-'+video_file).style.display='';
}
 
function closeVideo(video_file){
  ID('video-wrapper-'+video_file).style.display='none';
  ID('thumb-image-'+video_file).style.display=''; 
  ID('vid-holder-'+video_file).innerHTML='';
}

function DrawOverlay(videofile){
  var image_file = 'images/g-play-movie-l.png';
  document.write('<div class="large-image-overlay" onClick="show_high(\'' + videofile + '\');" id="overlay-' + videofile + '" class="cursor_link" style="background: transparent url(\'' + image_file + '\') no-repeat center center;" ></div>');    


  var overlaydiv = ID('overlay-'+videofile);
  //IE Overlay hack
  
  if (navigator.appVersion.indexOf("MSIE")!=-1){
    overlaydiv.style.backgroundImage = '';
    overlaydiv.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + image_file + ",sizingMethod='scale')";
  }
  
}