$(function(){
	var config = {
		sensitivity: 1,
		interval: 100,     // マウスオーバーした時にドロップダウンメニューが表示されるまでの時間（milliiseconds）
		over: doOpen2,      // マウスオーバーした時に実行されるコールバック関数の指定（必須）
		timeout: 500,      // マウスアウトした時にドロップダウンメニューが消えるまでの時間（milliseconds）
		out: doClose2       // マウスアウトした時に実行されるコールバック関数の指定（必須）
	};


	function doOpen2() {

		var placeHolder = $(this).children("ul.placeHolder").text();
		var __this = this; // コールバック関数無いでは、this変数は使用できないため、変数を作成して代入させる

		var category_id = $(this).attr("id");

		$(this).addClass("hover");
		$(this).children("ul.placeHolder").css("visibility", "visible");
		$(this).children("ul.placeHolder").css("display", "block");
		$(this).children("ul.placeHolder").css("z-index", "10");

		// プレースホルダー内にデータが挿入されていないときに、データを取得する
		if(typeof(category_id) != "undefined" && placeHolder.length == 0) {
			$.getJSON(
						"/api/category.php",
						{"category_id": category_id},
						function (data) {
							if (! data ) { return null; }
							//if ( data.statusText != "OK") { return false; }
							//$(__this).children("ul.placeHolder").setTemplateElement("DoropDownList");
							$(__this).children("ul.placeHolder").setTemplateURL("/user_data/packages/futaba/js/ddm_template.js.tpl");
							$(__this).children("ul.placeHolder").processTemplate(data);
							// 作成したLIタグ配下のDIVにマウスオーバー、マウスアウトイベントの登録
							$("li div", __this).dropDownMenu(config);
						}
					);
		}

	}


	function doClose2() {
		//while ( __this == this ) { try { __this = __this.parentNode; } catch(e) { __this = this; } }
		$(this).removeClass("hover");
		$(this).children("ul.placeHolder").css("visibility", "hidden");
		$(this).children("ul.placeHolder").css("display", "none");

	}

	// マウスオーバー、アウトイベントをul.childcategoryのLI要素に対して登録する
	$("ul.childcategory li div").dropDownMenu(config);


	var category_banner = function(e) {

		switch(e.type) {
		case 'mouseover':
			// 拡張子の取得
			var img_src = $(this).attr("src");
			var img;
			var ext;
			var over_src;
			if((img = img_src.lastIndexOf(".")) != -1) {
				path = img_src.substring(0, img);
				ext = img_src.substring(img);
				orver_src = path + "_on" + ext;

				$(this).attr("src", orver_src);

			}
			break;
		case 'mouseout':
			var img_src = $(this).attr("src");
			var out_src = img_src.replace("_on", "");
			$(this).attr("src", out_src);
			break;
		default:
			break;
		}

	}

	// マウスオーバー時に画像を変化させる
	// 左ショルダー部分のカテゴリ画像のマウスオーバー機能とマウスアウト機能
	$("li.level1 div a img").mouseover(category_banner).mouseout(category_banner);

	// ヘッダー部分のカテゴリ画像のマウスオーバー機能とマウスアウト機能
	$("div#head_categorylist li a img").mouseover(category_banner).mouseout(category_banner);

});

