function sbAdjustPath(iIdx2,iScaleW,iScaleH) {
	var aiTemp = new Array();
	var iTempW;
	var iTempH;
	var iZoomin;
	var iMarginX;
	var iMarginY;
	var iX,iY;
	var iIdx;
	var strPath;
	
	iTempW = (m_iCvWt - m_iMargin) / iScaleW;
	iTempH = (m_iCvHt - m_iMargin) / iScaleH;
	iZoomin = (iTempW < iTempH ? iTempW : iTempH)
	iMarginX = m_iCvWt / 2 - iScaleW * iZoomin / 2;
	iMarginY = m_iCvHt / 2 - iScaleH * iZoomin / 2;
	
	strPath = '';
	for (iIdx = 0; iIdx < m_astrPath[iIdx2].length; iIdx++) {
		if        (m_astrPath[iIdx2][iIdx].length == 0) {
		} else if (m_astrPath[iIdx2][iIdx].length == 1) {
			strPath += m_astrPath[iIdx2][iIdx] + ' ';
		} else {
			aiTemp = m_astrPath[iIdx2][iIdx].split(',');
			iX = Number(aiTemp[0]) * iZoomin + iMarginX;
			iY = Number(aiTemp[1]) * iZoomin + iMarginY;
			strPath += iX + ',' + iY + ' ';
		}
	}
	m_astrPath[iIdx2] = strPath.split(' ');
}

