// script to deal with related videos 
function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? document.getElementById(movieName) : document[movieName];
}

function playNewFlv(url) {
  getFlashMovie("video").playNewFlv(url);
}

$(document).ready(function() {
  // Remove the video that is currently playing
  $(".relatedvid").each(function() {
    var testSrc = $(this).children("p.lnk").children("a.video").attr("href");

    if (currentVidSrc == testSrc) {
      // same video, so let's hide it
      $(this).hide();
    }
  });
  
  // find the video links in the related videos section, intercept them,
  // and force the video player to reload with video chosen
  $("#related-videos a.video, #related-videos p.img a").bind("click", function() {
    // update the name, business, location
    var parentContainer = $(this).parents("div.relatedvid");
    var testName = parentContainer.children("p.citation").children("cite").text();
    var testBusiness = parentContainer.children("p.citation").children("span.companyname").text();
    var testLocation = parentContainer.children("p.citation").children("span.location").text();

    $("p.vidinfo").html(testName + "<br />" + testBusiness + testLocation);

    // update the headline as well
    var testTitle = parentContainer.children("h4").html();
	try
	{
		console.log(parentContainer.children("h4").html());
	}
	catch(err)
	{}
    $("h1 span").html(testTitle);

    // hide the current video that they have chosen, but make sure everything
    // is displayed first before we hide
    $(".relatedvid").slideDown();
    parentContainer.slideUp();

    // play the new video
    playNewFlv($(this).attr("href"));
    return false;
  });
});
