
function epd_set(position_number)
{
	for(i = 0; i < ids.length; i++){
		if(ids[i] == position_number){
			currentarrayindex = i;
			parent.replay.document.replay.SetVariable("Position", positions[i]);
		}
	}
	if(position_number != 0)
	{
		if(oldindex != null) {
			var oe = document.getElementById("id"+oldindex);
			oe.style.color = oldcolor;
			oe.style.background = oldbackground;
		}

		var ne = document.getElementById("id"+position_number);

		oldindex = position_number;
		oldcolor = ne.style.color;
		oldbackground = ne.style.background;

		ne.style.color = "white";
		ne.style.background = "red";
		ne.scrollIntoView();
	}
}


function epd_start()
{
	currentarrayindex = 0;
	parent.replay.document.replay.SetVariable("Position", positions[0]);
}


function epd_next()
{
	var v = variation[currentarrayindex];
	var found = 0;

	if(currentarrayindex  < (ids.length - 1))
	{
		for(i = (currentarrayindex + 1); i < ids.length; i++)
		{
			if(variation[i] == v)
			{
				epd_set(ids[i]);
				i = ids.length;
				found = 1;
			}
		}
	}

	if(found == 0)
	{ isplay = 0; }
}


function epd_previous()
{
	var v = variation[currentarrayindex];

	if(currentarrayindex > 0)
	{
		for(i = (currentarrayindex - 1); i >= 0; i--)
		{
			if(variation[i] == v)
			{
				epd_set(ids[i]);
				i = -1;
			}
		}
	}
}


function epd_final()
{
	var v = variation[0];
	var ls = 0;

	for(i = 0; i < ids.length; i++)
	{
		if(variation[i] == v)
		{
			ls = ids[i];
			currentarrayindex = i;
		}
	}

	epd_set(ls);
}
