/**
 *--------------------------------------------------------------------
 *
 * 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(){
	$('#header ul li a img').rollover('');
	$('#footer a img').rollover('');
});

