function initDocumentStructure ()
{
    var body = jQuery('body');
    var docWidth = jQuery(window).width();

    body.removeClass('resize_site');
    body.removeClass('resize_big_site');
    if (docWidth <= 1250){
      body.addClass('resize_site');
    }
    if (docWidth > 1400){
      body.addClass('resize_big_site');
    }
}

function buildForIE ()
{
  selectorsLastChild = '.flashbox li:last-child, #menu_block ul:last-child, .table tr:last-child, .table tr td:last-child';
  jQuery(selectorsLastChild).addClass('last-child');

  selectorsFirstChild = '.table tr:first-child';
  jQuery(selectorsFirstChild).addClass('first-child');
}

function animateMenu(elementMenu)
{
  var speed_menu = '10';
  var animateElementMenu = jQuery(elementMenu).addClass('active').parent('dt').next('dd');
  var animateElementChild = jQuery(elementMenu).parent('li').children('ul');
  var displayElementMenu = animateElementMenu.addClass('active').css('display');
  var displayElementChild = animateElementChild.css('display');
  if(displayElementMenu =='none') {
    jQuery(animateElementMenu).show();
  }
  else {
    jQuery(animateElementMenu).hide();
    jQuery(elementMenu).removeClass('active');
  }

  if(displayElementChild =='none') {
    jQuery(animateElementChild).slideDown(speed_menu);
    jQuery(elementMenu).addClass('active');
  }
  else {
    jQuery(animateElementChild).slideUp(speed_menu);
  }
}

function scrollablePhoto(width_scroll){
  jQuery(".scrollable").scrollable({
    size: width_scroll
  }).mousewheel();
}

function scrollableWidth(size_block){
  jQuery('.scrollable_block .items').each(function(){
    var image_width = jQuery(this).children('li').outerWidth(true);
    var amount_elemaents = jQuery(this).children('li').size();
    jQuery(this).css('width', image_width*amount_elemaents);
    if (amount_elemaents <= size_block)
      jQuery(this).parents('.scrollable_block').children('.next').addClass('disabled');
  });
}

jQuery(document).ready(function()
{
  initDocumentStructure();
  if(!jQuery.browser.msie)
    jQuery(window).resize(initDocumentStructure);
  else
    window.onresize = function(){initDocumentStructure();}

  if(jQuery.browser.msie)
    buildForIE();

  jQuery('#menu_production a.parent').click(function(){animateMenu(this);return false;});

  jQuery('.checkbox_block input[type="checkbox"]:checked').each(function(){
      var parent = jQuery(this).parent();
      jQuery(parent).addClass('checked_checkbox');
      jQuery(parent).children('span').addClass('checked_checkbox');
  });

  jQuery('.checkbox_block').click(function(){
     jQuery(this).toggleClass('checked_checkbox');
  });

  jQuery('.checkbox_block span').click(function(){
     jQuery(this).parents('.checkbox_block').toggleClass('checked_checkbox');
  });

  jQuery('.radio_block input[type="radio"]:checked').each(function(){
      var parent = jQuery(this).parent();
      jQuery(parent).addClass('checked');
      jQuery(parent).children('span').addClass('checked');

      if(jQuery(this).val() == 1)
        jQuery('#adr_req').show();
  });

  jQuery('.radio_block').click(function(){
      jQuery('.radio_block').removeClass('checked');
      jQuery(this).addClass('checked');
  });

  jQuery('.products_block').each(function(){
    jQuery(this).children('.product').eq(2).addClass('penultimate');
    jQuery(this).children('.product').eq(3).addClass('hidden');
  });

   jQuery('.table th:first-child, .table1 th:first-child').wrapInner('<div class="info"></div>').addClass('first-child');
   jQuery('.table th:last-child, .table1 th:last-child').wrapInner('<div class="info"></div>').addClass('last-child');
   jQuery('<span class="corner_t_l"></span><span class="corner_b_l"></span>').appendTo('.table th.first-child .info, .table1 th.first-child .info');
   jQuery('<span class="corner_t_r"></span><span class="corner_b_r"></span>').appendTo('.table th.last-child .info, .table1 th.last-child .info');

  jQuery('#catalogue .catalogue_product a, .product a, #partners a').hover(function(){
    jQuery(this).parent().addClass('active_elem');
    },function(){
    jQuery(this).parent().removeClass('active_elem');
  });

  if((jQuery.browser.msie && jQuery.browser.version != 6) || !jQuery.browser.msie) {
    var elements_with_corners = jQuery('h1, .price_product div, .info_block, .title, #cart, .add_title');
    jQuery(elements_with_corners).addClass('info');
    jQuery('<span class="corner_t_l"></span><span class="corner_t_r"></span><span class="corner_b_l"></span><span class="corner_b_r"></span>').appendTo(elements_with_corners);
  }

  jQuery(".original").fancybox(
  {
    hideOnContentClick: true,
    overlayOpacity: 0.67,
    padding: 0,
    autoScale: false,
    centerOnScroll: false
  });

  var body = jQuery('body');
  var docWidth = jQuery(window).width();
  var min_size_scrollable = 3;
  var max_size_scrollable = 5;

  if (docWidth <= 1250){
    scrollablePhoto(min_size_scrollable);
    scrollableWidth(min_size_scrollable);
  }
  if (docWidth > 1250){
    scrollablePhoto(max_size_scrollable);
    scrollableWidth(max_size_scrollable);
  }

  jQuery('#catalogue .catalogue_product').each(function(i){
    i = i+1;
    var ostatok = i/3 + '';
    if (ostatok.indexOf('.') == -1)
      jQuery(this).addClass('last-child');
  });

});

