function times() {
  var mydate=new Date();
  var year=mydate.getYear();
  if ( year<200 ) { year=1900+year }
  var day=mydate.getDay();
  var month=mydate.getMonth();
  var daym=mydate.getDate();
  if ( daym<10 )
  daym="0"+daym
  var hour = mydate.getHours();
  if ( hour<10 )
  hour="0"+hour
  var minute = mydate.getMinutes();
  if ( minute<10 )
  minute="0"+minute
  var second = mydate.getSeconds();
  if ( second<10 )
  second="0"+second
  var montharray=new Array("января","февраля","марта","апреля","мая","июня","июля","августа","сентября","октября","ноября","декабря");
  document.getElementById("today").innerHTML = ""+daym+" "+montharray[month]+" "+year+" "+hour+":"+minute+":"+second+"";
  setTimeout("times()",1000);
}

jQuery(window).load(function()
{
  // Вызываем текущие дату и время
  times();
  //rotate_news();

  // Вкл./Выкл. значение по умолчание дял поля поиска
  jQuery("#header #logo_search #search #search_feild input").focus(function () { if (jQuery(this).val() == "Что ищем?") { jQuery(this).val(""); } });
  jQuery("#header #logo_search #search #search_feild input").blur(function() { if (jQuery(this).val() == "") { jQuery(this).val("Что ищем?"); } });

  jQuery(".slider a.prev").click(function() {
    var top = "";

    // Получаем высоту блока с учетом отступов
    var outerHeight = jQuery(".container:not(.hidden) .item").outerHeight(true);

    // Считаем кол-во блоков
    var count_item = jQuery(".container:not(.hidden) .item").length;

    // Получаем общую высоту всех блоков (максимальная высота)
    var full_height = (outerHeight * count_item);

    // Текущее смещение
    var this_top = jQuery(".container:not(.hidden) .item").css("top");

    // Тулевой отступ
    var min_top = "0px";
    var max_top = "-" + (full_height-outerHeight) + "px";

    if (this_top >= min_top)
    {
      top = max_top;
    }
    else
    {
      top = outerHeight;
    }

    jQuery(".container:not(.hidden) .item").animate({"top": "+="+top}, 500);

    return false;
  });

  jQuery(".slider a.next").click(function() {
    var top = "";
    var outerHeight = jQuery(".container:not(.hidden) .item").outerHeight(true);
    var count_item = jQuery(".container:not(.hidden) .item").length;
    var full_height = (outerHeight * count_item);
    var this_top = jQuery(".container:not(.hidden) .item").css("top");
    var min_top = "0px";
    var max_top = "-" + (full_height-outerHeight) + "px";

    if (this_top != max_top)
    {
      jQuery(".container:not(.hidden) .item").animate({"top": "-="+outerHeight}, 500);
    }
    else
    {
      jQuery(".container:not(.hidden) .item").animate({"top": "0px"}, 500);
    }

    return false;
  });

  /*
  * Переключение вкладок новостей на главной странице
  */
  jQuery("body #mainContent div.maincontent_block_header div.maincontent_block_header_wrap div.maincontent_block_header_center ul.maincontent_block_header_tabs li:gt(0)").live("click", function() {
    var active_tab = jQuery(this).attr("class");
    var count_tabs = jQuery(this).parent().children().length;
    var count_tabs_content = jQuery(this).parent().parent().parent().parent().next().children().length;

    var i = "";
    for(i = 0; i <= count_tabs; i++)
    {
      jQuery("body #mainContent div.maincontent_block_header div.maincontent_block_header_wrap div.maincontent_block_header_center ul.maincontent_block_header_tabs li").eq(i).removeClass('active');
    }

    if (!jQuery(this).hasClass('active'))
    {
      jQuery(this).addClass('active');
    }

    var k = "";
    for(k = 0; k <= count_tabs_content; k++)
    {
      jQuery(this).parent().parent().parent().parent().next().children().eq(k).addClass('hidden');
    }

    jQuery("body #mainContent div.maincontent_block_header div.maincontent_block_header_wrap div.maincontent_block_header_center ul.maincontent_block_header_tabs li").parent().parent().parent().parent().next().find('#'+active_tab).removeClass('hidden');
  });

  jQuery(".config_news_block_wrap .config_news_block_button").live("click", function() {
    jQuery(this).parent().next().slideToggle("fast");
  });

  // Добавляем еще одну последнюю новость
  jQuery("#top_news .config_news_buttons .config_news_block_centerbg li.add_news_button").live("click", function() {
    var last_news_id = jQuery("#last_news ul li:last").attr('id');

    jQuery.post("/news/ajax/", 'operation=add_last_news&last_news_id=' + last_news_id,
      function(data){
        jQuery("#last_news ul").append(data);
      }
    );
  });

  // Удаляем одну последнюю новость
  jQuery("#top_news .config_news_buttons .config_news_block_centerbg li.del_news_button").live("click", function() {
    var count_last_news = jQuery("#last_news ul li").length;
    if (count_last_news > 10)
    {
      jQuery("#last_news ul li:last").remove();
    }
  });

  // Перезагрузка последних новостей
  jQuery("#top_news .config_news_buttons .config_news_block_centerbg li.reload_news_button").live("click", function() {
    jQuery.post("/news/ajax/", 'operation=reload_last_news',
      function(data){
        jQuery("#last_news ul").html(data);
      }
    );
  });

  // Добавляем одну последнюю новость в выбранной категории
  jQuery("div.cat_news_block_left .config_news_buttons .config_news_block_centerbg li.add_news_button, div.cat_news_block_right .config_news_buttons .config_news_block_centerbg li.add_news_button, div.cat_news_block_center .config_news_buttons .config_news_block_centerbg li.add_news_button").live("click", function() {
    var self = jQuery(this);
    var last_cat_news_id = self.parent().parent().parent().next().children().last().attr('id');
    var last_cat_news_subid = self.parent().parent().parent().next().children().last().attr('index');

    jQuery.post("/news/ajax/", 'operation=add_last_cat_news&last_cat_news_subid=' + last_cat_news_subid +'&last_cat_news_id=' + last_cat_news_id,
      function(data){
        self.parent().parent().parent().next().append(data);
      }
    );
  });

  // Удаляем одну последнюю новость в выбранной категории
  jQuery("div.cat_news_block_left .config_news_buttons .config_news_block_centerbg li.del_news_button, div.cat_news_block_right .config_news_buttons .config_news_block_centerbg li.del_news_button, div.cat_news_block_center .config_news_buttons .config_news_block_centerbg li.del_news_button").live("click", function() {
    var self = jQuery(this);
    var count_last_cat_news = self.parent().parent().parent().next().children().length;
    if (count_last_cat_news > 3)
    {
      self.parent().parent().parent().next().children().last().remove();
    }
  });

  // Перезагружаем новости в выбранной категории
  jQuery("div.cat_news_block_left .config_news_buttons .config_news_block_centerbg li.reload_news_button, div.cat_news_block_right .config_news_buttons .config_news_block_centerbg li.reload_news_button, div.cat_news_block_center .config_news_buttons .config_news_block_centerbg li.reload_news_button").live("click", function() {
    var self = jQuery(this);
    var last_cat_news_subid = self.parent().parent().parent().next().children().last().attr('index');

    jQuery.post("/news/ajax/", 'operation=reload_last_cat_news&last_cat_news_subid=' + last_cat_news_subid,
      function(data){
        self.parent().parent().parent().next().html(data);
      }
    );
  });

  // Добавляем "новость по теме"
  jQuery("#full_news .config_news_buttons .config_news_block_centerbg li.add_news_button").live("click", function() {
    var self = jQuery(this);
    var last_cat_news_id = self.parent().parent().parent().next().find("#last_news ul li:last").attr('id');
    var last_cat_news_subid = self.parent().parent().parent().next().find("#last_news ul li:last").attr('index');

    jQuery.post("/news/ajax/", 'operation=add_last_else_news&last_cat_news_subid=' + last_cat_news_subid +'&last_cat_news_id=' + last_cat_news_id,
      function(data){
        self.parent().parent().parent().next().find("#last_news ul").append(data);
      }
    );    
  });
  
  // Удаляем "новость по теме"
  jQuery("#full_news .config_news_buttons .config_news_block_centerbg li.del_news_button").live("click", function() {
    var self = jQuery(this);
    var count_last_news = self.parent().parent().parent().next().find("#last_news ul li").length;
    if (count_last_news > 3)
    {
      self.parent().parent().parent().next().find("#last_news ul li:last").remove();
    }
  });

  // Перезагрузка "новостей по теме"
  jQuery("#full_news .config_news_buttons .config_news_block_centerbg li.reload_news_button").live("click", function() {
    var self = jQuery(this);
    var this_news_id = self.parent().parent().parent().next().children().eq(1).attr('index');
    var last_cat_news_subid = self.parent().parent().parent().next().find("#last_news ul li:last").attr('index');

    jQuery.post("/news/ajax/", 'operation=reload_last_else_news&last_cat_news_subid=' + last_cat_news_subid + '&this_news_id=' +this_news_id,
      function(data){
        self.parent().parent().parent().next().find("#last_news ul").html(data);
      }
    );
  });

  // Отображение/скрытие подсказок в форме регистрации
  jQuery("#registration .help_small").live("click", function() {
    jQuery(this).parent().next().next().next().slideToggle(1000);
  });

  // Переключение вкладок в аккаунте
  jQuery("#mainContent #registration #acount_tab li").live("click", function() {
    var active_tab = jQuery(this).attr("class");
    var count_tabs = jQuery(this).parent().children().length;
    var count_tabs_content = jQuery(this).parent().parent().next().children().length;

    var i = "";
    for(i = 0; i <= count_tabs; i++)
    {
      jQuery("#mainContent #registration #acount_tab li").eq(i).removeClass('active');
    }

    if (!jQuery(this).hasClass('active'))
    {
      jQuery(this).addClass('active');
    }

    var k = "";
    for(k = 0; k <= count_tabs_content; k++)
    {
      jQuery(this).parent().parent().next().children().eq(k).addClass('hidden');
    }

    jQuery("#mainContent #registration #acount_tab li").parent().parent().next().find('#'+active_tab).removeClass('hidden');
  });
});
