// set up a variable tracking the selected button of the current video
var current_video; // = "Spot-A2-SD.flv";
// Use a variable to reference the embedded SWF file.
var flashVideoPlayer;// = (isIE) ? window['videoPlayer'] : document['videoPlayer'];

if (document.layers) {
  visible = 'show';
  hidden = 'hide';
} else if (document.getElementById) {
  visible = 'visible';
  hidden = 'hidden';
} else if (document.all) {
  visible = 'visible';
  hidden = 'hidden';
}

/* When the HTML page loads (through the onLoad event of the <body> tag), it calls the initialize() function. */
function initialize_video() {
    /* Check whether the browser is IE. If so, flashVideoPlayer is
    window.videoPlayer. Otherwise, it's document.videoPlayer. The
    videoPlayer is the ID assigned to the <object> and <embed> tags. */
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    // flashVideoPlayer = (isIE) ? window['videoPlayer'] : document['videoPlayer'];
    flashVideoPlayer = returnObjById('videoPlayer');
}

/* When the user clicks the play button in the form, update the videoStatus text area, and call the playVideo() function within the SWF file, passing it the URL of the FLV file. */
function callFlashPlayVideo(src,play) {
    if(!play) { play = false; }
    var video = src + '.flv';
    var resume = document.getElementById('resume');
    resume.innerHTML = '<p>Loading content...</p>';
    var flashcontent = returnObjById('flashcontent');
    if (flashcontent.style.left != '0px') {
      flashcontent.style.left = '315px';
      flashcontent.style.top = '60px';
//           flashcontent.style.display = 'block';
    }
    flashVideoPlayer.playVideo(video,play);
    current_video = video;
    resume.style.top = '315px';
    var handleSuccess = function(o){
        if(o.responseText != ''){
            resume.innerHTML = o.responseText;
        }
    }
    
    var handleFailure = function(o){
        resume.innerHTML='<p>Sorry. There is a problem loading this file.</p>';
    };
    
    var callback = {
      success:handleSuccess,
      failure: handleFailure,
      argument: { foo:"foo", bar:"bar" }
    };     
    
    var request = YAHOO.util.Connect.asyncRequest('GET', 'synopses/'+src+'.html', callback); 
}

function hide_me() {
    //alert(returnObjById('videoPlayer').pauseResume());
    var flashcontent = returnObjById('flashcontent');
    flashcontent.style.left = '-600px';
    callFlashPlayPauseVideo();
    var resume = document.getElementById('resume');
    resume.style.top = '60px';
//         flashcontent.style.display = 'none';
}

// Call the pauseResume() function within the SWF file.
function callFlashPlayPauseVideo() {
    flashVideoPlayer.pauseResume();
}

function returnObjById( id ){
    var returnVar;
    if (document.getElementById) { returnVar = document.getElementById(id); }
    else if (document.all) { returnVar = document.all[id]; }
    else if (document.layers) { returnVar = document.layers[id]; }
    return returnVar;
}

function addEvent(obj, evType, fn, useCapture){
    if (obj.addEventListener){
      obj.addEventListener(evType, fn, useCapture);
      return true;
    } else if (obj.attachEvent){
      var r = obj.attachEvent("on"+evType, fn);
      return r;
    } else {
      alert("Handler could not be attached");
    }
};

function initialize() {
    // write flash video player
    var so = new SWFObject("flv/tv2.swf", "videoPlayer", "384", "297", "0", "#ffffff");
    so.write("flashcontent");
    initialize_video();
    // create a node for video blurbs
    var flashcontent = returnObjById('flashcontent');
}
addEvent(window, 'load', initialize, false);


