<!--
var t, im, im_old, last_id, li, li_old, clicks;
var odd = secure = true;
var inter = start_time = clicks = 0;

function make(id,with_id,name)
{
	if ( inter == 0 )
	{
		document.getElementById("timer").innerHTML = "Игра началась!";
		start_time = new Date().getTime();
		inter = setInterval ( "print_timer()", 200 );
	}

	if ( secure )
	{
		im = document.getElementById(id);
		im_old = document.getElementById(last_id);

		if ( last_id != id && ( !im.style.background || strpos(im.style.background,"card_back.png") ) )
		{
			clicks += 1;
			
			li = document.getElementById(id + "_li");
			li_old = document.getElementById(last_id + "_li");
			
			im.style.background = "url(\"photos/" + id + ".jpg\") no-repeat";
			im.innerHTML = "<span class=\"names\">" + name + "</span>";

			if ( odd ) //Просто открываем карту
			{
				odd = false;
				last_id = id;
			}
			else //Проверяем, совпало или нет
			{
				odd = true;
				if ( with_id == last_id )
				{
					li.style.background = li_old.style.background = "url(\"images/highlight.gif\") no-repeat";
					pairs--;
				}
				else
				{
					li.style.background = li_old.style.background = "url(\"images/highlight_wrong.gif\") no-repeat";
					secure = false;
					setTimeout("clear_stuff()",700);
				}

				if ( !pairs )
				{
					clearInterval(inter);
					document.getElementById("timer").innerHTML = "Игра окончена! Вы&nbsp;всех угадали за" +  timer() + "!";
					pairs++; //Чтобы несколько раз не вылезало сообщение
				}
			} //odd
		}
	} //secure

	return false;
}

function clear_stuff ()
{
	im.style.background = im_old.style.background = "url(\"images/card_back.png\") no-repeat";
	li.style.background = li_old.style.background = "url(\"images/white.gif\") no-repeat";
	im.innerHTML = im_old.innerHTML = "";
	last_id = "";
	secure = true;
}

function print_timer()
{
	tm = document.getElementById("timer");
	tm.innerHTML = "Играем уже" + timer() + ".";
}

function timer()
{
	var rtn = "";

	game_time = Math.floor ( ( new Date().getTime() - start_time ) / 1000 );
	var minutes = Math.floor (game_time/60);
	var seconds = game_time%60;
	
	if ( game_time >= 60 )
	{
		rtn += " " + minutes + "&nbsp;минут" + decliner(minutes,"у","ы","");
	}

	if ( seconds )
	{
		rtn += " " + seconds + "&nbsp;секунд" + decliner(seconds,"у","ы","");
	}

	rtn += " и&nbsp;" + clicks + "&nbsp;клик" + decliner(clicks,"","а","ов");

	return rtn;
}

function decliner(n, one, two, five)
{
	var val;

	if ( n%10 == 1 && n%100 != 11)
		val = one;
	else if ( n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) )
		val = two;
	else
		val = five;

	return val;
}

function strpos (haystack, needle, offset)
{
	var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
	return i === -1 ? false : i;
}
//-->