/* ============================================================

hoverImageChange
ver1.0   2011.2


$("img.imgover,input.imgover").imageOverChange({});

==============================================================*/

(function($) {
	$.fn.imageOverChange = function(options) {
		// elementに格納
		var element = $(this);
		
		// 初期オプション
		var conf = $.extend({
			// アニメーション設定 false or true
			animate: false,
			animateOpacity: 0.4,
			animateSpeed: 800,
			// 追加するホバーイメージ名
			hoverImage: "_on",
			// キャンセルクラス
			changeCance: "activeImg"
		}, options);
		
		element.each(function(){
			var thisSrc = this.src;
			
			// ON画像指定
			if(thisSrc.indexOf("_off.") > 1){
				var hoverSrc = thisSrc.replace("_off.",conf.hoverImage+'.');
				$("<img>").attr("src", hoverSrc); //画像プリロード
			}		
			// ホバー処理
			$(this).hover(function(){
				if(!$(this).hasClass(conf.changeCance)){
					$(this).attr("src",hoverSrc);
				}
				if(conf.animate) {
					$(this).stop().animate({opacity: conf.animateOpacity}, 0).animate({opacity: 1}, conf.animateSpeed);
				}
			},function (){
				if(!$(this).hasClass(conf.changeCance)){
					$(this).attr("src",thisSrc);
				}
			});
		});
		return this;
	}
})(jQuery);


// プラグイン実行
$(function (){
	$("img.imgover,input.imgover").imageOverChange({});
});

