
var nowChList = new Array();
var BS = new Array("C", "C_sha", "D", "D_sha","E","F","F_sha","G","G_sha","A","A_sha","B");
var onOffBtnSW = true;
var linkText="";

function Ini(){
	chgMenu('C','BX_C');
	getData();
	readPar();
	dispImg();
	makeLinkData();
	dispLinkText();
}
function getData(){
	var Data = getCookie("pch=");
	if(Data != ""){
		nowChList = Data.split(".");
		nowChList.pop();
	}
}
function readPar(){
	if(location.search != ""){
		ng = location.search.replace("?pch=","");
		nowChList = ng.split(".");
		nowChList.pop();
	}	
}
function pushCh(imgN){
	 pushChList(imgN);
	 dispImg();
	 dispLinkText();
}
function doCookie(){
	makeLinkData();
	dispLinkText();
	setCookie("pch=",linkText,"365");
}
function pushChList(imgN){
	nowChList.push(imgN);
	doCookie();
}
function allClear(){
	nowChList = new Array();
	doCookie();
	dispImg();
}
function chgChList(dis,ch){
	nowChList[dis] = ch;
	doCookie();
	dispImg();
}
function delateChList(dis){
	nowChList.splice(dis,1);
	doCookie();
	dispImg();
}
function dispImg(){
	var imgUrl =""; 
	var str ="";
	var pageUrl = "";
	var pageUrlto = "";
	var nextImgForChk;
	var btnTen;
	var chk_nextImg;

	for(var i=0;i<nowChList.length;i++){
		imgUrl = "pngPianoChd/chdS_" + nowChList[i] + ".png";
		pageUrl = nowChList[i].split("_");
		if(pageUrl.length == 2){
			pageUrlto =  pageUrl[0];
			nextImgForChk = pageUrl[1];
		}
		else if(pageUrl.length == 3){
			pageUrlto =  pageUrl[0] + "_" + pageUrl[1];
			nextImgForChk = pageUrl[2];
		}
		chk_nextImg = chkNextImg(nextImgForChk);
		if(chk_nextImg){
			btnTen = "<span onClick=chgNextImg('"+nowChList[i]+"'," + i + ")><img src='./img/btn_ten.png'></span>";
		}else{
			btnTen = "";
		}
		str += "<div class='chbx'><div class='btnBox' id='bt_" + i + "'>" + btnTen + "<a href='./pianoChord_" + pageUrlto + ".html'><img src='./img/btn_info.png'></a><span onClick=delateChList(" + i + ")><img src='./img/btn_del.png'></span></div><img src='"+imgUrl+"'></div>";
	}
	pushInhtml("dispBox",str);
	
	if(onOffBtnSW == false){
		btnOff();
	}
}
function chkNextImg(chkNum){
		var num = chkNum.split("-");
		var chk;
		if(num[0] == 1){
			chk = false;
		}else{
			chk = true;
		}
		return chk;
}
function chgNextImg(img,arrayDis){
	var chNum;
	var imgNum;
	var imgName;

	var pageUrl = img.split("_");

	if(pageUrl.length == 2){
		chNum = pageUrl[1].split("-");
		imgName = pageUrl[0];
	}
	else if(pageUrl.length == 3){
		chNum = pageUrl[2].split("-");
		imgName = pageUrl[0] + "_" + pageUrl[1];
	}

	imgNum = chNum[0];
	var nowImgNum = chNum[1];

	if(chNum[0] != 0){
		nowImgNum = nowImgNum-0 + 1;
		if(nowImgNum>imgNum-1){
			nowImgNum = 0;
		}

		var imgUlr =imgName + "_" + imgNum + "-" + nowImgNum;
	}

	chgChList(arrayDis,imgUlr);
}
function makeLinkData(){
	linkText = "";
	for(var i=0;i<nowChList.length;i++){
		linkText += nowChList[i] + ".";
	}
	//alert(linkText);
}
function dispLinkText(){
	//var linkT = location.hostname + "?pch=" + linkText;
	var linkT = "http://www.piano-c.com/pianoClip.html?pch=" + linkText;
	//var str = "<a href='" + linkT + "'>CLIP URL</a>";
	var str = linkT;
	pushInhtml("dispLinkBox",str);
}
function onOffBtn(){
	var Elm;
	if(onOffBtnSW == true){
		btnOff();
		onOffBtnSW = false;
	}
	else if(onOffBtnSW == false){
		btnOn();
		onOffBtnSW = true;
	}
}
function btnOn(){
	for(i=0;i<nowChList.length;i++){
		Elm = "bt_" + i;
		dispElm_bl(Elm);
	}

}
function btnOff(){
	for(i=0;i<nowChList.length;i++){
		Elm = "bt_" + i;
		dispElm_no(Elm);
	}
}
function chgMenu(name,chId){
	var idName;
	var mIdName;
	for(var i=0;i<BS.length;i++){
		idName = "box_" + BS[i];
		mIdName = "BX_" + BS[i];
		dispElm_no(idName);
		chBgColor(mIdName,"#ffffff");
	}

	idName = "box_" + name;
	chBgColor(chId,"#F0FE65");

	dispElm_bl(idName);
}