function sbCreatePathLocate(iEd) {
	var iPointLimit = 100;
	var iX,iY,iX0,iY0,iX1,iY1;
	var aiTemp = new Array();
	var aiC0 = new Array();
	var aiX0 = new Array();
	var aiY0 = new Array();
	var aiC1 = new Array();
	var aiX1 = new Array();
	var aiY1 = new Array();
	var aiX2 = new Array();
	var aiY2 = new Array();
	
	var aiS0 = new Array();
	var aiR0 = new Array();
	var aiMinX0 = new Array();
	var aiMinY0 = new Array();
	var aiMaxX0 = new Array();
	var aiMaxY0 = new Array();
	var aiCtrX0 = new Array();
	var aiCtrY0 = new Array();
	
	var aiS1 = new Array();
	var aiR1 = new Array();
	var aiMinX1 = new Array();
	var aiMinY1 = new Array();
	var aiMaxX1 = new Array();
	var aiMaxY1 = new Array();
	var aiCtrX1 = new Array();
	var aiCtrY1 = new Array();
	
	var aiSizePar = new Array();
	var abRev = new Array();
	
	var iS00,iS01,iS10,iS11;
	
	var iSt;
	var iLayerIdx;
	var iLayerCnt;
	var iPointIdx;
	var iPointNear;
	var iIdx;
	var iR;
	var iS;
	
	iSt = iEd - 1;
	
	iLayerIdx = -1;
	for (iIdx = 0; iIdx < m_astrPath[iSt].length; iIdx++) {
		if        (m_astrPath[iSt][iIdx].length == 0) {
		} else if (m_astrPath[iSt][iIdx].length == 1) { if (m_astrPath[iSt][iIdx] == 'M') { iLayerIdx++; iPointIdx = 0; }
		} else {
			aiTemp = m_astrPath[iSt][iIdx].split(',');
			aiX0[iLayerIdx * iPointLimit + iPointIdx] = Number(aiTemp[0]);
			aiY0[iLayerIdx * iPointLimit + iPointIdx] = Number(aiTemp[1]);
			iPointIdx++;
			aiC0[iLayerIdx] = iPointIdx;
		}
	}
	
	iLayerIdx = -1;
	for (iIdx = 0; iIdx < m_astrPath[iEd].length; iIdx++) {
		if        (m_astrPath[iEd][iIdx].length == 0) {
		} else if (m_astrPath[iEd][iIdx].length == 1) { if (m_astrPath[iEd][iIdx] == 'M') { iLayerIdx++; iPointIdx = 0; }
		} else {
			aiTemp = m_astrPath[iEd][iIdx].split(',');
			aiX1[iLayerIdx * iPointLimit + iPointIdx] = Number(aiTemp[0]);
			aiY1[iLayerIdx * iPointLimit + iPointIdx] = Number(aiTemp[1]);
			iPointIdx++;
			aiC1[iLayerIdx] = iPointIdx;
		}
	}
	
	//
	iLayerCnt = iLayerIdx + 1;
	for (iLayerIdx = 0; iLayerIdx < iLayerCnt; iLayerIdx++) {
		//
		iPointIdx = 0;
		aiMinX0[iLayerIdx] = aiX0[iLayerIdx * iPointLimit + iPointIdx];
		aiMinY0[iLayerIdx] = aiY0[iLayerIdx * iPointLimit + iPointIdx];
		aiMaxX0[iLayerIdx] = aiX0[iLayerIdx * iPointLimit + iPointIdx];
		aiMaxY0[iLayerIdx] = aiY0[iLayerIdx * iPointLimit + iPointIdx];
		for (iPointIdx = 1; iPointIdx < aiC0[iLayerIdx]; iPointIdx++) {
			aiMinX0[iLayerIdx] = Math.min(aiMinX0[iLayerIdx],aiX0[iLayerIdx * iPointLimit + iPointIdx]);
			aiMinY0[iLayerIdx] = Math.min(aiMinY0[iLayerIdx],aiY0[iLayerIdx * iPointLimit + iPointIdx]);
			aiMaxX0[iLayerIdx] = Math.max(aiMaxX0[iLayerIdx],aiX0[iLayerIdx * iPointLimit + iPointIdx]);
			aiMaxY0[iLayerIdx] = Math.max(aiMaxY0[iLayerIdx],aiY0[iLayerIdx * iPointLimit + iPointIdx]);
		}
		
		//
		iPointIdx = 0;
		aiMinX1[iLayerIdx] = aiX1[iLayerIdx * iPointLimit + iPointIdx];
		aiMinY1[iLayerIdx] = aiY1[iLayerIdx * iPointLimit + iPointIdx];
		aiMaxX1[iLayerIdx] = aiX1[iLayerIdx * iPointLimit + iPointIdx];
		aiMaxY1[iLayerIdx] = aiY1[iLayerIdx * iPointLimit + iPointIdx];
		for (iPointIdx = 1; iPointIdx < aiC1[iLayerIdx]; iPointIdx++) {
			aiMinX1[iLayerIdx] = Math.min(aiMinX1[iLayerIdx],aiX1[iLayerIdx * iPointLimit + iPointIdx]);
			aiMinY1[iLayerIdx] = Math.min(aiMinY1[iLayerIdx],aiY1[iLayerIdx * iPointLimit + iPointIdx]);
			aiMaxX1[iLayerIdx] = Math.max(aiMaxX1[iLayerIdx],aiX1[iLayerIdx * iPointLimit + iPointIdx]);
			aiMaxY1[iLayerIdx] = Math.max(aiMaxY1[iLayerIdx],aiY1[iLayerIdx * iPointLimit + iPointIdx]);
		}
		
		//
		aiCtrX0[iLayerIdx] = aiMinX0[iLayerIdx] + (aiMaxX0[iLayerIdx] - aiMinX0[iLayerIdx]) / 2;
		aiCtrY0[iLayerIdx] = aiMinY0[iLayerIdx] + (aiMaxY0[iLayerIdx] - aiMinY0[iLayerIdx]) / 2;
		
		//
		aiCtrX1[iLayerIdx] = aiMinX1[iLayerIdx] + (aiMaxX1[iLayerIdx] - aiMinX1[iLayerIdx]) / 2;
		aiCtrY1[iLayerIdx] = aiMinY1[iLayerIdx] + (aiMaxY1[iLayerIdx] - aiMinY1[iLayerIdx]) / 2;
		
		//
		aiSizePar[iLayerIdx] = Math.sqrt(Math.pow((aiMaxX1[iLayerIdx] - aiMinX1[iLayerIdx]),2) + Math.pow((aiMaxY1[iLayerIdx] - aiMinY1[iLayerIdx]),2)) / Math.sqrt(Math.pow((aiMaxX0[iLayerIdx] - aiMinX0[iLayerIdx]),2) + Math.pow((aiMaxY0[iLayerIdx] - aiMinY0[iLayerIdx]),2));
		
		//
		iS00 = (Math.atan2(aiY0[iLayerIdx * iPointLimit] - aiCtrY0[iLayerIdx],aiX0[iLayerIdx * iPointLimit] - aiCtrX0[iLayerIdx]) / Math.PI * 180 + 360) % 360;
		iS01 = (Math.atan2(aiY0[iLayerIdx * iPointLimit + Math.round(aiC0[iLayerIdx] * 0.25)] - aiCtrY0[iLayerIdx],aiX0[iLayerIdx * iPointLimit + Math.round(aiC0[iLayerIdx] * 0.25)] - aiCtrX0[iLayerIdx]) / Math.PI * 180 + 360) % 360;
		iS10 = (Math.atan2(aiY1[iLayerIdx * iPointLimit] - aiCtrY1[iLayerIdx],aiX1[iLayerIdx * iPointLimit] - aiCtrX1[iLayerIdx]) / Math.PI * 180 + 360) % 360;
		iS11 = (Math.atan2(aiY1[iLayerIdx * iPointLimit + Math.round(aiC1[iLayerIdx] * 0.25)] - aiCtrY1[iLayerIdx],aiX1[iLayerIdx * iPointLimit + Math.round(aiC1[iLayerIdx] * 0.25)] - aiCtrX1[iLayerIdx]) / Math.PI * 180 + 360) % 360;
		abRev[iLayerIdx] = (((Math.round(iS01 - iS00 + 360) % 360) < 180 && (Math.round(iS11 - iS10 + 360) % 360) >= 180) || ((Math.round(iS01 - iS00 + 360) % 360) >= 180 && (Math.round(iS11 - iS10 + 360) % 360) < 180));
		
		//
		if (abRev[iLayerIdx]) {
			for (iPointIdx = 0; iPointIdx < aiC0[iLayerIdx]; iPointIdx++) {
				aiX0[iLayerIdx * iPointLimit + iPointIdx] = aiCtrX0[iLayerIdx] + (aiCtrX0[iLayerIdx] - aiX0[iLayerIdx * iPointLimit + iPointIdx]);
			}
		}
		iX = aiX0[iLayerIdx * iPointLimit] - aiCtrX0[iLayerIdx];
		iY = aiY0[iLayerIdx * iPointLimit] - aiCtrY0[iLayerIdx];
		aiR0[iLayerIdx] = Math.sqrt(Math.pow(iX,2) + Math.pow(iY,2));
		aiS0[iLayerIdx] = (Math.atan2(iY,iX) / Math.PI * 180 + 360) % 360;
		iX = aiX1[iLayerIdx * iPointLimit] - aiCtrX1[iLayerIdx];
		iY = aiY1[iLayerIdx * iPointLimit] - aiCtrY1[iLayerIdx];
		aiR1[iLayerIdx] = Math.sqrt(Math.pow(iX,2) + Math.pow(iY,2));
		aiS1[iLayerIdx] = (Math.atan2(iY,iX) / Math.PI * 180 + 360) % 360;
	}
	
	var strPath;
	strPath = '';
	iLayerIdx = -1;
	for (iIdx = 0; iIdx < m_astrPath[iSt].length; iIdx++) {
		if        (m_astrPath[iSt][iIdx].length == 0) {
		} else if (m_astrPath[iSt][iIdx].length == 1) {
			if (m_astrPath[iSt][iIdx] == 'M') { iLayerIdx++; iPointIdx = 0; }
			strPath += m_astrPath[iSt][iIdx] + ' ';
		} else {
			iX = aiX0[iLayerIdx * iPointLimit + iPointIdx] - aiCtrX0[iLayerIdx];
			iY = aiY0[iLayerIdx * iPointLimit + iPointIdx] - aiCtrY0[iLayerIdx];
			iR = Math.sqrt(Math.pow(iX,2) + Math.pow(iY,2));
			iS = Math.atan2(iY,iX) / Math.PI * 180;
			iR *= aiSizePar[iLayerIdx];
			iS += aiS1[iLayerIdx] - aiS0[iLayerIdx];
			iY = Math.sin(iS / 180 * Math.PI) * iR + aiCtrY1[iLayerIdx];
			iX = Math.cos(iS / 180 * Math.PI) * iR + aiCtrX1[iLayerIdx];
			strPath += Math.round(iX) + ',' + Math.round(iY) + ' ';
			iPointIdx++;
		}
	}
	
	m_astrPath[iEd] = strPath.split(' ');
}

