var xmlhttp, alerted, imgAr
var klikMag = true
var vraagtekenNaam
var hebVraagtekenNaam = false
var firstKlik = true
var visiCount = 0
var imvraagteken = new Image();
var soundselector;

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (e) {
   alert("Your browser does not support xmlhttp.\nThat is required.")
  }
 }
@else
 alert("Your browser does not support jscript version >= 5.\nThat is required.")
 xmlhttp=false
 alerted=true
@end @*/
if (!xmlhttp && !alerted) {
 try {
  xmlhttp = new XMLHttpRequest();
 } catch (e) {
  alert("Sorry, your browser does not support XMLHttpRequest.\nBrowserChess requires that.")
 }
}

// Get the browsertype
var browser = '';
if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  browser = "Netscape"
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
  browser = "Microsoft"
 }
}

function DoOnLoad()
{
// Get the soundselector
soundselector = document.getElementById('soundselector');

GetPictNames();
}	// End DoOnLoad


function GetPictNames()
{
if ( browser != "Microsoft" )
{
	xmlhttp = null;
	xmlhttp = new XMLHttpRequest();
}
var rand = Math.random();
xmlhttp.open("GET",pageUrl + "?comm=getpictnames" + "&kcount=" + kaartCount + "&rand=" + rand , false);
xmlhttp.send(null)
reply = xmlhttp.responseText.replace('\n','')
TimgAr = reply.split(';')
imgAr = new Array(kaartCount)
for ( t=0; t<=kaartCount-1; t++ )
{
	imgAr[t] = TimgAr[t]
}
// preload them
plaatje = new Image();
for ( i=0; i<imgAr.length; i++ )
{
plaatje.src = imgAr[i];
}
}	// End GetPictNames

function Evaluate()
{
var wasError = false
imgNamen = new Array(kaartCount)
for ( i=0; i<=kaartCount-1; i++ )
{
	var img = document.getElementById(i)
	imgNamen[i] = img.src
}
for ( i=0; i<=kaartCount-1; i++ )
{
	if ( imgNamen[i] != vraagtekenNaam )
	{
		var dezeCount = 0
		for ( j=0; j<=kaartCount-1; j++ )
		{
			if ( imgNamen[i] == imgNamen[j] && i != j )
			{
				dezeCount++
			}
		}
		if ( dezeCount < 1 )
		{
			document.getElementById(i).src = imvraagteken.src	
			wasError = true
			PlaySound('errsound')
		}
	}
}
if ( !wasError )
{
PlaySound('tadasound')
}
var hoera = true
for ( i=0; i<=kaartCount-1; i++ )
{
	if ( imgNamen[i] == vraagtekenNaam )
	{
		hoera = false
	}
}
if ( hoera )
{
	HoeraAan();
	StartKnopAan();
}

document.body.style.cursor = "auto";
klikMag = true
}	// End Evaluate

function StartKnopAan()
{
document.getElementById('sknop').style.visibility = "visible"
}

function HoeraAan()
{
for ( i=0; i<=3; i++ )
{
	id = 'hoera' + i
	document.getElementById(id).style.visibility = "visible"
}
PlaySound('hoerasound')
}

function HoeraUit()
{
for ( i=0; i<=3; i++ )
{
	id = 'hoera' + i
	document.getElementById(id).style.visibility = "hidden"
}
}

function PlaySound(soundname)
{
if ( browser != "Microsoft" ) { return; }
if ( soundname != 'clicksound' )
{
	if ( !soundselector.checked  ) { return; }
}
var sound = eval("document." + soundname )
try
{
sound.Stop()
sound.Rewind()
} catch(e) {}
try
{
sound.DoPlay()
}
catch(e)
{
sound.Play()
}
}	// End PlaySound

function NewGame()
{
HoeraUit();
document.body.style.cursor = "wait";
GetPictNames()
for ( i=0; i<=kaartCount-1; i++ )
{
	document.getElementById(i).src = vraagtekenNaam
}
document.getElementById('sknop').style.visibility = "hidden"
document.body.style.cursor = "auto";
}

function DoeKaartKlik(id)
{
if ( !klikMag ) { return }
//alert(id)
var imName = imgAr[id]
if ( !hebVraagtekenNaam )
{
	vraagtekenNaam = document.getElementById(id).src
	imvraagteken.src = vraagtekenNaam
	hebVraagtekenNaam = true
}

// Klik op een zichtbaar plaatje, niets doen
if ( document.getElementById(id).src != vraagtekenNaam ) { return }

PlaySound('clicksound')
document.getElementById(id).src = imName
self.status = imName
//debugger
visiCount++
if ( visiCount/2 == Math.floor(visiCount/2) )
{
	klikMag = false;
	document.body.style.cursor = "wait";
	setTimeout("Evaluate()",3000)
}

}	// End DoeKaartKlik()

var rPlNr = 0
var plaatjeNr = 0
function FlipCards()
{
// Get picture names
kaartCount = 20
if ( browser != "Microsoft" )
{
	xmlhttp = null;
	xmlhttp = new XMLHttpRequest();
}
var rand = Math.random();
xmlhttp.open("GET",pageUrl + "?comm=getpictnames" + "&kcount=" + kaartCount + "&rand=" + rand , false);
xmlhttp.send(null)
reply = xmlhttp.responseText.replace('\n','')
TimgAr = reply.split(';')
imgAr = new Array(kaartCount)
plaatjesAr = new Array(kaartCount)
for ( t=0; t<=kaartCount-1; t++ )
{
	imgAr[t] = TimgAr[t]
}
// preload them
plaatje = new Image();
for ( i=0; i<imgAr.length; i++ )
{
	plaatje.src = imgAr[i]
}
setTimeout("FlipEm()",3000)
//document.getElementById('i0').src = imgAr[0]
}	// End FlipCards

function xFlipEm()
{
//imgNr = Math.floor(Math.random() * 3 + 1 );
document.getElementById('i' + rPlNr).src = imgAr[plaatjeNr]
rPlNr++
if ( rPlNr == 4 )
{
	rPlNr = 0
}
plaatjeNr++
if ( plaatjeNr == kaartCount )
{
	plaatjeNr = 0
}
setTimeout("FlipEm()",7000)
}	// End FlipEm

function yFlipEm()
{
//imgNr = Math.floor(Math.random() * 3 + 1 );
document.getElementById('i' + rPlNr).style.filter="blendTrans(duration=2)"
document.getElementById('i' + rPlNr).filters.blendTrans(duration=2).Apply()
document.getElementById('i' + rPlNr).filters.blendTrans.Play()
document.getElementById('i' + rPlNr).src = imgAr[plaatjeNr]
rPlNr++
if ( rPlNr == 4 )
{
	rPlNr = 0
}
plaatjeNr++
if ( plaatjeNr == kaartCount )
{
	plaatjeNr = 0
}
setTimeout("FlipEm()",7000)
}	// End FlipEm

function FlipEm()
{
//imgNr = Math.floor(Math.random() * 3 + 1 );
document.getElementById('i' + rPlNr).style.filter="revealTrans(duration=3,transition=10)"
document.getElementById('i' + rPlNr).filters.revealTrans(duration=3,transition=10).Apply()
document.getElementById('i' + rPlNr).filters.revealTrans.Play()
document.getElementById('i' + rPlNr).src = imgAr[plaatjeNr]
rPlNr++
if ( rPlNr == 4 )
{
	rPlNr = 0
}
plaatjeNr++
if ( plaatjeNr == kaartCount )
{
	plaatjeNr = 0
}
setTimeout("FlipEm()",7000)
}	// End FlipEm
