var mp3 = 1;
var rigiro = 0;
var mp3PlayButton = "play.png";
var mp3StopButton = "pausa2.png";
var mp3title = new Array();
var mp3url = "http://www.blia.it/giochi/musicgame/";

var f = new Array();
f[0]= "ab7facc90510ee4d836a27edc4c6482c";
f[1] = "be11a2825ef164679651d1948a375b47";
f[2] = "7b02d74c05fede0ec0e6d44ac9765996";
f[3] = "0a0603d5a6b9353c7a65d46cfe340074";
f[4] = "526ff0e8a3e1afc74cd9f5a903cae683";
f[5] = "bcdb9477a7ec6b2673843d431fd5e8e1";
f[6] = "10fa0aea0c1358778bca6944b98f7fe0";
f[7] = "5c9062e93877684cfcefbe7925a70ccf";
f[8] = "c11557291b2dd6ac394038ae76ee92c5";
f[9] = "1116d70f3af1555dd95b361a7619eb1b";
f[10] = "6062c921e0618f1a9f771310d99d686c";
f[11] = "c7a330711c08dd60ca28aa7bcd3019a3";
f[12] = "1d0185e4efea01f609610ed385608eef";
f[13] = "61849ff92df86a5e8429cccf7b8fc94c";
f[14] = "de7b460cc46a1929c59ac3b2d6b72ff7";
f[15] = "360f336a53e58377c47b84a2b13ec2d3";
f[16] = "6384e2b2184bcbf58eccf10ca7a6563c";
f[17] = "bb110a454fadd9b811fcb54b061619c9";
f[18] = "39db4ab55e2a282f9f4a9eed8c5ecb5e";
f[19] = "75116764ed0b169835d6637063c4bc66";
f[20] = "458c37724b07758259619017ccc86376";
f[21] = "39fd69443e0862dd8fb996c9d9c1b57c";
f[22] = "7908f0c548340f5428dea4dc2b170e9f";
f[23] = "efeb4b863729da4cb8574c1465c0b975";
f[24] = "3f50ef7f9058f13e1cea24ddb173b65f";
f[25] = "88e84b57d53704f7a247c5680790c3df";
f[26] = "f4f52c274b8b0af7593e8d85f45ae7f1";
f[27] = "437076fe7e888805e296aeef78dc06e0";
f[28] = "8fd97ba6e064d344e7896a4d55121a41";
f[29] = "6384e2b2184bcbf58eccf10ca7a6563c";
f[30] = "4416400ad27ac0a8c055d7c8d031a2eb";
f[31] = "9910399ecd5ab6bc56440cb756b264a6";
f[32] = "fe6feb98b00d43a5b194cc47b76fcf1f";
f[33] = "45da71f97c5a7e712c07c4f2619e3999";
f[34] = "9d2dd9cca898f093f27bd84816230e4d";
f[35] = "46d926caf23474522cad105f3aafd658";
f[36] = "aa47f8215c6f30a0dcdb2a36a9f4168e";
f[37] = "5088af299f7e58722fffff02436c6eda";
f[38] = "ac426727339e0e744c2704d35fbde3f8";
f[39] = "8c8798a5207fe4b9291133d61edbc13c";
f[40] = "98ee0d25adb1771ee4f8a99f76c31ee7";
f[41] = "fb39327dd0a082b15ebf12cfbe51e117";

var rand_no = Math.ceil(6*Math.random())-1;
mp3title[0] = f[rand_no];
var rand_no = Math.ceil(6*Math.random())+5;
mp3title[1] = f[rand_no];
var rand_no = Math.ceil(6*Math.random())+11;
mp3title[2] = f[rand_no];
var rand_no = Math.ceil(6*Math.random())+17;
mp3title[3] = f[rand_no];
var rand_no = Math.ceil(6*Math.random())+23;
mp3title[4] = f[rand_no];
var rand_no = Math.ceil(6*Math.random())+29;
mp3title[5] = f[rand_no];
var rand_no = Math.ceil(6*Math.random())+35;
mp3title[6] = f[rand_no];

function g(a,n)
{
n = n.replace(/\,/g,"");
n = n.toLowerCase();
o = hex_md5(n);
box = document.getElementsByTagName("td").item(18-a*2);

if (mp3title[a] == o)
{
 alert("Risposta esatta");
box.style.backgroundColor="#00FF00";

} else {
 alert("Risposta sbagliata");
box.style.backgroundColor="#FF0000";
}
}

if(typeof(TagTooga) == 'undefined') 
	TagTooga = {} 

