var Category = {
  init: function() {
    this._setup();
  },

  _setup: function() {
    var count = 1;

    if(document.getElementById('category_title')) {
      var title_key = $('#category_title').html() 
      $('#category_title').html(Menu.getTitle($.trim(title_key)));
    }

    $('.category_product').each(function() {

      $(this).hover(function() {
        $(this).addClass('hover');
      }, function() {
        $(this).removeClass('hover');
      });

      if ((count == 2) || (count == 3))
      {
        $(this).addClass('dark');
      } else if(count == 4) {
        count = 0;
      }

      $('#category_product_block').append($(this));

      count++;
    }); 

    $('#category_product_block').find('a').each(function() {
      $(this).click(function(e) {
        e.preventDefault();
        GaspareStore._loadPopup(GsProduct, $(this).attr('href'));
        return false;
      });
    });
    
    $('#category_product_block .category_product > a').each(function() {
      var old_image = $(this);
      var link = $(this).attr("href");
      var content = "";
      jQuery.ajax({
        url: link,
        type: "post",
        success: function(data) {
         var original_image = old_image.find('img');
         var original_image_src = original_image.attr('src');
         var new_image = $(data).find(".hover_images img:eq(0)").attr("src");
         old_image.hover(
            function(){
              original_image.attr('src', new_image);
            },
            function() {
              original_image.attr('src', original_image_src);
            }
         )
         
         
        }
      });
    });
  }
};

