﻿var _index = null;
function ShowTopStory(index) {
  //Register the menu click with Google Analytics
  if (_index != null) {
    var caseStoryIndex = index + 1;
    trackClick("/casestory/" + caseStoryIndex);
  }

  _index = index;
  $jQuery("#CaseInfoBar").fadeOut("fast", hideTopStoryCallback);
  $jQuery("#TopStoryImage").fadeOut("fast", hideTopStoryCallback);
}

function hideTopStoryCallback() {
  if (topStoryItems[_index] == null)
    return;

  $jQuery(".TopStory .TopBar").css("background-color", topStoryItems[_index].colorValue)

/*
  $jQuery(".LanguageSwitcher .Languages a").css("color", topStoryItems[_index].colorValue).css("background-color", "");
  $jQuery(".LanguageSwitcher .Languages a.Selected").css("background-color", topStoryItems[_index].colorValue)
                                              .css("color", "");
*/
  $jQuery(".TopStory").css("visibility", "visible");
  $jQuery(".TopStory #CaseStoryRepeater a").removeClass("Selected");
  $jQuery(".TopStory #CaseStoryRepeater a").eq(_index).addClass("Selected");
  $jQuery(".TopStory .InnerBox").css("background-color", topStoryItems[_index].colorValue)
  $jQuery(".TopStory .Ornament").css("background-color", topStoryItems[_index].colorValue)
  $jQuery(".TopStory .CaseStripe").css("background-color", topStoryItems[_index].colorValue)
  $jQuery(".TopStory #CaseInfoBar").css("background-color", topStoryItems[_index].colorValue)
  $jQuery(".TopStory .Links").css("color", topStoryItems[_index].colorValue)
  $jQuery(".TopStory #CaseStoryRepeater a").css("border-color", topStoryItems[_index].colorValue).css("color", topStoryItems[_index].colorValue).css("background-color", "");
  $jQuery(".TopStory #CaseStoryRepeater a.Selected").css("background-color", topStoryItems[_index].colorValue)
                                              .css("color", "");

  $jQuery("#CaseInfoBar").html(topStoryItems[_index].caseInfoText + "<a href=\"" + topStoryItems[_index].linkUrl + "\">" + topStoryItems[_index].caseInfoLinkText + "</a>");
  $jQuery("#TopStoryLink").attr("href", topStoryItems[_index].linkUrl);
  $jQuery("#TopStoryImage").attr("src", topStoryItems[_index].imageUrl);
  $jQuery("#TopStoryImage").attr("alt", topStoryItems[_index].altText);

  $jQuery("#CaseInfoBar").fadeIn("slow");
  $jQuery("#TopStoryImage").fadeIn("slow");
  
  $jQuery.cookie('currentTopStoryItem', _index, {path: '/'})
}

$jQuery(document).ready(function () {
  ShowTopStory(currentTopStoryItem);
});