TagTooga.Mp3 = 
{ 
	playimg: null, 
	player: null, 

	go: function() 
		{ 
				var img = document.createElement('img');
				img.src = mp3PlayButton;
				img.title = 'listen'; 
				img.style.marginRight = '0.5em';
				img.style.cursor = 'pointer';
				img.onclick = TagTooga.Mp3.makeToggle(img, mp3url+mp3title[0]+".mp3");
				box = document.getElementsByTagName("td").item(5);
				box.removeChild(box.firstChild);
				box.appendChild(img);
				box = document.getElementsByTagName("td").item(18);
				box.style.textDecoration="blink"; 
		}, 

	toggle: function(img, url) 
		{ 
		if (TagTooga.Mp3.playimg == img) 
{

			TagTooga.Mp3.destroy();

	var oButton = new Array();
	var oField = new Array();
for (var a = 0; a < 7 ; a++) {
        oField[a]=document.createElement("INPUT");
        oField[a].setAttribute("type","text");
        oField[a].setAttribute("id",a);
        oButton[a]=document.createElement("BUTTON");
	oButton[a].appendChild(document.createTextNode("OK"));
        oButton[a].setAttribute("name",a);
	oButton[a].onclick=
function()
        {
	box = document.getElementById(this.name);
	g(this.name,box.value);
        }
}

				numero = document.getElementsByTagName("td").item(3).innerHTML;
if (mp3>6) {
mp3=0;
rigiro++;
}
				if (numero < 1) alert ("Tempo scaduto");
				else
img = document.getElementsByTagName("img").item(0);
img.onclick = TagTooga.Mp3.makeToggle(img, mp3url+mp3title[mp3]+".mp3");

if (mp3 == 0) {
				box1 = document.getElementsByTagName("td").item(18);
				box1.style.textDecoration="blink"; 
				box1 = document.getElementsByTagName("td").item(6);
				box1.style.textDecoration="none"; 
} else {
				box1 = document.getElementsByTagName("td").item(18-mp3*2);
				box1.style.textDecoration="blink"; 
				box1 = document.getElementsByTagName("td").item(20-mp3*2);
				box1.style.textDecoration="none"; 

}

if (rigiro == 0) {
box = document.getElementsByTagName("td").item(21-mp3*2);
box.removeChild(box.firstChild);
box.appendChild(oField[mp3-1]);
box.appendChild(oButton[mp3-1]);
}
if (mp3 == 0 && rigiro == 1) {
box = document.getElementsByTagName("td").item(21-7*2);
box.removeChild(box.firstChild);
box.appendChild(oField[6]);
box.appendChild(oButton[6]);
}

mp3++;

}
		else 
		{ 
		if (TagTooga.Mp3.playimg) 
			TagTooga.Mp3.destroy();
		var a = img.nextSibling;
	var thread = createCounter();
        activeThreads.push(thread);
        thread.start();

		img.src = mp3StopButton; 
		img.title = 'stop'; 
		TagTooga.Mp3.playimg = img; 
		TagTooga.Mp3.player = document.createElement('span');
		TagTooga.Mp3.player.innerHTML = '<object style="vertical-align:bottom;margin-right:0.2em" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"' +
'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"' +
			'width="1" height="1" id="player" align="middle">' +
			'<param name="wmode" value="transparent" />' +
			'<param name="allowScriptAccess" value="sameDomain" />' +
			'<param name="flashVars" value="theLink='+url+'" />' +
			'<param name="movie" value="http://www.blia.it/giochi/musicgame/playMp3.swf" /><param name="quality" value="high" />' +
			'<embed style="vertical-align:bottom;margin-right:0.2em" src="http://www.blia.it/giochi/musicgame/playMp3.swf" flashVars="theLink='+url+'"'+
			'quality="high" wmode="transparent" width="1" height="1" name="player"' +
			'align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"' +
			' pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
		img.parentNode.insertBefore(TagTooga.Mp3.player, img.nextSibling);
		}
		}, 

	destroy: function() 
	{ 
		TagTooga.Mp3.playimg.src = mp3PlayButton; 
		TagTooga.Mp3.playimg = null; 
		TagTooga.Mp3.player.removeChild(TagTooga.Mp3.player.firstChild); 
		TagTooga.Mp3.player.parentNode.removeChild(TagTooga.Mp3.player); 
		TagTooga.Mp3.player = null;
	}, 

	makeToggle: function(img, url) 
	{ 
		return function()
		{ 
			TagTooga.Mp3.toggle(img, url);
		}
	} 
} 

TagTooga.addLoadEvent = function(f) 
{ 
	var old = window.onload;
	
	if (typeof old != 'function') 
		window.onload = f;
	else 
		{ 
		window.onload = function() { old(); f() }
		} 
} 

TagTooga.addLoadEvent(TagTooga.Mp3.go);
