document.write("<bgsound src='#' id=music loop=1 autostart='true'>")
document.write("<div id='but301' style='position: absolute; top:10px; left:435px'>")
document.write("<a href='javascript:startgame(301)'><img src='301.gif' border=0></a></div>")
document.write("<div id='but501' style='position: absolute; top:10px; left:515px'>")
document.write("<a href='javascript:startgame(501)'><img src='501.gif' border=0></a></div>")
document.write("<div id='tekst' style='position: absolute; top:50px; left:90px'>")
document.write("<form name='message'>")
document.write("<input type='text' value='' name='waarde' size=30>")
document.write("</form>")
document.write("</div>")
document.write("<DIV id='res' style='position: absolute; top:350px; left:650px'>")
document.write("<input type='reset' value='Restart' onclick='javascript:reload()'>")
document.write("</div>")
document.write("<DIV id='dartbord' style='position: absolute; top:80px; left:40px'>")
document.write("<img src='dartbord.png'>")
document.write("</div>")
document.write("<DIV id='scorebord' style='position: absolute; top:200px; left:440px'>")
document.write("<img src='scorebord.gif'>")
document.write("</div>")
document.write("<table border=0><tr><td width=20><DIV ID='ticker1' style='position:absolute; top:215px; left:470px'></DIV></td></tr></table>")
document.write("<table border=0><tr><td width=20><DIV ID='ticker2' style='position:absolute; top:215px; left:525px'></DIV></td></tr></table>")
document.write("<DIV id='plaats1' style='position: absolute; top:150px; left:400px; visibility:hidden'>")
document.write("<img src='plaats.gif' name='pijl1'>")
document.write("</div>")
document.write("<DIV id='plaats2' style='position: absolute; top:150px; left:400px; visibility:hidden'>")
document.write("<img src='plaats.gif' name='pijl2'>")
document.write("</div>")
document.write("<DIV id='plaats3' style='position: absolute; top:150px; left:400px; visibility:hidden'>")
document.write("<img src='plaats.gif' name='pijl3'>")
document.write("</div>")
document.write("<DIV id='bal' style='position: absolute; top:40px; left:440px'>")
document.write("<a href='javascript:StopBall()'><img src='vierkant.gif' border=0></a>")
document.write("</div>")
document.write("<DIV id='uitleg' style='position: absolute; top:20px; left:615px'>")
document.write("<table border=0><tr><td width=210>")
document.write("How to play...<br><hr>")
document.write("First click the button of the game you want to play, 301 or 501.<br><br>Then you click the red ball to aim your shot. Release it when the pointer reaches the right point. Do this again to obtain the right height. Then the arrow will be trown. You must finish with a double!<br><br> The outside ring doubles its value, the inner ring tripples its value. The red centre gives you 25 points and the black centre means 50 points.")
document.write("</td></tr></table>")
document.write("</div>")
document.write("<div id='point1' STYLE='position:absolute;visibility:visible;'>")
document.write("<img src='schuif.gif' width=15 height=15 alt='' border='0'>")
document.write("</div>")
document.write("<div id='point2' STYLE='position:absolute;visibility:visible; top:100px; left:335px'>")
document.write("<img src='schuif.gif' width=15 height=15 alt='' border='0'>")
document.write("</div>")

var XX1=568; 
var XX2=45;
var xstep=1;
var delay_time=10;
var delay_pijl=40;
var stoppen1=false;
var stoppen2=false;
var pijlen=1;
var pijlscore=0;
var pijl1=0;
var pijl2=0;
var pijl3=0;
var info = '';
var info2= '';
var YY1=60;  
var top1=50
var bottom1=170; 
var yon1=0;  
var YY2=560;  
var top2=440;
var bottom2=560; 
var yon2=0;  
var pijltel = 0;
var ZZ1=0;
var ZZ2=0;
var beurt=0;
var gamerun=false;
var krijt = new Array();
var pijltjes = new Array();

for (i=0;i<11;i++) {
  pijltjes[i] = new Image()
  pijltjes[i].src = ' '+ i + '.gif'
}

var ns4=document.layers?1:0
var ie=document.all?1:0
var ns6=document.getElementById&&!document.all?1:0

if(ie){
   point1.style.top=YY1;
   point1.style.left=XX1;
   point2.style.top=XX2;
   point2.style.left=bottom2;
} else { alert('Internet Explorer only !') }

function reloc2() {
  if(yon1==0){YY1=YY1-xstep;}
  else{YY1=YY1+xstep;}
		
  if(YY1<top1){yon1=1;YY1=top1;}
  if(YY1>=bottom1){yon1=0;YY1=bottom1;}
  point1.style.left=XX1;
  point1.style.top=YY1+document.body.scrollTop;}

