/*--- 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'});
};

/*--- equal columns heights ---*/
Drupal.behaviors.forDrupalEqualHeights = function(context) {
  // with minimum height 50, no maximum height
  $('.center-content .block .content').equalHeights(50);
  $('.bottom-content .block .content').equalHeights(50);
  $('.footer-top-1, .footer-top-2, .footer-top-3, .footer-top-4').equalHeights(50);
};


/*--- welcome close button ---*/
Drupal.behaviors.forDrupalWelcomeClose = function(context) {
  $('.welcome .close').click(
    function() {
      $('.welcome').fadeOut('slow');
      $('.welcome').next('div.spacer').hide();
      $.cookie('platino_hidewelcome', '1', { expires: 1 });  // set cookie with an expiration date 1 day in the future
    }
  );
};


/*--- description as tooltip ---*/
Drupal.behaviors.forDrupalTooltips = function(context) {
  // check if it is enabled
  if (Drupal.settings.fordrupal && Drupal.settings.fordrupal.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:      "#73a9d7",                  // color/alpha of stroke
      fill:             'rgba(92, 92, 92, .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.form-text').bt($.extend(btstyles, {
      contentSelector:  "$(this).attr('title')"
    }));
  };
};

$(function() {
  if ($.cookie('platino_hidewelcome') == '1') {
    $('.welcome').hide();
    $('.welcome').next('div.spacer').hide();
  }
});
