var PhotoSet;
var IndexPrefix;
var ImageSuffix;

var pos;
var len;

function isTitle ()
{
	if (pos < len)
	{
		var c= PhotoSet.charAt(pos);
		if (((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || (c == '_'))
			return 1;
	}
	return 0;
}

function nextTitle ()
{
	var n= "";
	while (pos < len)
	{
		if (!isTitle ())
			return n;
		var c= PhotoSet.charAt(pos);
		pos++;
		n+= c;
	}
	return n;
}

function skipSpace ()
{
	while (pos < len)
	{
		var c= PhotoSet.charAt(pos);
		if ((c != ' ') && (c != '\t') && (c != '\r') && (c != '\n'))
			return;
		pos++;
	}
}

function isBreak ()
{
	if ((pos < len) && (PhotoSet.charAt(pos) == '-'))
	{
		pos++;
		return 1;
	}
	return 0;
}

function getComment ()
{
	if ((pos >= len) || (PhotoSet.charAt(pos) != '['))
		return "";

	pos++;
	var str= "";
	while (pos < len)
	{
		var c= PhotoSet.charAt(pos++);
		if (c == ']')
			return str;
		str+= c;
	}
	return str;
}

//spewImages ("-[Look, ma] 123 124[Click me] 125 - 126 127 126", "i", ".JPG", 10, 10, document);
function spewImages (Set, Indx, Sufx, hspace, vspace, doc)
{
	PhotoSet= Set;
	IndexPrefix= Indx;
	ImageSuffix= Sufx;
	pos= 0;
	len= Set.length;

	while (pos < len)
	{
		skipSpace ();

		if (isBreak())
		{
			doc.write ("<HR>");
			var com= getComment ();
			if (com.length > 0)
				doc.writeln ("<FONT SIZE=\"+1\">" + com + "</FONT><BR>");
		}
		else if (isTitle ())
		{
			var img= nextTitle ();
			var com= getComment ();
			doc.writeln ("<A HREF=\"" + img + ImageSuffix + "\"><IMG SRC=\"" + IndexPrefix + img + ImageSuffix +"\" ALT=\"" + com + "\" HSPACE=" + hspace + " VSPACE=" + vspace + " ALIGN=CENTER></A>");
		}
		else
		{
			alert ("Parse error at '" + PhotoSet.charAt (pos) + "':  ..." + PhotoSet.substring (pos - 5, pos + 5) + "...");
			pos++;
		}
	}
}
