/*--- superfish menu ---*/
Drupal.behaviors.forDrupalMenu = function(context) {
  $('ul.sf-menu').superfish({
    dropShadows:  false,
    delay:        400,
    animation:    {opacity:'show',height:'show',width:'show'},
    speed:        'fast',
    onShow:        function(){ $(this).siblings('a.sf-with-ul').addClass('aHover')},
    onHide:        function(){ $(this).siblings('a.sf-with-ul').removeClass('aHover')}
  }).find('ul').bgIframe({opacity:'false'});
};

/*--- top tab panel ---*/
Drupal.behaviors.forDrupalTabPanel = function(context) {
  // top panel tab effect
  $('.toppanel-tab').click(function() {
    $('.toppanel-container').slideToggle();
  });

  // top panel close button
  $('.close-button').click(function() {
    $('.toppanel-tab').trigger('click');
  });
};

/*--- description as tooltip ---*/
Drupal.behaviors.forDrupalTooltips = function(context) {
  // check if it is enabled
  if (Drupal.settings.zincout && Drupal.settings.zincout.description_as_tooltip) {
    // hide all form description
    //  $('form .form-item .description').hide();   // does not work for those under fieldset which are collapsed
    $('form .form-item .description').css('display', 'none');
    
    // collapsible fieldset will not work under tooltips, move it out so it is still usable like Token
    $('form .form-item .description fieldset').each(function() {
      var p = $(this).parents('.form-item');
      $(this).appendTo(p);
      p.find('.description fieldset').remove();
    });

    var btstyles = {
      trigger:          'hoverIntent',  // trigger to show/hide tip
      positions:        ['top', 'bottom', 'right', 'left'],    // preference of positions for tip (will use first with available space)
      contentSelector:  "$(this).find('.description').html()",
      closeWhenOthersOpen: true,                 // tip will be closed before another opens - stop >= 2 tips being on
      hoverIntentOpts:  { interval: 200, timeout: 300 },  // options for hoverIntent
      strokeWidth:      1,                       // width of stroke around box
      strokeStyle:      "#fff",                  // color/alpha of stroke
      fill:             'rgba(39, 51, 58, .8)',  // fill color for the tooltip box
      cssStyles:        {color: '#fff'},         // styles to add the text box
      width:            '250px',                 // width of tooltip box
      centerPointX:     .7,                      // the spike extends from center of the target edge to this point
      centerPointY:     .7,                      // defined by percentage horizontal (x) and vertical (y)
      spikeLength:      25,                      // length of spike
      spikeGirth:       25                       // width of spike
    };
    
    // only those with description will be added the tooltip
    $('.form-item .description').parent('.form-item').bt(btstyles);
    
    // tooltips for search box
    $('.search-box input').bt($.extend(btstyles, {
      contentSelector:  "$(this).attr('title')"
    }));
  };
};