function sbCreatePathbuki(iEd) {
	var iPointLimit = 100;
	var iX0,iY0,iX1,iY1;
	var aiTemp = new Array();
	var aiC0 = new Array();
	var aiX0 = new Array();
	var aiY0 = new Array();
	var aiC1 = new Array();
	var aiX1 = new Array();
	var aiY1 = new Array();
	var aiX2 = new Array();
	var aiY2 = new Array();
	var aiTn = new Array();
	var iSt;
	var iLayerIdx;
	var iLayerCnt;
	var iPointIdx;
	var iPointNear;
	var iIdx;
	
	iSt = iEd - 1;
	
	iLayerIdx = -1;
	for (iIdx = 0; iIdx < m_astrPath[iSt].length; iIdx++) {
		if        (m_astrPath[iSt][iIdx].length == 0) {
		} else if (m_astrPath[iSt][iIdx].length == 1) { if (m_astrPath[iSt][iIdx] == 'M') { iLayerIdx++; iPointIdx = 0; }
		} else {
			aiTemp = m_astrPath[iSt][iIdx].split(',');
			aiX0[iLayerIdx * iPointLimit + iPointIdx] = Number(aiTemp[0]);
			aiY0[iLayerIdx * iPointLimit + iPointIdx] = Number(aiTemp[1]);
			iPointIdx++;
			aiC0[iLayerIdx] = iPointIdx;
		}
	}
	
	iLayerIdx = -1;
	for (iIdx = 0; iIdx < m_astrPath[iEd].length; iIdx++) {
		if        (m_astrPath[iEd][iIdx].length == 0) {
		} else if (m_astrPath[iEd][iIdx].length == 1) { if (m_astrPath[iEd][iIdx] == 'M') { iLayerIdx++; iPointIdx = 0; }
		} else {
			aiTemp = m_astrPath[iEd][iIdx].split(',');
			aiX1[iLayerIdx * iPointLimit + iPointIdx] = Number(aiTemp[0]);
			aiY1[iLayerIdx * iPointLimit + iPointIdx] = Number(aiTemp[1]);
			iPointIdx++;
			aiC1[iLayerIdx] = iPointIdx;
		}
	}
	
	iLayerCnt = iLayerIdx + 1;
	for (iLayerIdx = 0; iLayerIdx < iLayerCnt; iLayerIdx++) {
		aiTn[iLayerIdx] = 1;
	}
	
	iLayerIdx = -1;
	for (iIdx = 0; iIdx < m_astrPath[iSt].length; iIdx++) {
		if        (m_astrPath[iSt][iIdx].length == 0) {
		} else if (m_astrPath[iSt][iIdx].length == 1) { if (m_astrPath[iSt][iIdx] == 'M') { iLayerIdx++; iPointIdx = 0; }
		} else {
			iPointNear = iPointIdx * (aiC1[iLayerIdx] - 1) / (aiC0[iLayerIdx] - 1);
			if (aiTn[iLayerIdx] == 1) {
				iX0 = aiX1[iLayerIdx * iPointLimit + (Math.floor(iPointNear) + 0) % aiC1[iLayerIdx]];
				iY0 = aiY1[iLayerIdx * iPointLimit + (Math.floor(iPointNear) + 0) % aiC1[iLayerIdx]];
				iX1 = aiX1[iLayerIdx * iPointLimit + (Math.floor(iPointNear) + 1) % aiC1[iLayerIdx]];
				iY1 = aiY1[iLayerIdx * iPointLimit + (Math.floor(iPointNear) + 1) % aiC1[iLayerIdx]];
			} else {
				iX0 = aiX1[iLayerIdx * iPointLimit + (aiC1[iLayerIdx] - 1 - (Math.floor(iPointNear) + 0) % aiC1[iLayerIdx])];
				iY0 = aiY1[iLayerIdx * iPointLimit + (aiC1[iLayerIdx] - 1 - (Math.floor(iPointNear) + 0) % aiC1[iLayerIdx])];
				iX1 = aiX1[iLayerIdx * iPointLimit + (aiC1[iLayerIdx] - 1 - (Math.floor(iPointNear) + 1) % aiC1[iLayerIdx])];
				iY1 = aiY1[iLayerIdx * iPointLimit + (aiC1[iLayerIdx] - 1 - (Math.floor(iPointNear) + 1) % aiC1[iLayerIdx])];
			}
			aiX2[iLayerIdx * iPointLimit + iPointIdx % aiC0[iLayerIdx]] = iX0 + (iX1 - iX0) * (iPointNear - Math.floor(iPointNear));
			aiY2[iLayerIdx * iPointLimit + iPointIdx % aiC0[iLayerIdx]] = iY0 + (iY1 - iY0) * (iPointNear - Math.floor(iPointNear));
			iPointIdx++;
		}
	}
	
	var strPath;
	strPath = '';
	iLayerIdx = -1;
	for (iIdx = 0; iIdx < m_astrPath[iSt].length; iIdx++) {
		if        (m_astrPath[iSt][iIdx].length == 0) {
		} else if (m_astrPath[iSt][iIdx].length == 1) {
			if (m_astrPath[iSt][iIdx] == 'M') { iLayerIdx++; iPointIdx = 0; }
			strPath += m_astrPath[iSt][iIdx] + ' ';
		} else {
			iX0 = aiX0[iLayerIdx * iPointLimit + iPointIdx];
			iY0 = aiY0[iLayerIdx * iPointLimit + iPointIdx];
			iX1 = aiX2[iLayerIdx * iPointLimit + iPointIdx];
			iY1 = aiY2[iLayerIdx * iPointLimit + iPointIdx];
			strPath += Math.round(iX0 + (iX1 - iX0) * m_iBlendPar) + ',' + Math.round(iY0 + (iY1 - iY0) * m_iBlendPar) + ' ';
			iPointIdx++;
		}
	}
	
	m_astrPath[iEd] = strPath.split(' ');
}

