// La table de Tjahzi
// ------------------
// (c) Stéphane Hardy 2002-2011
// http://www.thorgal-bd.fr/

this.ligne=1;
this.colonne=0;
var result=new Array(0,0,0,0,0);
var essai=new Array(0,0,0,0,0);
var result_eff=new Array(0,0,0,0,0);

for (i=1;i<=4;i++){result[i]=Math.round(Math.random()*(8-1)+1)}

function tjahzi(perso){
if (this.result==1||this.colonne==4)return true;
this.colonne++;
c_nav("l"+this.ligne+"_"+this.colonne).innerHTML="<img src='images/tjahzi/"+perso+".gif'>";
essai[this.colonne]=perso;
}

function tj_retour(){
if (this.colonne<1)return true;
c_nav("l"+this.ligne+"_"+this.colonne).innerHTML="";
essai[this.colonne]=0;
this.colonne--;
}

function verifier(){
if (this.result==1)reset();
var victoire=0;
var perso_trouve="";
if (essai[1]==0||essai[2]==0||essai[3]==0||essai[4]==0)return true;
for (i=1;i<=4;i++){
if (essai[i]==result[i]){
perso_trouve=perso_trouve+"<img src='images/tjahzi/r1.gif'>";
essai[i]=0;
result_eff[i]=1;
victoire++;}}
if (victoire==4)ouais();
for (i=2;i<=4;i++){
if (essai[1]==result[i]&&result_eff[i]==0){
perso_trouve=perso_trouve+"<img src='images/tjahzi/r2.gif'>";
essai[1]=0;
result_eff[i]=1;}}
for (i=1;i<=4;i++){
if (i==2)i++;
if (essai[2]==result[i]&&result_eff[i]==0){
perso_trouve=perso_trouve+"<img src='images/tjahzi/r2.gif'>";
essai[2]=0;
result_eff[i]=1;}}
for (i=1;i<=4;i++){
if (i==3)i++;
if (essai[3]==result[i]&&result_eff[i]==0){
perso_trouve=perso_trouve+"<img src='images/tjahzi/r2.gif'>";
essai[3]=0;
result_eff[i]=1;}}
for (i=1;i<=3;i++){
if (essai[4]==result[i]&&result_eff[i]==0){
perso_trouve=perso_trouve+"<img src='images/tjahzi/r2.gif'>";
essai[4]=0;
result_eff[i]=1;}}
if (essai[1]!=0&&essai[2]!=0&&essai[3]!=0&&essai[4]!=0)perso_trouve=perso_trouve+"<img src='images/tjahzi/r3.gif'>";
c_nav("r"+this.ligne).innerHTML=perso_trouve;
for (i=1;i<=4;i++){
result_eff[i]=0;
essai[i]=0;}
this.ligne++;
this.colonne=0;
if (this.ligne==11&&victoire<=3)booof();
}

function ouais(){
this.victoire=1;
for (i=1;i<=4;i++){c_nav("res_"+i).innerHTML="<img src='images/tjahzi/"+result[i]+".gif'>";}
this.result=1;
c_nav("bulle").innerHTML="<table border='0' cellpadding='0' cellspacing='0' width='290' height='300' background='images/legende/bulle2.gif'><td width='290' height='39' colspan='3'></td></tr><tr><td width='44' height='156'></td><td width='208' height='156' align='center'><font face='Tahoma' size='4' color='black'><b>Félicitations... et merci !<br><br>Appuyer sur <b>&quot;Jouer&quot;</b> pour une nouvelle histoire.</b></font></td><td width='48' height='156'></td></tr><tr><td width='290' height='105' colspan='3'></td></tr></table>";
}

function booof(){
for (i=1;i<=4;i++){c_nav("res_"+i).innerHTML="<img src='images/tjahzi/"+result[i]+".gif'>";}
this.result=1;
c_nav("bulle").innerHTML="<table border='0' cellpadding='0' cellspacing='0' width='290' height='300' background='images/legende/bulle2.gif'><td width='290' height='39' colspan='3'></td></tr><tr><td width='44' height='156'></td><td width='208' height='156' align='center'><font face='Tahoma' size='4' color='black'><b>Quel dommage...<br><br>Appuyer sur <b>&quot;Jouer&quot;</b> pour une nouvelle histoire.</b></font></td><td width='48' height='156'></td></tr><tr><td width='290' height='105' colspan='3'></td></tr></table>";
}

function reset(){location.href="thorgal_table_de_tjahzi.php";}

function fenetre(){
if(this.victoire==1||this.ligne==11)return;
if (document.all){var t=document.body.clientHeight/2;var g=(document.body.clientWidth-500)/2;}
if (!document.all){var t=window.innerHeight/2;var g=(window.innerWidth-500)/2;}
c_nav("fond").style.visibility="hidden";
c_nav("ivaldir").style.visibility="visible";
c_left("ivaldir",g);
c_top("ivaldir",t-60);
}

function eff(){
c_nav("fond").style.visibility="visible";
c_nav("ivaldir").style.visibility="hidden";
}
