// -----------------------------------------------------------------
//						Redland Shire Council 
// -----------------------------------------------------------------
// Class    : TOC 
// Purpose  : Handles the moving (hiding and showing) of the table
//			  of contents, and the restoration of its state after
//			  a postback.
// -----------------------------------------------------------------
// Calls    :
// Called by: the onclick event of the imgShowHideTOC image in
//			  default.aspx
// -----------------------------------------------------------------
// Arguments:
// Globals  :
// Returns  :
// -----------------------------------------------------------------
// Notes    :
// -----------------------------------------------------------------
// History  :
// =================================================================

//Initialise the current left offset of the TOC to 0, where it begins.
x = 0;

//Slide the TOC off the left of the screen so it is hidden
function HideTOC()
{
	//Animate in steps of 7 pixels
	x = x - 7;

	//Update the div tags left property
	document.getElementById('divTOC').style.left = x;
	
	//While the x value is > -300, recursively call the hide function to keep the animation going
	if (x > -document.getElementById('divTOC').clientWidth - 20)
	{
		//Slide by another 7 pixels every 5 milliseconds
		setTimeout("HideTOC()",5)
	}
	
}

//Slide the TOC back onto the screen so that it is visible
function ShowTOC()
{
	//Animate in steps of 7 pixels
	x = x + 7;
	
	//Update the div tags left property
	document.getElementById('divTOC').style.left = x;
	
	//While the x value is < 0, animate the function back in view.
	if (x < 0)
	{
		//Slide by another 7 pixels every 5 milliseconds
		setTimeout("ShowTOC()",5)
	}
	else
	{
		//Make it's position flush with the left border if the x value goes above 0.
		document.getElementById('divTOC').style.left = 0;
	}
	
}

//Toggle hiding and showing of the TOC div layer.
//NB: TOC is always requested and drawn, this function only
//toggles the visibility using CSS.
function toggleTOC()
{
	//The TOC is currently hidden...
	if (parseInt(document.getElementById('divTOC').style.left) < 0)
	{
		//Show the TOC
		x = -document.getElementById('divTOC').clientWidth + 20;
		ShowTOC();
		
		//Set the invisible form field to hold the visibility state of the TOC
		document.getElementById('txtTOCOnOff').value = "On";
		document.getElementById('divTOC').style.visibility = "visible";
	}
	else
	{
		//The TOC is currently visible, so hide it...
		x=0;
		HideTOC();
		
		//Set the invisible form field to hold the visibility state of the TOC
		document.getElementById('txtTOCOnOff').value = "Off";
	}
}

function refreshTOCVisibility()
{
	//If user has hidden TOC, set it to hidden
	//This function is called after a postback
	if (document.getElementById('txtTOCOnOff').value == "Off")
	{
		document.getElementById('divTOC').style.left = -document.getElementById('divTOC').clientWidth - 20;
	}
	else
	{
		// the TOC is meant to be visible, set it to visible
		document.getElementById('divTOC').style.visibility = "visible";
	}
	
	//Don't allow the TOC to be wider than 300 pixels
	if (document.getElementById('divTOC').clientWidth > 300)
	{
		document.getElementById('divTOC').style.width = '300px';
	}
	
	//Don't allow the TOC to be narrower than 235 pixels (to allow the Title and Auto Refresh checbox to fit)
	if (document.getElementById('divTOC').clientWidth < 235)
	{
		document.getElementById('divTOC').style.width = '235px';
	}
	
	// if netscape or firefox need to set the width to alignt the close button on the right
	if (checkBrowser()=='firefox')
	{
		document.getElementById('divTOCTitle').style.width = document.getElementById('divTOC').offsetWidth - 4;
	}
}
