$.noConflict();


jQuery(document).ready(function($){

  // Product Grid Detail Popup
  var $products_grid  = $('.products-grid'),
      animation_speed = 150,
      delay_time      = 400;

  if ($products_grid.find('.prodPopup').length > 0)
  {
    // FadeOUT on mouseLEAVE
    $products_grid.delegate('li', 'mouseleave', function(e){
      $(e.currentTarget).find('.prodPopup').fadeOut(animation_speed);
    });

    // FadeIN on mouseENTER
    $products_grid.delegate('li', 'mouseenter', function(e){
      var $target = $(e.currentTarget),
          $popup  = $target.find('.prodPopup');

      var container_top_right_coordinate = $products_grid.offset().left + $products_grid.outerWidth(true),
              popup_top_right_coordinate = $target.offset().left + $target.outerWidth(true) + $popup.outerWidth(true) - 1;

      // -------------------------------------------------
      // Display the popup on the left side if there isn't
      // enough room within the container to display it
      // -------------------------------------------------
      if ( popup_top_right_coordinate > container_top_right_coordinate )
      {
        $popup.css({
          'left': '-' + ($popup.outerWidth(true) - $popup.css('border-right')) + 'px',
          'border-width': '1px 0 1px 1px'
        });
      }

      // Display the popup
      $popup
        .stop(true, true)
        .delay(delay_time)
        .fadeIn(animation_speed);
    });
  }


  // ------------------------------
  // Form Input Placeholder
  // ------------------------------
  if (!Modernizr.inputtypes.email)
    {
      $('input[placeholder], textarea[placeholder]').each(function(i, input){
        var $input = $(input);

        // Initially load the placeholder value
        if ($input.val() == '') { $input.val($input.attr('placeholder')); }

        $input
          .bind('focusin', function(){
            var $this = $(this);
            if ($this.val() == $input.attr('placeholder')) { $this.val(''); }
          })
          .bind('focusout', function(){
            var $this = $(this);
            if ($this.val() == '') { $this.val($input.attr('placeholder')); }
          });
      });
    }

  $('#show_mini_search_form').click(function(e){
    e.preventDefault();
    $('#search_mini_form .form-search').fadeToggle();
  });

  $('#show_newsletter_form').click(function(e){
    e.preventDefault();
    $('#newsletter_form').fadeToggle();
  });

});

