/**
 *--------------------------------------------------------------------
 *
 * jQueryRollover D5ver v1.0.1
 * http://blog.daichifive.com/archives/490
 * Copyright (c) 2009 DAICHIFIVE(http://www.daichifive.com/)
 *
 *--------------------------------------------------------------------
 * Licensed under the MIT:
 * [en] http://www.opensource.org/licenses/mit-license.php
 * [ja] http://sourceforge.jp/projects/opensource/wiki/licenses%2FMIT_license
 *
 * Original Version:
 * jQueryRollover v1.0.1
 * http://rewish.org/javascript/jquery_rollover_plugin
 * Copyright (c) 2009 Rewish (http://rewish.org/)
 *--------------------------------------------------------------------
 * Usage:
 * $(function(){
 *   // <img>
 *   $('div#nav a img').rollover();
 *
 *   // <input type="image">
 *   $('form input:image').rollover();
 *
 *   // set active
 *   $('div#nav a img').rollover('div#nav a#home img');
 * });
 *--------------------------------------------------------------------
 **/

(function($) {
    $.fn.rollover = function(active) {
        var postfix = '_on';
        var index = $('body *').index($(active));
        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);
            if (index == $('body *').index(img)) {
            	img.attr('src', src_on);
            }
            else {
            	img.hover(
                	function() {
                    	img.attr('src', src_on);
                	},
                	function() {
                    	img.attr('src', src);
                	}
            	);
            }
        });
    };
})(jQuery);


/**ノーマルロールオーバー**/

$(function(){
	$('.roll').each(function(){
		this.originalSrc = $(this).attr('src');
		this.rolloverSrc = this.originalSrc.replace(/(\.gif|\.jpg|\.png)$/, '_on'+"$1");
		this.rolloverImg = new Image();
		this.rolloverImg.src = this.rolloverSrc;
	}).hover(function(){
		$(this).attr('src',this.rolloverSrc);
	},function(){
		$(this).attr('src',this.originalSrc);
	});
});
