﻿  function SwapProjectVideo(imgID, videoPanelID, videoUrl, creditsID, creditsText, optionContainerID, selectedOptionID)
  {
    //Write out the flash object       
    var videoElem = document.getElementById(videoPanelID);
    videoElem.innerHTML = BuildYTFlashObj(videoUrl);
  
    //Show video, hide image
    ShowHideElements(videoPanelID, imgID)
    
    //Change the credits
    UpdateCredits(creditsID, creditsText);
    
    //Change the 'selected' class on appropriate option
    SetSelectedOption(optionContainerID, selectedOptionID);
  }

  function SwapProjectImage(imgID, videoPanelID, imgPath, imgAlt, creditsID, creditsText, optionContainerID, selectedOptionID)
  {
    //Change the image, the alt text
    var imgElem = document.getElementById(imgID);
    imgElem.src = imgPath;
    imgElem.alt = imgAlt;
    
    //Show Image, hide video
    ShowHideElements(imgID, videoPanelID)
    
    //Change the credits
    UpdateCredits(creditsID, creditsText);

    //Change the 'selected' class on appropriate option
    SetSelectedOption(optionContainerID, selectedOptionID);
  }
  
  function ShowHideElements(showElemID, hideElemID)
  {
    //Hide Element
    var hideElem = document.getElementById(hideElemID);
    hideElem.style.display = "none";
    
    //Show Element
    var showElem = document.getElementById(showElemID);
    showElem.style.display = "block";
  }
  
  function UpdateCredits(creditsID, creditsText)
  {
    var creditElem = document.getElementById(creditsID);
    creditElem.innerHTML = creditsText;
  }
  
  function SetSelectedOption(optionContainerID, selectedOptionID)
  {
    var container = document.getElementById(optionContainerID);
    var options = container.getElementsByTagName('a');
    
    for(i=0; i<options.length;i++)
    {
        var option = options[i];
        if(option.id == selectedOptionID)
            option.className = 'selected';
        else
            option.className = '';
    }
  }
  
  function BuildYTFlashObj(videoUrl)
  {
     return "<object width=\"445\" height=\"295\">" +
        "<param name=\"movie\" value=\"" + videoUrl + "\"></param>" +
        "<param name=\"allowFullScreen\" value=\"true\"></param>" +
        "<param name=\"allowscriptaccess\" value=\"always\"></param>" + 
        "<embed src=\"" + videoUrl + "\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"445\" height=\"295\"></embed></object>";
  }