function reloc1() {
  if(yon2==0){YY2=YY2-xstep;}
  else{YY2=YY2+xstep;}
		
  if(YY2<top2){yon2=1;YY2=top2;}
  if(YY2>=bottom2){yon2=0;YY2=bottom2;}
  point2.style.top=XX2;
  point2.style.left=YY2+document.body.scrollTop;}

function loopfunc1() {
  if (stoppen1) { return }
  reloc1();
  setTimeout("loopfunc1()",delay_time);}

function loopfunc2() {
  if (stoppen2) { return }
  reloc2();
  setTimeout("loopfunc2()",delay_time);}

function animeer1() {
  document.pijl1.src = pijltjes[pijltel].src
  pijltel++;
  if (pijltel < 11) { setTimeout("animeer1()",delay_pijl) }
}
function animeer2() {
  document.pijl2.src = pijltjes[pijltel].src
  pijltel++;
  if (pijltel < 11) { setTimeout("animeer2()",delay_pijl) }
}
function animeer3() {
  document.pijl3.src = pijltjes[pijltel].src
  pijltel++;
  if (pijltel < 11) { setTimeout("animeer3()",delay_pijl) }
}

function StopBall() {
if (!gamerun) { alert('Choose a game first!'); return }
  ZZ1 = YY1-110;
  ZZ2 = YY2-500;
  if (stoppen1) {
    stoppen2 = true;
    stoppen1 = false;
    if (pijlen == 1) {
      plaats1.style.visibility='visible';
      plaats1.style.top=210+(ZZ1*3); //midden top=210, left=187 waardenYY: top50-170 left440-560
      plaats1.style.left=187+(ZZ2*3);
      pijltel = 0;
      animeer1();
      setTimeout("geluid(1)",400);    }
    if (pijlen == 2) {
      plaats2.style.visibility='visible';
      plaats2.style.top=208+(ZZ1)*3; //midden top=210, left=187 waardenYY: top50-170 left440-560
      plaats2.style.left=187+(ZZ2*3);
      pijltel = 0;
      animeer2();
      setTimeout("geluid(2)",400);    }
    if (pijlen == 3) {
      plaats3.style.visibility='visible';
      plaats3.style.top=208+(ZZ1*3); //midden top=210, left=187 waardenYY: top50-170 left440-560
      plaats3.style.left=187+(ZZ2*3);
      pijltel = 0;
      animeer3();
      setTimeout("geluid(3)",400);    }
    pijlen++;
    if (pijlen == 4) {
      setTimeout("opnieuw()",2000);
    } else {
      setTimeout("loopfunc1()",1000);    }  }
  else {
    stoppen1 = true;
    stoppen2 = false;
    loopfunc2();  }}

