MJL.event.add(window, "load", function(event) {
    // MJL に関係するコードはこの中に記述
    MJL.enable.rollover("roll", {disable:"unroll"});
    MJL.enable.flash("flash");
}, false);

jQuery(document).ready(function(){

//プリセット
var conbox = jQuery("#mainContent");
var sec = conbox.find("div.section");
var det = conbox.find("div.detail");
var sech2 = sec.find("h2");
var secdet = sec.find("div.detail");
var alview = jQuery("img#allview");
var arrays = ["a","b","c","d","e","f","g","h","i","j","k","l","m"];

secdet.css("display", "none");
sech2.css("cursor", "pointer");
alview.css("cursor", "pointer");



// 開閉ボタンのcookie読み
sech2.each(function (i){
	if (jQuery.cookie("cookName")) {
		if ((jQuery.cookie("cookName").indexOf(arrays[i])) != -1) {//cookieに値があるときは表示
			jQuery(this).nextAll("div.detail").css("display", "block");
			jQuery(this).find("img").attr("src", jQuery(this).find("img").attr("src").replace("_cl.", "_op."));
			jQuery(this).closest("div.section").css("backgroundColor", "#f6f6f6");
		} else {//値がないときは非表示
			jQuery(this).nextAll("div.detail").css("display", "none");
			jQuery(this).find("img").attr("src", jQuery(this).find("img").attr("src").replace("_op.", "_cl."));
			jQuery(this).closest("div.section").css("backgroundColor", "#f6f6f6");
		}
	}
	i = i+1;
});

// 一度に開閉するボタンのcookie読み
if(jQuery.cookie("allview") == 0) {
  alview.attr("src", alview.attr("src").replace("_cl.", "_op."));
}else if(jQuery.cookie("allview") == 1) {
  alview.attr("src", alview.attr("src").replace("_op.", "_cl."));
}

jQuery("img").mouseover(function(){
	if(jQuery(this).attr("src").match("_cl.")){
	  jQuery(this).attr("src", jQuery(this).attr("src").replace("_cl.", "_cl_o."));
	}
	else if(jQuery(this).attr("src").match("_op.")){
	  jQuery(this).attr("src", jQuery(this).attr("src").replace("_op.", "_op_o."));
	}
});
jQuery("img").mouseout(function(){
	if(jQuery(this).attr("src").match("_cl_o.")){
	  jQuery(this).attr("src", jQuery(this).attr("src").replace("_cl_o.", "_cl."));
	}
	else if(jQuery(this).attr("src").match("_op_o.")){
	  jQuery(this).attr("src", jQuery(this).attr("src").replace("_op_o.", "_op."));
	  }
});



// 一度に開閉するボタン
alview.click(function () {
	if(jQuery(this).attr("src").match("_cl")){
	  secdet.slideDown("slow");
	  sec.css("backgroundColor", "#f6f6f6");
	  jQuery(this).attr("src", jQuery(this).attr("src").replace("_cl", "_op"));
	  sech2.find("img").each(function(i) {
	 	   jQuery(this).attr("src",  jQuery(this).attr("src").replace("_cl", "_op")); //
	  });
		var index = "abcdefghijklm";//cookieに値を全部代入
  	jQuery.cookie("cookName",index);
		jQuery.cookie("allview","0");
	}
	else if(jQuery(this).attr("src").match("_op")){
	  secdet.slideUp("slow");
	  sec.css("backgroundColor", "#f6f6f6");
	  jQuery(this).attr("src", jQuery(this).attr("src").replace("_op", "_cl"));
	  sech2.find("img").each(function(j) {
  	  jQuery(this).attr("src", jQuery(this).attr("src").replace("_op", "_cl"));
	  });
	  jQuery.cookie("cookName", "9");//IE6のNullと""の同一視回避
		jQuery.cookie("allview","1");
	}
});

// 個別に開閉するボタン
jQuery(".section h2").click(function () {
	var indexcode = sech2.index(this);
  var index = arrays[indexcode];
  var name = "cookName" ;//cookie Name
  var cookVal = jQuery.cookie(name);//cookie value

if(jQuery(this).nextAll("div.detail").css("display") == "none") {// display:noneだったら表示
  jQuery(this).closest("div.section").css("backgroundColor", "#f6f6f6");
  jQuery(this).nextAll("div.detail").slideDown("slow");
  jQuery(this).find("img").attr("src", jQuery(this).find("img").attr("src").replace("_cl", "_op"));
 }
 else if(jQuery(this).nextAll("div.detail").css("display") == "block") {	//display:blockだったら非表示
  jQuery(this).closest("div.section").css("backgroundColor", "#f6f6f6");
  jQuery(this).nextAll("div.detail").slideUp("slow");
  jQuery(this).find("img").attr("src", jQuery(this).find("img").attr("src").replace("_op", "_cl"));
 }
if (jQuery.cookie(name)) {//既にcookNameを持っていたら
 if ((cookVal.indexOf(index)) != -1) {//valueに対応する値をもっている場合
 	if(jQuery.cookie(name).length == 1){
		jQuery.cookie(name,"9");//IE6のNullと""の同一視回避
 	}
		var cookVal = jQuery.cookie(name).replace(index,"");//※3
		jQuery.cookie(name,cookVal);//クリックした値の削除。
	}else{
  	jQuery.cookie(name,cookVal+index);//クリックした値の追加。
	}
 }else{
   jQuery.cookie(name,index);//cookieを新たにセットする
 }
});

});



