$(function(){

	function ImgOvAnimeFadeSizing(){

		var OvClass = "rollover",
		OvStr = "_on", //ロールオーバー後の画像に追加する文字列
		OvRrap = "ovRrap",
		OvImg = "ovImg",
		Speed = 500; //アニメーションの速度

		$("img."+OvClass).each(function(){ //classがrolloverのimg要素に対しての処理

			var This = $(this),
			UrlDef = This.attr("src"),
			UrlChange = UrlDef.replace(/^(.+)(\.[a-z]+)$/,"$1"+OvStr+"$2");

			function OvElm(){
				return This.prev("span."+OvImg);
			}
			function OvElmLen(){ //ロールオーバー画像表示確認関数
				return OvElm().length;
			}
			function Width(){
				return This.width()+"px";
			}
			function Height(){
				return This.height()+"px";
			}

			This.hover(
			function(){
				if(!This.attr("src").match(OvStr+".")){
					if(!OvElmLen()){
						if(jQuery.support.checkOn && jQuery.support.htmlSerialize && !window.globalStorage){ //Operaバグ対策
							This.before("<span style='display:inline-block;' class='"+OvImg+"' ></span>");
						}
						This.css({opacity:"0",position:"relative"})
						.before("<span style='display:inline;width:"+Width()+";height:"+Height()+";background-image:url("+UrlDef+");position:absolute;' class='"+OvImg+"'></span>")
						.before("<span style='display:inline;width:0;height:0;background-image:url("+UrlChange+");position:absolute;' class='"+OvImg+"'></span>");
						OvElm().css({opacity:"0"});
					}
					OvElm().stop().animate({width:Width(),height:Height(),opacity:"1"},Speed)
					.prev("span."+OvImg).stop().animate({width:"0",height:"0",opacity:"0"},Speed);
				}
			},
			function(){
				if(OvElmLen()){
					OvElm().stop().animate({width:"0",height:"0",opacity:"0"},Speed)
					.prev("span."+OvImg).stop().animate({width:Width(),height:Height(),opacity:"1"},Speed,function(){
						This.css({opacity:"1",position:"static"})
						.prevAll("."+OvImg).remove();
					});
				}
			})
			.each(function(){ //プリロード設定
				$("<img>").attr("src",UrlChange);
			});

		});

	}

	ImgOvAnimeFadeSizing();

});

