// imageList = null;
nbImages = 0;
imageIdList = "";
currentImage = "";
currentImageNum = "";

function initImageIdList()
{
  imageIdList = Array();
  
  //  Parse all links and associate the JS
  i=0;
  $('wehc-images').getChildren().each(function(item, index){
    imageIdList[i] = item.getChildren();
    i++;
  });
}


/**
 * Shows a big image
 *
 * @param string : link identifier
 * @param string : image url
 * @return void
 * @author nicolas
 **/
function showImage(imageNum)
{
  imageId = $('wehc-img'+imageNum);
  if (imageId!=currentImage)
  {
    if (currentImage!="")
    {
      currentImage.removeClass("current");
    } else {
      $('wehc-images').getFirst().getChildren().removeClass("current");
    }
    currentImage = imageId;
    currentImageNum = imageNum;

    imageId.addClass("current");

    img = new Asset.image("../assets/img/slideshow/"+imageList[imageNum], {title: ''});
    $('wehc-big-picture').getFirst().replaceWith(img);
  }
  return false;
}

/**
 * Opens the main video Player popup from the site menu
 *
 * @param none
 * @return void
 * @author nicolas
 **/
function showNextImage()
{
  if (!imageIdList)
  {
    initImageIdList();
  }
  imageNum = (currentImageNum+1)%nbImages;
  showImage(imageNum);
  
  return false;
}

/**
 * Shows the previous image
 *
 * @param none
 * @return void
 * @author nicolas
 **/
function showPreviousImage()
{
  if (!imageIdList)
  {
    initImageIdList();
  }
  imageNum = (nbImages+currentImageNum-1)%nbImages;
  showImage(imageNum);
  
  return false;
}

/**
 * Opens the main video Player popup from the site menu
 *
 * @param none
 * @return void
 * @author nicolas
 **/
function launchMainVideo()
{
  //launchVideoPlayer('http://static.we.tv/uploads/video/index.html?bcpid=296756391&bclid=1349157579');
	launchVideoPlayer('http://link.brightcove.com/services/link/bcpid1370868025');
}

/**
 * Opens the video Player popup
 *
 * @param String URL
 * @return void
 * @author nicolas
 **/
function launchVideoPlayer(videoUrl)
{
  window.open(videoUrl,'popup_video_wetvhc','menubar=no, status=no, scrollbars=no, menubar=no, width=790, height=620');
}


/**
 * Toggles a blog entry opened/closed state
 *
 * @integer, blogEntryId
 * @return void
 * @author nicolas
 **/
function toggleBlogEntry(blogEntryId)
{
  $('wehc-postid-button-'+blogEntryId).toggleClass('close');
  $("wehc-postid-"+blogEntryId).toggleClass('opened');
  return false;
}

/**
 * Toggles an helpline opened/closed state
 *
 * @integer, blogEntryId
 * @return void
 * @author nicolas
 **/
function toggleHelplineEntry(helplineEntryId)
{
  $('wehc-helplineid-button-'+helplineEntryId).toggleClass('close');
  $("wehc-helplineid-"+helplineEntryId).toggleClass('opened');
  return false;
}
