(function() {
	jQuery.fn.mypopupmenu = function()
	{
		var url;
		var str;
		var img_src;
		var str2;
		var img;
		
				$(".rollover_menu").children("a").each(function(){
					// カテゴリー画像を変更
					if($(this).attr("href")==location.href) // 親カテゴリーページ表示時にカテゴリー画像を変更
					{
						$("img", this).attr("src", $("img", this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_over$2"));
					}
					else // サブカテゴリーページ表示時に親カテゴリー画像を変更
					{
						url = location.href;
						str = url.replace(/^.*\?/, "").replace(/&.*$/, "");
						img_src = $(this).attr("href");
						str2 = img_src.replace(/^.*\?/, "").replace(/&.*$/, "");
	
						if (str.match(str2) != null) 
						{
							$("img", this).attr("src", $("img", this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_over$2"));
						}
					}
				});

				$("div[class=rollover_menu]").hover(
					function () {
							var obj = this;

							// サブカテゴリーマッチングのため
							url = location.href;
							str = url.replace(/^.*\?/, "").replace(/&.*$/, "");
							img_src = $(this).children("a").attr("href");
							str2 = img_src.replace(/^.*\?/, "").replace(/&.*$/, "");

							// オーバー状態ではなく表示ページでない時に画像変更
							img = $("img", this).attr("src");
							if ((img.match("/_over/") == null) && (($(this).children("a").attr("href")!=location.href) && (str.match(str2) == null)))
							{
								$("img", this).attr("src", $("img", this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_over$2"));
							}

							$(this).oneTime(DISPLAY_TIME * 1000, function()
							{
								$(obj).children("div").css({"display":"block"});
								
								// ブラウザによる分岐
//								if ($.browser.msie && $.browser.version <= 6)
//								{
//									var top_position = $(obj).children("div").offset().top;
//									var left_position = $(obj).children("div").offset().left;
//
//									$(obj).children("div").css({'position':'absolute','top':top_position + "px",'left':left_position + "px"});
//								}
//								else
//								{
//									$(obj).children("div").css("position", "absolute");
//								}
							});
					},
					function () {
							$(this).stopTime(); // タイマー停止

							// サブカテゴリーマッチングのため
							url = location.href;
							str = url.replace(/^.*\?/, "").replace(/&.*$/, "");
							img_src = $(this).children("a").attr("href");
							str2 = img_src.replace(/^.*\?/, "").replace(/&.*$/, "");

							// オーバー状態ではなく表示ページでない時に画像変更
							img = $("img", this).attr("src");
							if ((img.match("/_over/") == null) && (($(this).children("a").attr("href")!=location.href) && (str.match(str2) == null)))
							{
								$("img", this).attr("src",$("img", this).attr("src").replace(/^(.+)_over(\.[a-z]+)$/, "$1$2"));
							}

							$(this).children("div").css("display", "none");
					  }
				)
	}
})(jQuery);
