/* copyright (c) Robert E Walker 2006 */


/********************************/
// Initialization

var movieControlIsLoaded = false;
var checkMovieStartInterval = 500;

/********************************/
function activateMovieControls ()
{
 try
 {
  var controllableElement = getControllableElement('testimonial');
  if (null != controllableElement)
  {
   movieStop('testimonial');
   showVideoControls();
   setTimeout('checkMovieStart()', checkMovieStartInterval);
  }// if
 }
 catch (error)
 {
  alert ('activateMovieControls: ' + error.message);
 }// try
}// function activateMovieControls

/********************************/
function showVideoControls ()
{
 /* display video controls */
 var divs = document.getElementsByTagName('div')
 var div;
 
 if (divs)
 {
  for (count = 0; count < divs.length; count++)
  {
   div = divs[count];
   // for IE Win use attribute 'className'
   if (('video_controls' == div.getAttribute('class')) || ('video_controls' == div.getAttribute('className')))
   {
//	div.style.display = 'block';
	div.style.visibility = 'visible';
   }
  }
 }
 // regardless of whether the controls actually loaded,
 // set the flag so we know we've finished here.
 movieControlIsLoaded = true;
}// function showVideoControls

/********************************/
function getControllableElement (movieId)
{
 var controllableElement = null;
 var element;
 var dump;
 
 if (element = document.getElementById(movieId))
 {
  // Check if element can be controlled
  // Send a command and if the command fails then element
  // cannot be controlled
  try
  {
   // IsPlaying is used as a convient supported method
   // ie: Safari and IE Win will not throw an error with this call
   dump = element.IsPlaying();
   // return element
   controllableElement = element;
  }
  catch (error)
  {
   // element cannot be controlled
   // look for a child embed element that can be controlled
   // note: this will return the first controllable embed
   var embeds;
   var embed;
   try
   {
    embeds = element.getElementsByTagName('embed');
    for (var count = 0; count < embeds.length; count++)
    {
     embed = embeds[count];
     try
     {
      dummy = embed.IsPlaying();
      controllableElement = embed;
     }
     catch (error)
     {
      alert (error.message);
     }// try
    }// for
   }
   catch (error)
   {
	alert (error.message);
   }// try
  }// try
 }
 else
 {
  throw new Error('Unable to get element id = ' + movieId)
 }// if
 
 return controllableElement;
}// function getControllableElement

/********************************/
function moviePlay (movieId)
{
 var movie;
 if (movie = getControllableElement(movieId))
 {
  movie.Play();
 }
}// function moviePlay

/********************************/
function movieStop (movieId)
{
 var movie;
 if (movie = getControllableElement(movieId))
 {
  movie.StopPlay();
 }
}// functin movieStop

/********************************/
function movieRewind (movieId)
{
 var movie;
 if (movie = getControllableElement(movieId))
 {
  movie.Rewind();
  movie.Play();
 }
}// functin movieStop

/********************************/
function checkMovieStart ()
{
 // check that all startup flags are set to true.
 
 // this flag is external to this script.
 // in case the flag isn't being used...
 if ('undefined' == typeof (cycleLinkIsLoaded))
 {
  cycleLinkIsLoaded = true;
 }// if
 
// if ((movieControlIsLoaded) && (cycleLinkIsLoaded))
 if (true)
 {
  try
  {
   if (loading = document.getElementById('video_loading'))
   { 
	loading.style.visibility = 'hidden';
   }// if
  }
  catch (error)
  { 
   // for now do nothing
  }// try
  moviePlay('testimonial');
//  alert('all loaded');
 }
 else
 {
  setTimeout('checkMovieStart()', checkMovieStartInterval);
 }// if

}// function checkMovieStart