var originalText = null;
var aPictures = null;
function RestoreText()
{
	$("#featurePicture").css({'display' : 'none'});
	$("#pageContent").show("slow");
	$("#titleGraphic").attr({'src' : aTitles[0]});
}
function GetImage(ndx)
{
	$("#pageContent").css({'display' : 'none'});
	$("#featurePicture").css({'display' : 'none'});
	$("#featurePicture").attr({src: aPictures[ndx]});
	$("#featurePicture").show("slow");
	$("#titleGraphic").attr({src: aTitles[1]});
	$("#restoreTextLink").css({'display' : 'inline'});
}

function Toggle(rownum)
{
	var tbodyObject = document.getElementById("tbody" + rownum);
	var spanObject =  document.getElementById("span" + rownum);

	if(tbodyObject.style.display == "none")
	{
		$("#" + tbodyObject.id).show("slow");
		spanObject.innerText = "-";
	}
	else
	{
		$("#" + tbodyObject.id).hide("slow");
		spanObject.innerText = "+";
	}
}
function SwitchSubmenu(ndx, showMe)
{
	$("#menuIndex").val(ndx);
	NewContent(showMe);
}
function NewContent(conType)
{
	frm = document.forms.actionform;
	frm.newContent.value = conType;
	//for error teting use:frm.submit();
	if(conType != "none")
	{
		SendAjaxData(frm, frm.action, "UpdateClient");
	}
}
function pickRandom(range) 
{
	if (Math.random)
		return Math.round(Math.random() * (range-1));
	else 
	{
		var now = new Date();
		return (now.getTime() / 1000) % range;
	}
}
// Write out an IMG tag, using a randomly-chosen image name.
var photoChoice = pickRandom(totalPhotos);
var bgChoice = pickRandom(totalBGs);
function UpdateClient()
{
	if(objAjaxReq.readyState == 4)
	{
		if(objAjaxReq.status == 200 && objAjaxReq.responseText.length > 0)	
		{
			var tmp,tmp2,nvPair,thisElement,rChoice;
			//Pick a new random photo for the middle gutter
			tmp = document.getElementById("gutterImage");
			photoChoice++;
			if(photoChoice == gutterImg.length)
				photoChoice = 0;
			tmp.src = gutterImg[photoChoice];
			//tmp.src = gutterImg[pickRandom(totalPhotos)];
			
			//Pick a new random background for the right side
			tmp = document.getElementById("bgImage");
			bgChoice++;
			if(bgChoice == rightBG.length)
				bgChoice = 0;
			tmp.src = rightBG[bgChoice];
			//tmp.src = rightBG[pickRandom(totalBGs)];

			// Split the contents of responseText into a series of objectname, value pairs
			tmp = objAjaxReq.responseText;
			tmp = tmp.split("~~"); 
			if(tmp.length > 0)
			{
				for(i=0; i<tmp.length; i++)
				{
					nvPair = tmp[i].split("@@");
					if(nvPair.length == 2)
					{
						if(nvPair[0] == "jScriptCode")
							eval(nvPair[1])
						else
						{
							thisElement = document.getElementById(nvPair[0]);
							thisElement.innerHTML = nvPair[1];
							//tmp2 = "#" + nvPair[0];
							//$(tmp2).html(nvPair[1]);
						}
					}
				}
			}
		}
		else
			alert("Error number " + objAjaxReq.status)
		//Clear the object for the next request.
		objAjaxReq = null;
	}
}
