var HotCell = "#333333";
var ColdCell = "#222222";
var selectedPic = 0;
var anchorJump = "";

function TopSpacing(IDTag)
{
	var NewHTML = "";
	var NewIDTag = IDTag.substring(0, IDTag.length - 1);

	NewHTML += "\t<tr onMouseOver=\"Highlight('" + NewIDTag + "');\" onMouseOut=\"UnHighlight('" + NewIDTag + "');\">\n";
	NewHTML += "\t\t<td height=20 class=Border width=1>\n";
	NewHTML += "\t\t</td>\n";
	NewHTML += "\t\t<td id=" + IDTag + " height=20 colspan=5 class=Cell>\n";
	NewHTML += "\t\t</td>\n";
	NewHTML += "\t\t<td height=20 class=Border width=1>\n";
	NewHTML += "\t\t</td>\n";
	NewHTML += "\t</tr>\n";

	return NewHTML;
}

function SideSpacing(IDTag)
{
	var NewHTML = "";

	NewHTML += "\t\t<td id=" + IDTag + " width=20 class=Cell>\n";
	NewHTML += "\t\t</td>\n";

	return NewHTML;
}

function Highlight(IDTag)
{
	for (var i = 1; i <= 7; i++)
	{
		eval(IDTag + i).style["backgroundColor"] = HotCell;
	}
}

function UnHighlight(IDTag)
{
	for (var i = 1; i <= 7; i++)
	{
		eval(IDTag + i).style["backgroundColor"] = ColdCell;
	}
}

function CreateRow(IDTag, Yahoo, YahooA)
{
	var NewHTML;
	
	NewHTML = "<script>\n";
	NewHTML += "\tdocument.write(TopSpacing(\"" + IDTag + "1\"));\n";
	NewHTML += "</script>\n";
	NewHTML += "<tr onMouseOver=\"Highlight('" + IDTag + "');\" onMouseOut=\"UnHighlight('" + IDTag + "');\">\n";
	NewHTML += "\t<td width=1 class=Border>\n";
	NewHTML += "\t</td>\n";
	NewHTML += "\t<script>\n";
	NewHTML += "\t\tdocument.write(SideSpacing(\"" + IDTag + "2\"));\n";
	NewHTML += "\t</script>\n";
	NewHTML += "\t<td id=" + IDTag + "3 class=Cell align=center>\n";
	
	if (Yahoo)
	{
		if (YahooA)
		{
			NewHTML += "\t\t<a class=\"Linky\" href=\"" + YahooAURL + "\">\n";
		}
		else
		{
			NewHTML += "\t\t<a class=\"Linky\" href=\"" + YahooBURL + "\">\n";
		}
	}
	else
	{
		NewHTML += "\t\t<a class=\"Linky\" href=\"" + IDTag + "/index.html\">\n";
	}
		
	if (!Yahoo)
	{
		NewHTML += "\t\t\t<script>\n";
		NewHTML += "\t\t\t\tdocument.write(\"<img border=0 src=\\\"" + IDTag + "/img/thumb/\" + " + IDTag + "() + \"\\\">\");\n";
		NewHTML += "\t\t\t</script>\n";
	}
	
	NewHTML += "\t\t\t<br/>\n";
	NewHTML += "\t\t\t" + eval(IDTag + "Title") + "\n";
	NewHTML += "\t\t</a>\n";
	NewHTML += "\t</td>\n";
	NewHTML += "\t<script>\n";
	NewHTML += "\t\tdocument.write(SideSpacing(\"" + IDTag + "4\"));\n";
	NewHTML += "\t</script>\n";
	NewHTML += "\t<td id=" + IDTag + "5 class=Cell>\n";
	NewHTML += "\t\t" + eval(IDTag + "Text") + "\n";
	NewHTML += "\t</td>\n";
	NewHTML += "\t<script>\n";
	NewHTML += "\t\tdocument.write(SideSpacing(\"" + IDTag + "6\"));\n";
	NewHTML += "\t</script>\n";
	NewHTML += "\t<td width=1 class=Border>\n";
	NewHTML += "\t</td>\n";
	NewHTML += "</tr>\n";
	NewHTML += "<script>\n";
	NewHTML += "\tdocument.write(TopSpacing(\"" + IDTag + "7\"));\n";
	NewHTML += "</script>\n";
	NewHTML += "<tr>\n";
	NewHTML += "\t<td colspan=7 height=2 class=Border>\n";
	NewHTML += "\t</td>\n";
	NewHTML += "</tr>\n";
	
	return NewHTML;
}

function startup()
{
	if (window.location.search != "")
	{
		swapPic(parseInt(window.location.search.substring(3, window.location.search.length)));
		
		window.location.hash = selectedPic;
	}
	else
	{
		if (window.location.hash == "")
		{
			swapPic(0);
		}
		else
		{
			swapPic(parseInt(window.location.hash.substring(1, window.location.hash.length)));
			
			window.location.hash = selectedPic;
		}
	}

	updateDirectLink();
}

function loadPic(picNumber)
{
	swapPic(picNumber);
	
	window.location.search = "p=" + picNumber;
	
	UpdateDirectLink();
}

function updateDirectLink()
{
	if (window.location.href.indexOf('#') == -1)
	{
		document.getElementById("directLink").href = window.location.href;
		
		document.getElementById("directLink").innerHTML =window.location.href;
	}
	else
	{
		document.getElementById("directLink").href = window.location.href.substring(0, window.location.href.indexOf('#'));
		
		document.getElementById("directLink").innerHTML =window.location.href.substring(0, window.location.href.indexOf('#'));
	}
}

function processArrow(event)
{
	var keynum;

	if (window.event) // IE
	{
		keynum = event.keyCode;
	}
	else if (event.which) // Netscape/Firefox/Opera
	{
		keynum = event.which;
	}
	
	if ((keynum == 39) || (keynum == 40))
	{
		next();
	}
	
	if ((keynum == 37) || (keynum == 38))
	{
		previous();
	}
}

function next()
{
	if (selectedPic < getMaxPics())
	{
		swapPic(selectedPic + 1)
	}
	else
	{
		swapPic(0);
	}
	
	window.location.search = "p=" + selectedPic;
	
	updateDirectLink();
}

function previous()
{
	if (selectedPic > 0)
	{
		swapPic(selectedPic - 1)
	}
	else
	{
		swapPic(getMaxPics());
	}
	
	window.location.search = "p=" + selectedPic;
	
	updateDirectLink();
}