function score(pl) {
  var hoek=0;
  var factor=1;
  pijlscore=0;
  hoek=Math.atan2(ZZ2,ZZ1);
  if ((hoek<= 2.9800497297791683 )&&(hoek>2.671409189943056)) {pijlscore=1}
  if ((hoek<= 2.671409189943056  )&&(hoek>2.345778200261375)) {pijlscore=18}
  if ((hoek<= 2.345778200261375  )&&(hoek>2.040979790441634)) {pijlscore=4}
  if ((hoek<= 2.040979790441634  )&&(hoek>1.7323392506055215)) {pijlscore=13}
  if ((hoek<= 1.7323392506055215 )&&(hoek>1.4092534029842718)) {pijlscore=6}
  if ((hoek<= 1.4092534029842718 )&&(hoek>1.1006128631481593)) {pijlscore=10}
  if ((hoek<= 1.1006128631481593 )&&(hoek>0.7853981633974483)) {pijlscore=15}
  if ((hoek<= 0.7853981633974483 )&&(hoek>0.47018346364673724)) {pijlscore=2}
  if ((hoek<= 0.47018346364673724)&&(hoek>0.16154292381062482)) {pijlscore=17}
  if ((hoek<= 0.16154292381062482)&&(hoek>-0.1398223687841933)) {pijlscore=3}
  if ((hoek<=-0.1398223687841933 )&&(hoek>-0.4570687565477896)) {pijlscore=19}
  if ((hoek<=-0.4570687565477896 )&&(hoek>-0.7749818734664786)) {pijlscore=7}
  if ((hoek<=-0.7749818734664786 )&&(hoek>-1.0939044591293614)) {pijlscore=16}
  if ((hoek<=-1.0939044591293614 )&&(hoek>-1.4068671609708354)) {pijlscore=8}
  if ((hoek<=-1.4068671609708354 )&&(hoek>-1.734725492618958)) {pijlscore=11}
  if ((hoek<=-1.734725492618958  )&&(hoek>-2.0476881944604317)) {pijlscore=14}
  if ((hoek<=-2.0476881944604317 )&&(hoek>-2.356194490192345)) {pijlscore=9}
  if ((hoek<=-2.356194490192345  )&&(hoek>-2.684523897042004)) {pijlscore=12}
  if ((hoek<=-2.684523897042004  )&&(hoek>-2.9872738776636742)) {pijlscore=5}
  if ((hoek<=-2.9872738776636742 )||(hoek>2.9800497297791683)) {pijlscore=20}
  a=Math.sqrt((ZZ2*ZZ2*9)+(ZZ1*ZZ1*9))
  if (a<=6) { factor=2; }
  if (a<=13) { pijlscore=25; }
  if ((a>=77)&&(a<=85)) { factor=3 }
  if ((a>=128)&&(a<=136)) { factor=2 }
  if (a>136) { factor=0 }
  info='';
  if (factor==2) { info += 'Double ';  }
  if (factor==3) { info += 'Triple ';  }
  if (factor==0) { info += 'You Missed...'; }
  else { info += pijlscore }
  if ((a>6)&&(a<=13)) { info = 'Bull' }
  if (a<=6) { info = 'Bulls Eye !' }
  pijlscore = pijlscore*factor;
  totaalscore = totaalscore-pijlscore;
  if ((totaalscore < 0)||(totaalscore==1)) {
    totaalscore = totaalscore+pijlscore+pijl1+pijl2;
    info += ' - No Score, too much...';
    leeg();
    pl=3;
  } else {
    if (totaalscore==0) {
      if (factor != 2) {
        totaalscore = totaalscore+pijlscore+pijl1+pijl2;
        info += ' - No Score, no double...'
        pl=3;
        leeg();
      } else {
        ap = (beurt*3) + pl;
        info = 'You won!!!\nYou needed '+ap+' arrows !';
        document.message.waarde.value=info;
	beurt++;
	krijt[beurt] = 0;
	bord();
        info += '\n\nPress OK for a new game...';
	alert(info);
	window.location.reload(true);      }
    } else {
      info += ' ('+totaalscore+' left)';    }  }
  document.message.waarde.value=info;
  if (pl == 1) { pijl1 = pijlscore }
  if (pl == 2) { pijl2 = pijlscore }
  if (pl == 3) {
    beurt++
    pijl3 = pijlscore;
    beurtscore = pijl1+pijl2+pijl3;
    if (beurtscore==180) { document.all.music.src="180.wav" }
    info2 += '\n' +totaalscore;
    krijt[beurt]=totaalscore;
    bord();  }}
function leeg() {
      pijl1 = 0;
      pijl2 = 0;
      pijl3 = 0;
      pijlscore=0;
      pijlen=1;
      pl=0;
      plaats1.style.visibility='hidden';
      plaats2.style.visibility='hidden';
      plaats3.style.visibility='hidden';}

function opnieuw() {
  leeg();
  loopfunc1();}

function geluid(pl) {
  document.all.music.src="plok.wav";
  score(pl); }

function bord() {
	b0=0;
	b1=beurt;
	b2=0;
	if (beurt > 8) { b1=8; b2=beurt }
	if (beurt > 17) { b0=beurt-17; b1=beurt-9; b2=beurt }
	messagecontent1='<span style="position:relative;font-family:Arial;color:FFFFFF;font-size:14pt;font-weight:3">'	
	messagecontent1+='<font color="FFFFFF"><i>'
	for (i=b0;i<=b1;i++) {
          if (i!=beurt) { messagecontent1+='<strike>' }
	  messagecontent1+=krijt[i]+' ';
          if (i!=beurt) { messagecontent1+='</strike>' }
	}
	messagecontent1+='</i></font>'
	messagecontent1+='</span>'
	ticker1.innerHTML=messagecontent1 
   if (b2 > 0) {
	messagecontent2='<span style="position:relative;font-family:Arial;color:FFFFFF;font-size:14pt;font-weight:3">'	
	messagecontent2+='<font color="FFFFFF"><i>'
	for (i=b1+1;i<=b2;i++) {
          if (i!=beurt) { messagecontent2+='<strike>' }
	  messagecontent2+=krijt[i]+' ';
          if (i!=beurt) { messagecontent2+='</strike>' }
	}
	messagecontent2+='</i></font>'
	messagecontent2+='</span>'
	ticker2.innerHTML=messagecontent2
   }}

function startgame(spel) {
  if (gamerun) { return }
  gamerun=true;
  info2=spel
  krijt[0]=info2;
  bord()
  if (info2 == '301') { totaalscore = 301 }
  if (info2 == '501') { totaalscore = 501 }
  loopfunc1();}
function reload() {
  results = confirm("Are you sure to restart?");
  if (results=='1') { window.location.reload(true) }}
