(function($) {
// divides children of a div into a number of columns;
// potentially grid-aware; can have a parsing callback
$.fn.energyColumns = function(options) {

  if (!this.length) { return this; }

  var opts = $.extend(true, {}, $.fn.energyColumns.defaults, options);

  
  this.each(function() {
    var $this = $(this),
      children = $this.children(),
      length = children.length,
      width = $this.outerWidth(),
      columnCount = 1,
      calculatedColumns = (length < opts.columns) ? length : opts.columns,
      border = opts.border,
      totalGutter = border ? 
        (parseInt(opts.gutter, 10)) * (calculatedColumns * 2 - 2) + (calculatedColumns - 1): 
        (parseInt(opts.gutter, 10)) * (calculatedColumns * 2 - 2),
      columnWidth = Math.floor((width - totalGutter)/calculatedColumns),
      itemsPerCol = Math.ceil(length / calculatedColumns),
      totalCols = Math.ceil(length / itemsPerCol),
      // this is where we get the array of how the items are split up
      itemDivision = opts.parseCallback.apply($this, [opts]);
    // save the unaltered markup and then mark it with a processed class
    // we're going to assume we're taking care of all css ourselves
    $this.data({
      originalMarkup : $this.html()
    }).addClass('energy-columns').css({
      'overflow' : 'hidden'
    });
    for (var i = 0; i < calculatedColumns; i++) {
      // create element
      var columnElement = $('<div />', {
        'class': 'energy-column energy-column-' + columnCount,
      }).css({
        float : 'left',
        padding: '0 ' + opts.gutter,
        width: columnWidth
      });
      if (columnCount == 1) {
        columnElement.css('padding-left', '0');
      }
      if (columnCount == calculatedColumns) {
        columnElement.css('padding-right', 0);
      }
      if (border && columnCount != 1) {
        columnElement.css('border-left', '1px dotted #acacac');
      }
      children.slice(itemDivision[i],itemDivision[i+1]).appendTo(columnElement);
      columnElement.appendTo($this);
      columnCount++;
    }
  });

  return this;
};

// this callback takes the div's children, divides them equally, and returns an array with the slice locations
var defaultParseCallback = function(opts) {
  $this = $(this);
  var remainingItems = $this.children().length,
    sliceLocs = [0],
    sliceIndex = 0,
    remainingCols = opts.columns;
  while (remainingItems > 0) {
    var sliceSize = Math.ceil(remainingItems / remainingCols);
    remainingItems = remainingItems - sliceSize;
    sliceIndex = sliceIndex + sliceSize;
    sliceLocs.push(sliceIndex);
    remainingCols--;
  }
  return sliceLocs;
};

$.fn.energyColumns.defaults = {
  columns : 3,
  gutter : '10px',
  parseCallback: defaultParseCallback,
  border: false
};

})(jQuery);

