(function ($) {
  Drupal.behaviors.miss = {
    attach: function(context, settings) {
      // Main Menu Sub-nav
      $('#site-menu-primary ul li.expanded').each(function(){
        var menu = $(this);
        var link = menu.children('a');
        var helper = $('<div/>').addClass('helper');
        helper.css({
          'top': -1,
          'left': -6,
          'width': menu.width() + 6,
          'height': menu.height() + 1
        });
        menu.append(helper);
        menu.css({
          'width': menu.outerWidth(),
          'height': menu.outerHeight(),          
          'padding': 0
        });
        var submenu = menu.find('ul');
        helper.append(link);
        helper.append(submenu);
        helper.mouseenter(function(){
          menu.addClass('hover');
        }).mouseleave(function(){
          menu.removeClass('hover');
        });
        // var submenu = menu.find('ul');
      });
      
      // Avoid FoUC on Quicktabs
      $('.quicktabs-wrapper').show();

      // Add hinting to forms
      
      // Remove our hint on focus
      $('INPUT.hint').focus(function() {
        if($(this).val() == $(this).attr('title')){
          $(this).val('');
          $(this).removeClass('hint');
        }
      });
      
      // Remove our hint if it's still there on submit
      $('form').submit(function() {
        $('INPUT.hint').each(function() {
          if($(this).val() == $(this).attr('title')){
            $(this).val('');
            $(this).removeClass('hint');
          }
        });
      });
      
      // Restore our hint on blur if appropriate
      $('INPUT.hint').blur(function(){
        if($(this).val() == '' && $(this).attr('title') != ''){
          $(this).val($(this).attr('title'));
          $(this).addClass('hint');
        }
      }); 
      
      // Place our hint in desired fields
      $('INPUT.hint').each(function(){
        if($(this).attr('title') == ''){ return; }
          if($(this).val() == ''){ $(this).val($(this).attr('title')); }
          else { $(this).removeClass('hint'); }
      });
      
      // Allow the search block form to be used with just the enter key and no button
      $('form#search-block-form input[type=submit]').hide();
      
      $('form#search-block-form').each(function() {
        $('input').keypress(function(e) {
            // Enter pressed?
            if(e.which == 10 || e.which == 13) {
                this.form.submit();
            }
        });
      });
            
      // On the products page, hovering over thumbnails should send a click to switch the image (simulate a click).
      // Clicking should navigate to the link
      $('#quicktabs-products .attachment-after img').mouseover(function() {
        $(this).click();
      });
      
      $('#quicktabs-products .attachment-after img').mouseup(function() {
        if ($(this).closest('a').attr('href') != '//') {
          window.open($(this).closest('a').attr('href'));
        }
      });
    }
  }
}(jQuery));

;

