/**
 * jQuery.heightAlign - jQuery Plugin
 *
 * Under The MIT License
 * Copyright (c) 2011 Tetsuya MORI. (http://monry.jp/)
 * 
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * Version: 1.0.0
 * Revision: $Rev$
 * Date: $Date$
 */
(
  function($) {
    // {{{ 高さ調節
    $.fn.heightAlign = function(options) {
      var
        // デフォルトの設定
        _defaults = {
          'group_by_attribute': false
        },

        // 設定確定
        _setting = $.extend(_defaults, options),

        _targets = $(this),

        // 呼出時のコンテキスト
        _context = $(this).context,

        // 呼出時のセレクタ
        _selector = $(this).selector,

        // 実処理
        _align = function() {
          // {{{ 高さリスト構築
          var height_list = {};
          _targets.each(
            function(index, element) {
              var key = '';
              if (_setting.group_by_attribute) {
                key = $(element).attr(_setting.group_by_attribute);
              }
              if (typeof height_list[key] == 'undefined') {
                height_list[key] = 0;
              }
              if (height_list[key] < $(element).height()) {
                height_list[key] = $(element).height();
              }
            }
          );
          // }}}

          // {{{ 高さリストを元に高さを実際に調整
          $.each(
            height_list
            , function(key, value) {
              var __selector = _selector;
              if (_setting.group_by_attribute) {
                __selector += '[' + _setting.group_by_attribute + '="' + key + '"]';
              }
              $(__selector, _context).height(value);
            }
          );
          // }}}
        }
      ;

      _align();

      return this;
    }
    // }}}

  }
)(jQuery);


