/*********************************************************************************ドロップメニュー*/

$.fn.droppy = function() {
  
  this.each(function() {
    
    var root = this, zIndex = 1000;
    
    function getSubnav(ele) {
      if (ele.nodeName.toLowerCase() == 'li') {
        var subnav = $('> ul', ele);
        return subnav.length ? subnav[0] : null;
      } else {
        return ele;
      }
    }
    
    function getActuator(ele) {
      if (ele.nodeName.toLowerCase() == 'ul') {
        return $(ele).parents('li')[0];
      } else {
        return ele;
      }
    }
    
    function hide() {
      var subnav = getSubnav(this);
      if (!subnav) return;
      $.data(subnav, 'cancelHide', false);
      setTimeout(function() {
        if (!$.data(subnav, 'cancelHide')) {
          $(subnav).slideUp();
        }
      }, 500);
    }
  
    function show() {
      var subnav = getSubnav(this);
      if (!subnav) return;
      $.data(subnav, 'cancelHide', true);
      $(subnav).css({zIndex: zIndex++}).slideDown();
      if (this.nodeName.toLowerCase() == 'ul') {
        $(getActuator(this)).addClass('hover');
      }
    }
    
    $('ul, li', this).hover(show, hide);
    $('li', this).hover(
      function() { $(this).addClass('hover'); },
      function() { $(this).removeClass('hover'); }
    );
    
  });
  
};

/*********************************************************************************ロールオーバー*/
/**
 * jQueryRollover v1.0.1
 * http://rewish.org/javascript/jquery_rollover_plugin
 *
 * Copyright (c) 2009 Rewish (http://rewish.org/)
 *
 * Licensed under the MIT:
 * [en] http://www.opensource.org/licenses/mit-license.php
 * [ja] http://sourceforge.jp/projects/opensource/wiki/licenses%2FMIT_license
 *
 * Inspired by:
 * Telepath Labs (http://dev.telepath.co.jp/labs/article.php?id=15)
 *
 * Usage:
 * jQuery(document).ready(function($) {
 *   // <img>
 *   $('div#nav a img').rollover();
 *
 *   // <input type="image">
 *   $('form input:image').rollover();
 *
 *   // set postfix
 *   $('div#nav a img').rollover('_over');
 * });
 *
 **/
(function($) {
    $.fn.rollover = function(postfix) {
        postfix = postfix || '_on';
        return this.not('[src*="'+ postfix +'."]').each(function() {
            var img = $(this);
            var src = img.attr('src');
            var src_on = [
                src.substr(0, src.lastIndexOf('.')),
                src.substring(src.lastIndexOf('.'))
            ].join(postfix);
            $('<img>').attr('src', src_on);
            img.hover(
                function() {
                    img.attr('src', src_on);
                },
                function() {
                    img.attr('src', src);
                }
            );
        });
    };
})(jQuery);