;
(function ($) {
  $(document).ready(function() {
    var nav = $('.block-energy-core-navigation-main').find('ul').first();
    nav.children('li').has('ul').hoverIntent(function() {
      $(this).children('ul').hide().css('top', '100%').fadeIn(100);
    }, function() {
      $(this).children('ul').fadeOut(100, function() {
        $(this).css('top', '-9999px');
      });
    })
    .children('ul').each(function() {
      var width = 0,
        containers = $(this).children('li');
      for (var i=0;i<containers.length;i++) {
        width += containers.eq(i).outerWidth(true);
      }
      width = width > 925 ? 925 : width;
      $(this).css('width', width);
    }).energyColumns({columns: 5});
    var offices = $('.block-energy-core-navigation-main .secondary-nav li.last.leaf').append($('.office-flyout')).hoverIntent(function() {
      $(this).children('.office-flyout').fadeIn(100);
    },
    function () {
      $(this).children('.office-flyout').fadeOut(100);
    });
    // attach the slideDown
    $('#header .energy-location-widget, #sidebar-right .energy-location-widget:not(.no-zip)').hoverIntent(function() {
      $('.energy-location-form', this).slideDown();
    }, function() {
      $('.energy-location-form', this).slideUp();      
    });

  });
})(jQuery);
;
/* stolen shamelessly, minor modifications:
http://stackoverflow.com/questions/1216114/how-can-i-make-a-div-stick-to-the-top-of-the-screen-once-its-been-scrolled-to */

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

  (function moveScroller() {
    var a = function() {
      var b = $(window).scrollTop(),
        c = $("#sticky-header"),
        d = $("#sticky-header-anchor"),
        e = d.offset().top;
      if (b>e) {
        d.css({height:c.outerHeight()});
        c.css({position:"fixed",top:"0px"});
      } else {
        if (b<=e) {
          d.css({height:'auto'});
          c.css({position:"relative",top:""});
        }
      }
    };
    $(window).scroll(a);a();
  })();
  if (Drupal.settings.energy_content && (!Drupal.settings.energy_content.isFront || !Drupal.settings.energy_content.toggle_tophero_frontpage)) {
    var offset = $("#sticky-header").offset().top;
    $(window).scrollTop(offset);
  }
});
})(jQuery);;
/*! http://mths.be/placeholder v1.8.5 by @mathias */
;(function(window, document, $) {

	var isInputSupported = 'placeholder' in document.createElement('input'),
	    isTextareaSupported = 'placeholder' in document.createElement('textarea');

	if (isInputSupported && isTextareaSupported) {

		$.fn.placeholder = function() {
			return this;
		};

		$.fn.placeholder.input = $.fn.placeholder.textarea = true;

	} else {

		$.fn.placeholder = function() {
			return this.filter((isInputSupported ? 'textarea' : ':input') + '[placeholder]')
				.bind('focus.placeholder', clearPlaceholder)
				.bind('blur.placeholder', setPlaceholder)
				.trigger('blur.placeholder').end();
		};

		$.fn.placeholder.input = isInputSupported;
		$.fn.placeholder.textarea = isTextareaSupported;

		$(function() {
			// Look for forms
			$('form').bind('submit.placeholder', function() {
				// Clear the placeholder values so they don’t get submitted
				var $inputs = $('.placeholder', this).each(clearPlaceholder);
				setTimeout(function() {
					$inputs.each(setPlaceholder);
				}, 10);
			});
		});

		// Clear placeholder values upon page reload
		$(window).bind('unload.placeholder', function() {
			$('.placeholder').val('');
		});

	}

	function args(elem) {
		// Return an object of element attributes
		var newAttrs = {},
		    rinlinejQuery = /^jQuery\d+$/;
		$.each(elem.attributes, function(i, attr) {
			if (attr.specified && !rinlinejQuery.test(attr.name)) {
				newAttrs[attr.name] = attr.value;
			}
		});
		return newAttrs;
	}

	function clearPlaceholder() {
		var $input = $(this);
		if ($input.val() === $input.attr('placeholder') && $input.hasClass('placeholder')) {
			if ($input.data('placeholder-password')) {
				$input.hide().next().show().focus().attr('id', $input.removeAttr('id').data('placeholder-id'));
			} else {
				$input.val('').removeClass('placeholder');
			}
		}
	}

	function setPlaceholder() {
		var $replacement,
		    $input = $(this),
		    $origInput = $input,
		    id = this.id;
		if ($input.val() === '') {
			if ($input.is(':password')) {
				if (!$input.data('placeholder-textinput')) {
					try {
						$replacement = $input.clone().attr({ 'type': 'text' });
					} catch(e) {
						$replacement = $('<input>').attr($.extend(args(this), { 'type': 'text' }));
					}
					$replacement
						.removeAttr('name')
						// We could just use the `.data(obj)` syntax here, but that wouldn’t work in pre-1.4.3 jQueries
						.data('placeholder-password', true)
						.data('placeholder-id', id)
						.bind('focus.placeholder', clearPlaceholder);
					$input
						.data('placeholder-textinput', $replacement)
						.data('placeholder-id', id)
						.before($replacement);
				}
				$input = $input.removeAttr('id').hide().prev().attr('id', id).show();
			}
			$input.addClass('placeholder').val($input.attr('placeholder'));
		} else {
			$input.removeClass('placeholder');
		}
	}

}(this, document, jQuery));;
/**
  pxToEm and equalHeights plugins courtesy Filament Group
  http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/
  http://www.filamentgroup.com/lab/setting_equal_heights_with_jquery/
**/

