//jquery.hoverhere.js
//hoverされた項目のハイライトと「現在の場所はココ」でメニュー画像を入れ替える

/*
usage:
	<ul id="menu">
		<li><a href="a.html"><img src="a.png"></a></li>
		<li><a href="b.html"><img src="b.png"></a></li>
		<li><a href="c.html"><img src="c.png"></a></li>
	</ul>

	$("#menu a").hoverhere({
		here  : "-here",  // optional, default: "-hr"
		hover : "-hover"  // optional, default: "-hv"
	});

	a html below is modified ..
		<a href="a.html"><img src="a.png"></a>
	when hovered.. 
		<a href="a.html"><img src="a-hover.png"></a>
	when url like *a.html* .. 
		<a href="a.html"><img src="a-here.png"></a>
*/

/*
jquery.hoverhere.js:
  highlight hovered item and indicate "you are here" in menu slices.
Copyright (C) 2010 Haruka Kataoka for drumsoft

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

contact: hrk8#drumsoft.com
*/


(function($){
	$.fn.hoverhere = function(opt) {
		var defaults = {
			here  : "-hr",
			hover : "-hv"
		};
		opt = $.extend(defaults, opt);

		var preloader = [];
		function preload(src){
			var i = new Image();
			i.src = src;
			preloader.push[i];
		}

		var uri = location.href;
		this.each(function(){
			var a = $(this);
			var href = a.attr("href");
			var img = $("img", this);
			if ( href && uri.indexOf(href) >= 0 ) { // you are here!
				var src = img.attr("src").replace( /(\.\w+)$/, opt.here + "$1");
				img.attr("src", src);
			}else{ // hover event
				var src = img.attr("src");
				var srchover = src.replace( /(\.\w+)$/, opt.hover + "$1");
				preload(srchover);
				$(this).hover(
					function(e){
						img.attr("src", srchover);
					},
					function(e){
						img.attr("src", src);
					}
				);
			}
		});

		return this;
	};
})(jQuery);

