$(document).ready(function() {
  // Изменение картинки и описания на главной странице
  var i = 1;
  var btxt = $('#c_text div').length;
  $('#c_text').children('div').not(':first').hide();
  $('#c_prev').click(function () {
    if(--i < 1) {i = btxt};
    $('#f1_image').removeClass().addClass('bg' + i);
    $('#c_text').children('div:visible').hide();
    $('#c_text').children('div.txt' + i).show();
  })
  $('#c_next').click(function () {
    if(++i > btxt) {i = 1};
    $('#f1_image').removeClass().addClass('bg' + i);
    $('#c_text').children('div:visible').hide();
    $('#c_text').children('div.txt' + i).show();
  })
  
  // Перенос названия категории или товара в h2
  var catname = $('.cat_path span.cat_name').hide().text();
  if(catname != '') {
    $('#lay_body h2:first').text(catname);
    $('.cat_path span.cat_sp:last').hide();
  } else {
    catname = $('h1.item_name').hide().text();
    if(catname != '') { $('#lay_body h2:first').text(catname); }
  }
  
  // Форматирование таблицы (класс tbl)
  $('.tbl th').each(function() {
    $(this).parent().next().children().addClass('ne');
    $(this).parent().prev().children().addClass('pr');
  })
  $('.tbl td:first-child, .tbl th:first-child').css('border-left', '0px solid #fff');
  $('.tbl td:last-child, .tbl th:last-child').css('border-right', '0px solid #fff');

  // Изменение даты
  var j = 0;
  var sdata = '';
  $('.small_news_item_date div').each(function() {
    var sdata = $(this).text();
    while(sdata.indexOf('.') >= 0) {
      j = sdata.indexOf('.');
      sdata = sdata.substring(0, j) + " " + sdata.substring(j+1);
    }
    $(this).text(sdata);
  })
});
