﻿			var totalPerso = 0;
			var totalTexts = 0;
			
			var myPersos = new Array('hmjmps','hapowr','hfcmbt','hfjmps','hflthr','hfmaxx','hfmetl','hmbjmp','nmpeas','nmmaxx','nmlthr','nmlosr','nmgrch','nmdocc','nmbsnp','nmbrlp','nmbpea','nfvred','nftrmp','nfpeas','nfmetl','nfmaxx','nfbrlp','napowr','naghul','hmmetl','hmmaxx','hmlthr','hmcmbt','hmbmet', 'mabrom', 'maddog','mamrat');
			var mySpecialPersos = new Array();
			var myOrientations = new Array('e','ne','nw','se','sw','w');
			var myAnims = new Array('aa','ak');
			
			var brahminStop = false;
			
			function addPerso(x,y, type, orientations, speakM)
			{
				var perso = new myPerso(x,y, type, orientations, speakM);

			}
			
			function myPerso(x,y, type, orientations, speakM)
			{
				myDoc = document.getElementById("main");
				thePerso = type;
				theOrien = orientations;
				myNum = totalPerso;
				
				var alignement = document.createAttribute("onmousedown");
				if(orientations == 'random')
				{
					theOrien = Math.floor(Math.random()*myOrientations.length);
				}
				
				if(type == 'random')
				{
					thePerso = Math.floor(Math.random()*(myPersos.length-3));
				}
				else if (type == 'brahmine')
				{
					thePerso = myPersos.length-3;
					alignement.nodeValue = "destroyBrahmine('"+myNum+"', "+theOrien+");";
				}
				else if (type == 'dog')
				{
					thePerso = myPersos.length-2;
				}	
				else if (type == 'rat')
				{
					thePerso = myPersos.length-1;
				}
				
				nL = document.createElement("div");
				nL.id = "perso_"+myNum;
				nL.style.position = "absolute" 
				nL.style.left = x+"px";
				nL.style.top = y+"px";
				nL.style.zIndex = 10;
				nI = document.createElement("img");
				nI.src = 'perso/'+myPersos[thePerso]+'ss_'+myOrientations[theOrien]+'.gif';
				
 				nI.setAttributeNode(alignement);
				nL.appendChild(nI);
				myDoc.appendChild(nL);
				totalPerso++;
			
				
				timer = setTimeout("animate("+myNum+","+thePerso+","+theOrien+")", Math.floor(8000+Math.random()*8000));
				if (speakM == true) timerB = setTimeout("speak("+myNum+")", Math.floor(10000+Math.random()*15000));
			}
			
			function destroyBrahmine(name, refC)
			{
				myDoc = document.getElementById("perso_"+name)
				myDoc.firstChild.src = 'perso/mabromex_'+myOrientations[refC]+'.gif';
			}
			 
			function speak(ref)
			{
				myNum = totalTexts;
				nL = document.createElement("div");
				nL.id = "text_"+myNum;
				nL.style.position = "absolute" 
				myDoc = document.getElementById("perso_"+ref)
				nL.style.zIndex = 11;
				nL.style.left = -100+"px";
				nL.style.top = -50+"px";
				nI = document.createElement("img");
				nI.src = "texts/" + Math.floor(Math.random() * 18) +".gif";
				nL.appendChild(nI);
				myDoc.appendChild(nL);
				totalTexts++;
				timerA = setTimeout("removeText("+myNum+","+ref+")", 6000);
				timerB = setTimeout("speak("+ref+")", Math.floor(10000+Math.random()*15000));
			}
				
			function removeText(ref, perso)
			{
				myDocA = document.getElementById("text_"+ref)
				
				myDocB = document.getElementById("perso_"+perso);

				myDocB.removeChild(myDocA);
			}
			
			function animate(refA, refB, refC)
			{
				myDoc = document.getElementById("perso_"+refA)
				theAnim = Math.floor(Math.random()*myAnims.length);
				myDoc.firstChild.src = 'perso/'+myPersos[refB]+myAnims[theAnim]+'_'+myOrientations[refC]+'.gif';
				if (refB==30 && brahminStop == true)
				{
					timer = setTimeout("animate("+refA+","+refB+","+refC+")", Math.floor(8000+Math.random()*8000));
				}
			}
