$(document).ready(function() {

  // Handle external links (new window)
  $('a[href^="http://"][class!=nopopup]').each(function() {
    $(this).attr('title', $(this).attr('title') + ' (opens in a new window)');
  }).click(function(evt) {
    evt.preventDefault();
    window.open($(this).attr('href'));
  });

  // Handle popups
  $('a.popup').click(function(evt) {
    evt.preventDefault();
    window.open($(this).attr('href'), 'popup', 'width=500, height=400, scrollbars=1');
  });

  // Enable tooltips on policy tables
  $('body.policy td.tooltip').tooltip({
    bodyHandler: function() {
      return '<h3>' + $(this).html() + '</h3>'
           + '<div class="body">' + this.tooltipText + '</div>';
    }
  });

  // Stripe tables
  $('table.stripe tbody tr:odd').addClass('alt');

  //lightbox overlay
  var lightBoxConfig = {
          'overlayShow'     : true,
          'overlayOpacity'  : 0.4,
          'zoomSpeedIn'     : 500,
          'zoomSpeedOut'    : 50,
          'easingIn'        : 'easeOutBack',
          'easingOut'       : 'easeInBack'
      };

  var overlayError = function(error, domElement) {
      if (jQuery.browser['mozilla']) {
          console.warn(error, domElement);
      }
  };

  $('a.mb').each(function(i){
    $(this).attr('href', $(this).attr('href') + '?format=html');

    $(this).fancybox({
      'hideOnContentClick'	: false 
    });

  });
  
  $('#blurb-container > div').removeClass('hide');
  $('#blurb-container').cycle({
    speed:      1000,
    timeout:    10000,
    pager:      '#blurb',
    pagerEvent: 'mouseover',
    pauseOnPagerHover: true,
    pagerAnchorBuilder: function(idx, slide) {
        return '#blurb li:eq(' + (idx) + ') a';
    }
  });
  $('#product-banner-container > div').removeClass('hide');

  $('#product-banner-container').cycle({
      speed:      1000,
      timeout:    10000,
      pager:      '#product-banner',
      pagerEvent: 'mouseover',
      pauseOnPagerHover: true,
      pagerAnchorBuilder: function(idx, slide) {
          return '#product-banner li:eq(' + (idx) + ') a';
      }
  });

  $('#promotional-banner-container > div').removeClass('hide');
  $('#promotional-banner-container').cycle({
      speed:      1000,
      timeout:    10000,
      pager:      '#promotional',
      pagerEvent: 'mouseover',
      pauseOnPagerHover: true,
      pagerAnchorBuilder: function(idx, slide) {
          return '#promotional li:eq(' + (idx) + ') a';
      }
  });

});

