$(document).ready(function(){
  // Index page banner
  $(".SlideSwitch").mouseover(function(e){
    $(".SlideSwitchActive").removeClass("SlideSwitchActive");
    $(this).addClass("SlideSwitchActive");
  });

  // Tabs
  $("div.Tabs .TabNav a").click(function () {
    if (!($(this).hasClass("Selected"))) { SwitchTab(this); }
    return false;
  });
  
  $("div.Tabs .TabNav a").filter(":first").click();

  $(".SiteSearch").focusin(function(event) {
    if ($(".SiteSearch").attr("value") == "Поиск по сайту") {
      $(".SiteSearch").css("color","#000");
      $(".SiteSearch").attr("value","")
    }
  });
  
  $(".SiteSearch").focusout(function(event) {
    if ($(".SiteSearch").attr("value") == "") {
      $(".SiteSearch").css("color","#8d8d8d");
      $(".SiteSearch").attr("value","Поиск по сайту");
    }
  });

});

function SwitchTab(oTabItem) {
  var tabContainers = $("div.Tabs > div.Tab");
  
  $("div.Tabs .TabNav a").removeClass("Selected");
  $(oTabItem).addClass("Selected");

  var tabItemWidth = $(oTabItem).outerWidth();
  var tabItemOffset = $(oTabItem).position();


  $(".TabNavItemsSelector").css({
    width: tabItemWidth,
    left: tabItemOffset.left + 15
  });

  tabContainers.hide().filter(oTabItem.hash).show();
}

function SimulateTab(oTabItem) {
  var tabItemWidth = $(oTabItem).outerWidth();
  var tabItemOffset = $(oTabItem).position();

  $(".TabNavItemsSelector").css({
    width: tabItemWidth,
    left: tabItemOffset.left + 15
  });
}

function refreshSpeech() {
  var systemDate = new Date();
  var ajaxURL = "/fcgi-bin/cman/cman.fcgi?module=fortunes;object=fortune;action=get;mode=pub;uniqueid=" + Date.parse(systemDate);
  
  $(".DirectSpeech").fadeOut("fast");
  $(".DirectSpeechLoader").fadeIn("fast");
  
  $(".DirectSpeech").load(
    ajaxURL,
    "",
    function () {
      $(".DirectSpeechLoader").hide();
      $(".DirectSpeech").fadeIn("fast");
    }
  );
}

