<!-- // Copyright Paul Wilkins - Don't Steal
var swap=new Array;
swap[swap.length] = {ch:'q', regex:/q/g, vert:'\/', vregex:/\//g, horiz:'7', hregex:/7/g}
swap[swap.length] = {ch:'\\', regex:/\\/g, vert:'7', vregex:/7/g, horiz:'\/', hregex:/\//g}
swap[swap.length] = {ch:'Q', regex:/Q/g, vert:'Z', vregex:/Z/g, horiz:'E', hregex:/E/g}
swap[swap.length] = {ch:'C', regex:/C/g, vert:'E', vregex:/E/g, horiz:'Z', hregex:/Z/g}
swap[swap.length] = {ch:'w', regex:/w/g, vert:'s', vregex:/s/g, horiz:'w', hregex:/w/g}
swap[swap.length] = {ch:'a', regex:/a/g, vert:'a', vregex:/a/g, horiz:'d', hregex:/d/g}
swap[swap.length] = {ch:'k', regex:/k/g, vert:'l', vregex:/l/g, horiz:'k', hregex:/k/g}
swap[swap.length] = {ch:'K', regex:/K/g, vert:'L', vregex:/L/g, horiz:'K', hregex:/K/g}

var imagePath = "images/";
var image = new Array;
image[" "] = "blank.jpg";
image["*"] = "start.jpg";
image["O"] = "end.jpg";
image["@"] = "player.jpg";
image["X"] = "block.jpg";
image["."] = "path.jpg";
image[","] = "path2.jpg";
image["o"] = "steppath.jpg";
image["'"] = "steppath2.jpg";
image["7"] = "topleft.jpg";
image["q"] = "topright.jpg";
image["\\"] = "botleft.jpg";
image["/"] = "botright.jpg";
image["1"] = "jump1.jpg";
image["2"] = "jump2.jpg";
image["H"] = "hjoin.jpg";
image["I"] = "vjoin.jpg";
image["#"] = "holder.jpg";
image["Q"] = "holdertopleft.jpg";
image["E"] = "holdertopright.jpg";
image["Z"] = "holderbotleft.jpg";
image["C"] = "holderbotright.jpg";
image["w"] = "switchup.jpg";
image["s"] = "switchdown.jpg";
image["a"] = "switchleft.jpg";
image["d"] = "switchright.jpg";
image["k"] = "beamtop.jpg";
image["i"] = "beam.jpg";
image["l"] = "beambot.jpg";
image["K"] = "beamtopoff.jpg";
image["L"] = "beambotoff.jpg";
	
function ShowStep(dir)
{
	if (dir == "prev")
	{
		step--;
		step = (step < 0) ? 0 : step;
	}
	if (dir =="next")
	{
		step++;
		step = (step > line.length) ? line.length : step;
	}
	document.getElementById("prev").style.visibility = (step > 0) ? "" : "hidden";
	document.getElementById("flipVert").style.visibility = (line.length) ? "" : "hidden";
	document.getElementById("flipHoriz").style.visibility = (line.length) ? "" : "hidden";
	document.getElementById("next").style.visibility = (step < line.length-1) ? "" : "hidden";

	var html = Step(step, flipVert, flipHoriz);
	var span = document.createElement("span");
	for (var i=0; i<html.length; i++)
	{
		ch = html.charAt(i);
		switch (ch)
		{
			case "\n":
				elem = document.createElement("br")
				break;
			default:
				elem = document.createElement("img");
				elem.src = imagePath + image[ch];
				elem.width="23";
				elem.height="23";
				break;
		}
		span.appendChild(elem);
}
	var orbox = document.getElementById('orbox');
	orbox.replaceChild(span, orbox.firstChild);
}

function Flip(dir)
{
	if (dir == "vert")
	{
		flipVert = !flipVert;
	}
	if (dir == "horiz")
	{
		flipHoriz = !flipHoriz;
	}
	ShowStep("this");
}

function Step(step, flipVert, flipHoriz)
{
	html = "";
	if (flipVert)
	{
		for (var i=line[step].length-1; i>=0; i--)
		{
			string = GetLine(step, i, flipHoriz);
			for (j=0; j<swap.length; j++)
			{
				string = string.replace(swap[j].regex, ":");
				string = string.replace(swap[j].vregex, swap[j].ch);
				string = string.replace(/\:/g, swap[j].vert);
			}
			html += string+"\n";
		}
	}
	else
	{
		for (var i=0; i<line[step].length; i++)
		{
			html += GetLine(step, i, flipHoriz)+"\n";
		}
	}
	return html;
}

function GetLine(step, row, flipHoriz)
{
	var string = line[step][row];
	if (flipHoriz)
	{
		string = Reverse(string);
		for (j=0; j<swap.length; j++)
		{
			string = string.replace(swap[j].regex, ":");
			string = string.replace(swap[j].hregex, swap[j].ch);
			string = string.replace(/\:/g, swap[j].horiz);
		}
	}
	return string;
}

function Reverse(string)
{
	var newString = "";
	for (i=0; i<string.length; i++)
	{
		newString += string.charAt(string.length-i);
	}
	return newString;
}

