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

$(document).ready(function(){

//プリセット
var conbox = $("#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 = $("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 ($.cookie("cookName")) {
		if (($.cookie("cookName").indexOf(arrays[i])) != -1) {//cookieに値があるときは表示
			$(this).nextAll("div.detail").css("display", "block");
			$(this).find("img").attr("src", $(this).find("img").attr("src").replace("_cl.", "_op."));
			$(this).closest("div.section").css("backgroundColor", "#f6f6f6");
		} else {//値がないときは非表示
			$(this).nextAll("div.detail").css("display", "none");
			$(this).find("img").attr("src", $(this).find("img").attr("src").replace("_op.", "_cl."));
			$(this).closest("div.section").css("backgroundColor", "#f6f6f6");
		}
	}
	i = i+1;
});

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

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



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

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

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

});