(function($){ 

  Number.prototype.pxToEm = String.prototype.pxToEm = function(settings){
    //set defaults
    settings = jQuery.extend({
      scope: 'body',
      reverse: false
    }, settings);

    var pxVal = (this === '') ? 0 : parseFloat(this);
    var scopeVal;
    var getWindowWidth = function(){
      var de = document.documentElement;
      return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
    };  

    if (settings.scope == 'body' && $.browser.msie && (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(1) > 0.0) {
      var calcFontSize = function(){    
        return (parseFloat($('body').css('font-size'))/getWindowWidth()).toFixed(3) * 16;
      };
      scopeVal = calcFontSize();
    }
    else { scopeVal = parseFloat(jQuery(settings.scope).css("font-size")); }

    var result = (settings.reverse === true) ? (pxVal * scopeVal).toFixed(2) + 'px' : (pxVal / scopeVal).toFixed(2) + 'em';
    return result;
  };
  
  $.fn.equalHeights = function(px, notSelector) {
    notSelector = notSelector || 'NOSELECTOR';
    $(this).each(function(){
      var currentTallest = 0;
      $(this).children().not(notSelector).each(function(i){
        if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
      });
      if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
      // for ie6, set height since min-height isn't supported
      if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
      $(this).children().not(notSelector).css({'min-height': currentTallest}); 
    });
    return this;
  };
  
  $(document).ready(function() {
    // do this case-by-case until we can generalize properly.
//    $('.column-row:has(>.column)').equalHeights();     
    $('.group_homepage_block_row.column-row').equalHeights();     
  });
  
})(jQuery);
;
(function($) {
  $(document).ready(function() {
    // stripe table rows
    $('table tbody, table:not(:has(thead))').each(function() {
      $(this).children('tr').each(function(i) {
        $(this).addClass((i+1)%2 == 1 ? 'tr-odd' : 'tr-even');
      });
    });
    $('.field-name-field-landing-3col-blocks-ll .field-items').energyColumns();
    $('.list-columns-2').energyColumns({
     'columns' : 2,
     'gutter' : '5px'
    });
    // attach placeholder shim
    $('input, textarea').placeholder();
    // adjust 3col landing lead blocks
    $('.field-name-field-landing-3col-blocks-lead .field-items').equalHeights();
    // content promotion bean pager
    $('.bean-content-promotion').not('.bean-content-promotion-processed').each(function() {
      $(this).addClass('bean-content-promotion-processed');
      var id = $(this).attr('id'), items_per_page;
      if (Drupal.settings.energy_beans && Drupal.settings.energy_beans[id]) {
        items_per_page = Drupal.settings.energy_beans[id].items_per_page;
      }
      else {
        items_per_page = 6;
      }
      $(this).children('.content').itemPager({
        pagerNumber: items_per_page,
        linkToAll: false,
        showPrevNext: true
      });
    });
    // columns on the in focus bean
    $('.entity-bean.bean-in-focus > .content').equalHeights();
    $('.field-name-field-in-focus-left-content .field-items').equalHeights(null, ':first');
    $('.block-bean.bean-in-focus > h4.block-title').append('<a class="in-focus-control"><span>Open</span></a>').each(function() {
      $('.entity-bean.bean-in-focus').hide();
    });
    $('.in-focus-control').toggle(function() {
      $(this).find('span').addClass('opened').html('Close');
      $(this).closest('.block-bean').find('.entity-bean.bean-in-focus').slideDown();
    },
    function() {
      $(this).find('span').removeClass('opened').html('Open');      
      $(this).closest('.block-bean').find('.entity-bean.bean-in-focus').slideUp();
    });
    
  });
})(jQuery);;