function sbDrawFrame(ctxCv,iBaseX,iBaseY,iBaseW,iBaseH) {
	var iLineWidth;
	iLineWidth = ctxCv.lineWidth;
	ctxCv.lineWidth = 2;	//Math.floor(iBaseW * 2 / m_iCvWt);
	ctxCv.beginPath();
	ctxCv.rect(iBaseX + ctxCv.lineWidth - 1,iBaseY + ctxCv.lineWidth - 1,iBaseW - ctxCv.lineWidth,iBaseH - ctxCv.lineWidth);
	ctxCv.stroke();
	ctxCv.lineWidth = iLineWidth;
}

function sbDrawBack(ctxCv,iBaseX,iBaseY,iBaseW,iBaseH,iPar,strCol1,strCol2) {
	var strCol0;
	strCol0 = ctxCv.fillStyle;
	if (iPar > 0.9) {
		ctxCv.fillStyle = strCol1;
		sbDrawLine(ctxCv,iBaseX,iBaseY,iBaseW,iBaseH,1,0.4,1.5,true);
		sbDrawLine(ctxCv,iBaseX,iBaseY,iBaseW,iBaseH,1,0.8,1.5,true);
	}
	if (iPar > 0) {
		ctxCv.fillStyle = strCol2;
		ctxCv.beginPath();
		ctxCv.moveTo(iBaseX,iBaseY + iBaseH * (1 - 0.06 * iPar));
		ctxCv.bezierCurveTo(iBaseX + iBaseW * (1 - 0.42 * iPar),iBaseY + iBaseH * 1.09,iBaseX + iBaseW,iBaseY + iBaseH * (1 - 0.24 * iPar),iBaseX + iBaseW,iBaseY + iBaseH * (1 - 0.24 * iPar));
		ctxCv.lineTo(iBaseX + iBaseW,iBaseY + iBaseH);
		ctxCv.lineTo(iBaseX,iBaseY + iBaseH);
		ctxCv.closePath();
		ctxCv.fill();
	}
	ctxCv.fillStyle = strCol0;
}
function sbDrawLine(ctxCv,iBaseX,iBaseY,iBaseW,iBaseH,iSt,iPar,iSize,bFill) {
	var iX,iY;
	var aiX = new Array();
	var aiY = new Array();
	var aiTemp = new Array();
	var aiCurve = new Array();
	var iCurve;
	var iIdx,iIdx2;
	var strMode;
	var iCol;
	
	iPar = (iPar < 0 ? 0 : (iPar > 1 ? 1 : iPar));
	
	strMode = '';
	iCol = 0;
	for (iIdx = 0; iIdx < m_astrPath[iSt].length; iIdx++) {
		if        (m_astrPath[iSt][iIdx].length == 0) {
		} else if (m_astrPath[iSt][iIdx].length == 1) {
			strMode = m_astrPath[iSt][iIdx];
			if        (strMode == 'M')  {
			} else if (strMode == 'C')  { iCurve = 0;
			} else if (strMode == 'L')  {
			} else if (strMode == 'z')  { bFill ? ctxCv.fill() : ctxCv.stroke();
			} else if (strMode == "\n") {
			} else                      {
			}
		} else {
			for (iIdx2 = 0; iIdx2 <= 1; iIdx2++) {
				aiTemp = m_astrPath[iSt + iIdx2][iIdx].split(',');
				aiX[iIdx2] = Number(aiTemp[0]);
				aiY[iIdx2] = Number(aiTemp[1]);
			}
			iX = Math.round(aiX[0] + (aiX[1] - aiX[0]) * iPar);
			iY = Math.round(aiY[0] + (aiY[1] - aiY[0]) * iPar);
			
			iX = iX * iSize - m_iCvWt * iSize / 2 + m_iCvWt / 2;
			iY = iY * iSize - m_iCvHt * iSize / 2 + m_iCvHt / 2;
			
			iX = iBaseX + iX * (iBaseW / m_iCvWt);
			iY = iBaseY + iY * (iBaseH / m_iCvHt);
			
			if        (strMode == 'M') {
				iCol = (iCol + 1) % 2;
				ctxCv.beginPath();
				ctxCv.moveTo(iX,iY);
			} else if (strMode == 'C') { 
				aiCurve[iCurve * 2 + 0] = iX;
				aiCurve[iCurve * 2 + 1] = iY;
				iCurve++;
				
				if (iCurve == 3)   {
					ctxCv.bezierCurveTo(aiCurve[0],aiCurve[1],aiCurve[2],aiCurve[3],aiCurve[4],aiCurve[5]);
				}
			} else if (strMode == 'L') { ctxCv.lineTo(iX,iY);
			} else if (strMode == 'z') {
			} else                     {
			}
		}
	}
}
