var open_category = new Array();
var aw = [];
aw[0] = "00000000201-00000000588-00000000202";	//カテゴリ－アプリ
aw[1] = "00000000201-00000000207-00000000204";	//カテゴリ－Ｗｅｂ

function get_j(aid,jsan) {
	var type_key = aid.split("-");
	if(type_key[1]=="00000000588"){ var ttype = "iphone" };
	if(type_key[1]=="00000000207"){ var ttype = "web" };

	var reidid = aid.replace(/-/g,"/");
	var att = 0;
	//オープンチェック
	for(i=0; i<open_category.length; i++){
		if (aid == open_category[i]) {
			jQuery("#"+aid).next().slideUp(function(){
				jQuery("#"+aid).next().empty();
			});
			open_category.splice(i,1);
			//三角の変更（横）
			jQuery("#"+aid+"> img").attr("src","/common/images/arrow/img_btn_"+(ttype == "iphone" ? "app" : "site")+"arrow_right.gif");
			return;
		}
	}
	open_category.push(aid);

	//JSONデータ取得
	jQuery.getJSON("/childcategory?article_id="+reidid, function(json){
			//遷移
			if (json.items[0].child_type==null) {
				window.location.href = "/?article_id="+reidid+"&type="+ttype+"&area=cat";
				return;
			}
			//三角の変更（下）
			jQuery("#"+aid+"> img").attr("src","/common/images/arrow/img_btn_"+(ttype == "iphone" ? "app" : "site")+"arrow_down.gif");
			//展開
			if ((aid == aw[0])||(aid == aw[1])||(aid == aw[2])||(aid == aw[3])) {
				jQuery("#"+aid).after("<ul style='display:block;' id='"+aid+"_"+att+"'></ul>");
			} else {
				jQuery("#"+aid).after("<ul style='display:none;' id='"+aid+"_"+att+"'></ul>");
			}
			for(i=0; i<json.count; i++){
				var idid = json.items[i].article_id.replace(/\//g,"-");
				//背景
				if ((json.items[i].child_type=="category_web")||(json.items[i].child_type=="web")) { var cat_bg = "/common/images/bg_webnavi.jpg"; }
				if ((json.items[i].child_type=="category_iphone")||(json.items[i].child_type=="iphone")) { var cat_bg = "/common/images/bg_aplinavi.jpg"; }
				//カテゴリ階層
				var key = aid.split("-");
				if (key.length == 3){
					var ct_arrow_pos = 5;
				} else if (key.length == 4) {
					var ct_arrow_pos = 15;
				}
				jQuery("#"+aid+"_"+att).append("<li class='category_appli' id='"+idid+"' style='background-repeat:repeat;'><img style='margin-left:"+ct_arrow_pos+"px;margin-right:5px;' src='/common/images/arrow/img_btn_"+(ttype == "iphone" ? "app" : "site")+"arrow_right.gif'><a href='javascript:void(0);'>"+json.items[i].title+"</a></li>");

				//クリックイベント
				jQuery("#"+idid).click(function(){
					get_j(this.id,json);
				});
			}
			//スライド表示
			if ((aid != aw[0])||(aid != aw[1])||(aid != aw[2])||(aid != aw[3])) {
				jQuery("#"+aid+"_"+att).slideDown("normal");
			}
	});
}

jQuery(function() {
	for(i=0; i<aw.length; i++){
		get_j(aw[i]);
	}
});
