function openVariations(pTxt, pSource)
{
	document.getElementById("spVariacoes").style.display = "block";
	spTop = isIE ? window.event.y+document.body.scrollTop : 100;
	spLeft = isIE ? window.event.x+40 : 200
	document.getElementById("spVariacoes").style.top = spTop// - 128
	document.getElementById("spVariacoes").style.left = spLeft

	var variations = "<table width='180'>";

	tableRows = parseInt(chord[pTxt].length/3 + 1)
//	for (var row = 0; row < tableRows; row ++)
	for (var row = 0; row < 1; row ++)
	{
		variations += "<tr>"
		for (var col = 0; col < 3; col++)
		{
			pos = row * 3 + col
			//alert("pos: " + pos)			
			if (pos < chord[pTxt].length) 
			{
				//alert("pTxt: " + pTxt + ", pos: " + pos + ", 1, 1, pSource: " + pSource)
				cont ++;
				variations += "<td height='60' width='33%' align=right>" + retornaAcorde(pTxt, pos, 1, 1, pSource) + "</td>";
				//variations += ""; //"<td height='60' width='33%' align=right>" + "</td>";
			}
			else
			{
				
				variations += "<td>&nbsp;</td>";
			}
		}		
		variations += "</tr>"
	}
	//alert(111)
	document.getElementById("spVariacoes").innerHTML = variations
}
function changeChordChart(chordName, chordPosition, divSource)
{
	//alert("d" + divSource + " - " + chord[chordName][chordPosition])
	
	cont = divSource
	desenho = retornaAcorde(chordName, chordPosition, 1, 0, 0);
	document.getElementById("d" + divSource).innerHTML = desenho;
	document.getElementById("spVariacoes").style.display = "none";
}

function retornaAcorde(txt, chordPosition, direcao, styleChord, chordSource)
{

	//styleChord  0 = normal / 1 = sem o titulo
	// direcao    1 = destro / -1 = canhoto
	txt1 = chord[txt][chordPosition]
	//direcao = -1
	arrAcorde = txt1.split(' ')
	var min = 100
	var max = toques = 0
	tds = new Array()
	var bolTonica = true
	for (n = 0; n < arrAcorde.length; n++)
	{
		arrAc = arrAcorde[n]
		if (arrAc != "X")
		{
			if (arrAc != "0" && parseInt(arrAc) < min) min = parseInt(arrAc)
			if (parseInt(arrAc) > max) max = parseInt(arrAc)
			if (arrAc.substring(0,1) != "P" && arrAc != "0") toques ++
			if (bolTonica) {tonica = n; bolTonica = false;}
		}
	}
	var primeiroTraste = min
	if (max <=5) min = 1;
	acorde = "<table border=0 cellspacing=0 cellpadding=0>"
	if (styleChord == 0) acorde += "<tr><td height=10 class=aco colspan=2><a style=cursor:hand onclick=openVariations('" + txt + "'," + cont + ")>" + txt + "</a></td></tr>"
	acorde += "<tr><td valign=top align=right class=smalltext>" + (min == 1 ? "" : min) + "</td>";

	if (styleChord == 0)
	acorde +="<td width=36 height=41><span onClick=openVariations('" + txt + "'," + cont + ") onmouseover='img" + cont + ".src=\"images/braco_color.gif\"' onmouseout='img" + cont + ".src=\"images/braco.gif\"' iid=sp" + cont + " style='cursor:hand;position:absolute'>";
	else
	acorde +="<td width=36 height=41><span onClick='changeChordChart(\"" + txt + "\"," + chordPosition + "," + chordSource + ");' onmouseover='img" + cont + ".src=\"images/braco_color.gif\"' onmouseout='img" + cont + ".src=\"images/braco.gif\"' iid=sp" + cont + " style='cursor:hand;position:absolute'>";
	
	
	acorde += "<table border=0 cellpadding=0 cellspacing=0 width=36 height=40>"
	for (traste = min; traste <= min + 4; traste ++)
	{
		acorde +="<tr height=8>"
		pestana = false
		trasteVazio = true;
		for (corda = 0; corda <= 5; corda ++)
		{
			//for (corda = 5; corda >= 0; corda --){
			tds[corda] ="<td width=7 align=right vaalign=bottom height=8>" 
			posPestana = (arrAcorde[corda]  == "P" + traste)
			if (arrAcorde[corda] == traste || pestana || posPestana)
			{
				trasteVazio = false;
				if ((toques > 4 && traste == primeiroTraste) || pestana || posPestana)
				{
				//	if (!pestana) dedo ++
					pestana = true
					tds[corda] += "<img src='images/pestana.gif' width=6 height=4 align=top>"
				}
				else
				{
					tds[corda] += "<img src=images/b1.gif align=absmiddle>"; 
				}
			}
			tds[corda] += "</td>"
	} 
	//if (trasteVazio && dedo > 1 && dedo < 3 && toques <4) dedo ++
	if (direcao == -1) 
	{
		for (n=5; n>=0; n--)
		{
			acorde += tds[n]
		}
	} else
	{
		for (n=0; n<=5; n++)
		{
			acorde += tds[n]
		}
	}
	acorde +="</tr>"}
	acorde +="<tr height=8>"
	if (direcao == -1) 
	{
		for (n = arrAcorde.length-1; n>=0; n--){
		acorde += "<td class='smalltext' align=center>" + (arrAcorde[n] == "X" ? "<img src='images/x.gif' align=absmiddle>" : (tonica == n ? "<img src='images/b1.gif' align=absmiddle>" :"<img src='images/o_minusculo2.gif' align=absmiddle>")) + "</td>"}
	}
	else
	{
		for (n = 0; n < arrAcorde.length; n++){
		acorde += "<td class='smalltext' align=center>" + (arrAcorde[n] == "X" ? "<img src='images/x.gif' align=absmiddle>" : (tonica == n ? "<img src='images/b1.gif' align=absmiddle>" :"<img src='images/o_minusculo2.gif' align=absmiddle>")) + "</td>"}
	}
	acorde +="</tr>"
	acorde +="</table>"
// fim notas
	acorde +="</span><img id=img" + cont + " src='images/braco.gif'></td>";
	acorde +="</tr></table>"

	return acorde;
}
