$(document).ready(function(){
  /*$('.goGreen').hover(
    function(){
      $(this).css('background','url(/goGreenHover.gif) no-repeat');
    },
    function(){
      $(this).css('background','url(/goGreen.gif) no-repeat');
    }
  );
  */
  $('#jsddm>li>a').hover(
    function(){
      $(this).addClass('hover');
      $(this).prev().animate(
        {
          top:'5px',
          height:'32px'
        }
      )
    },
    function(){
      $(this).prev().animate(
        {
          top:'40px',
          height:'0px'
        },
        function(){
          $(this).next().removeClass('hover');
        }
      )
    }
  );
  
  var currentProductButton = null;
  $('.mainProduct').hover(
    function(){
      $(this).find('.productImage').hide();
      currentProductButton = $(this).find('.productHoverImage')[0];
      $(this).find('.productHoverImage').show().animate(
        {
          width:'170px',
          height:'137px',
          top:'-3px',
          left:'-3px'
        },
        100,
        function(){
          if(this != currentProductButton){
            shrinkProductButton(this);
            return;
          }
          $(this).animate(
            {
              width:'162px',
              height:'129px',
              top:'2px',
              left:'2px'
            },
            100,          
            function(){
              if(this != currentProductButton){
                shrinkProductButton(this);
                return;
              }
              $(this).animate(
                {
                  width:'164px',
                  height:'131px',
                  top:'0px',
                  left:'0px'
                },
                100
             );
            }
          );
        }
      );
    },
 
    function(){
      currentProductButton = null;
      shrinkProductButton(this);
    }
  );
  
  function shrinkProductButton(e){
     $(e).find('.productHoverImage').animate(
        {
          width:'131px',
          height:'106px',
          top:'12px',
          left:'16px'
        },
        100,
        function(){
          $(this).prev().show();
          $(this).hide()
        }
      );
   }
});