function tooglecard (id, src) {
	
	// if stop do nothing
	if (start==false) {
		return false;
	}
	
	// if two cards already showed, do nothing
	if (showedCards==2) {
		return false;
	}
	
	//alert(document.getElementById(id).src);
	//return false;
	
	if (document.getElementById(id).src!='http://www.zimmerfrei.li/memosan/cards/back.gif' &&
		document.getElementById(id).src!='http://zimmerfrei.playme.ch/memosan/cards/back.gif'
		) {
		return false;
	}
	
	// show the card
	document.getElementById(id).src = "cards/"+src;
	
	if (lastCardId=="") {
		// first card 
		showedCards=1;
		document.getElementById("debug1").childNodes[0].nodeValue=showedCards;
		
		lastCardSrc=document.getElementById(id).src;
		lastCardId=id;
	} else {
		// second card
		showedCards=2;
		document.getElementById("debug1").childNodes[0].nodeValue=showedCards;
		
		if (lastCardSrc==document.getElementById(id).src) {
			// same cards
			totalShow=totalShow+2;
			document.getElementById("debug2").childNodes[0].nodeValue=totalShow;
			checkFinish();
			// reset
			showedCards=0;
			document.getElementById("debug1").childNodes[0].nodeValue=showedCards;

			lastCardId="";
			lastCardSrc="";
		} else {
			// different cards, wait and return to back
			setTimeout("recover('"+id+"','"+lastCardId+"');showedCards=0;lastCardId='';lastCardSrc='';",1000);
			document.getElementById("debug1").childNodes[0].nodeValue=showedCards;
		}
		

	}
}

function recover(id,lastCardId) {
	document.getElementById(lastCardId).src = "cards/back.gif";
	document.getElementById(id).src = "cards/back.gif";
}

function play() {

	// 
	start=true;

	// off game
	document.getElementById('playground_cover').style.display = 'none';
	document.getElementById('play').style.display = 'none';
	document.getElementById('logo').style.display = 'none';
	document.getElementById('highscore').style.display = 'none';
	document.getElementById('credits').style.display = 'none';
	document.getElementById('instructions').style.display = 'none';
	document.getElementById('order').style.display = 'none';
	document.getElementById('beta').style.display = 'none';
	
	// on game
	document.getElementById('stop').style.display = 'block';
	document.getElementById('timerstar').style.display = 'block';
	document.getElementById('timer').style.display = 'block';
	
	// start timer
	gametime=setInterval("setTime()",1000)
}

function setTime() {
	var s=document.getElementById("time").childNodes[0].nodeValue;
	s++;
	document.getElementById("time").childNodes[0].nodeValue=s;
	document.getElementsByName('timehighscore')[0].value=s;
}

function checkFinish() {
	if (totalShow==24) {
		// stop timer
		clearInterval(gametime);
		// recover
		document.getElementById('playground_cover').style.display = 'block';
		// show all pictures
		showAllPictures();
		// show the highscore input
		document.getElementById('highscore_input').style.display = 'block';
	}
}

function stopdebug() {
	// stop timer
	clearInterval(gametime);
	// recover
	document.getElementById('playground_cover').style.display = 'block';
	// show all pictures
	showAllPictures();
	// show the highscore input
	document.getElementById('highscore_input').style.display = 'block';
}

function showAllPictures() {
	var counter=1;
	for(i=0;i<(Cards.length*2);i++) {
		if (counter<7) {
			document.getElementById("c"+counter).src = "cards/"+Cards[i];
		} else if (counter>12 && counter<19) {
			document.getElementById("c"+counter).src = "cards/"+Cards[i-6];
		} else {
			document.getElementById("c"+counter).src = "cards/back.gif";
		}
		counter=counter+1;
	}
	
	for(j=1;j<=12;j++) {
		document.getElementById("b"+j).style.display = 'block';
	}
}

function saveHighScore() {
	// time=document.getElementById("time").childNodes[0].nodeValue;
	// document.getElementsByName('timehighscore')[0].value=time;
	// document.mainForm.submit();
	// alert(document.getElementsByName('timehighscore')[0].value);
}

function credits() {
	document.getElementById('credits').style.display = 'block';
	document.getElementById('instructions').style.display = 'none';
	document.getElementById('order').style.display = 'none';
}

function instructions() {
	document.getElementById('instructions').style.display = 'block';
	document.getElementById('credits').style.display = 'none';
	document.getElementById('order').style.display = 'none';
}

function order() {
	document.getElementById('order').style.display = 'block';
	document.getElementById('credits').style.display = 'none';
	document.getElementById('instructions').style.display = 'none';
}

function pausecomp(millis)  {
	date = new Date();
	var curDate = null;

	do { var curDate = new Date(); } 
	while(curDate-date < millis);
} 


function decision(message, url)
{
	if(confirm(message)) location.href = url;
}

function setDisplay(the_div,disp){
	if (document.getElementById)
	{
		document.getElementById(the_div).style.display = disp;
	}
	else if (document.all)
	{
		document.all[the_div].style.display = disp;
	}
}

function noSpam(user,domain)
{
	window.location = "mailto:" + user + "@" + domain;
	return false;
}

