/**
 *
 * jQuery for shop/index view
 *
 */

  var ms_show_cat = 300;    // ms = miliseconds
  var ms_hide_cat = 200;

  var hover_div;            // image div being hovered
  var btn_clicked = false;  // button clicked => keep button down

  $(window).bind('load', function () {

    // submenu switching
    $('#submenu a').click( function() {
      this.blur();
      // remove current class
      $("#submenu a").removeClass('current');
      // fadeout current + fadein linked
      var new_cat_id = this.name;
      var link = this;
      $('div.shop_tab:visible').fadeOut(ms_hide_cat, function() {
        $(link).addClass('current');
        $(new_cat_id).fadeIn(ms_show_cat);
      });
      return false;
    });

    // shop button img hover
    $('div.shop_img img').hover(
      function () {
        var $$ = $(this);
        // ENTER
        $$.data("left", "nee");
        $$.stop().animate({ marginTop: "-3px", marginBottom: "3px", marginLeft: "-3px", marginRight: "3px" }, 100, false,
          function () {
            if ($$.data("left") == "ja" && !btn_clicked) {
              $$.animate({ marginTop: "-6px", marginBottom: "6px", marginLeft: "-6px", marginRight: "6px" }, 100);
              $$.data("left", "nee");
            }
          }
        );
      },
      function () {
        var $$ = $(this);
        // LEAVE
        if ($$.is(":animated")) {
          $$.data("left", "ja");
        } else {
          if (!btn_clicked) {
            $$.animate({ marginTop: "-6px", marginBottom: "6px", marginLeft: "-6px", marginRight: "6px" }, 100);
        }
        }
      }
    );

    // shop button click => stop animation
    $('div.shop_button').click( function() {
      btn_clicked = true;
    });

  });