var ClosedHeight = 1;		//Units: 'em'
var OpenHeight = 15;		//Units: 'em'

var ChangeBy = 0.2;		//Units: 'em'
var Interval = 8; 		//Units: milliseconds

var CategoryData = new Array();
var NumCategories = 0;

var CurrentWindow = null;
var CurrentHeading = null;

var PageLoaded=true;

//THE FOLLOWING 'function' IS A CLASS

function ResizeData(DivID, FinalHeight)
{
this.LayerID = DivID;
this.InProgress = false;
this.FinalHeight  = FinalHeight;
}

function SendReqItemsForm()
{
if (getElementById_s("ReqGroupAddButton").value!= "No Items Chosen") document.RequiredGroupAddForm.submit();
}


function ReLabelButton()
{
var form = document.RequiredGroupAddForm;
var a=0;
var Count = 0;

for(a=0; a < form.elements.length; a++)
	{
	if (form.elements[a].type=="text")
		{
		if (parseInt(form.elements[a].value) > 0)
			{
			Count += parseInt(form.elements[a].value);
			}
		}
	}
getElementById_s("ReqGroupAddButton").value = (Count > 0) ? ("Add Chosen " + Count + " Items To Basket") : "No Items Chosen";

}


function InitiateReSize(CategoryLayer, FinalHeight)
{
var LayerID = CategoryLayer.id;
var a = 0;
var CatIndex = -1;

for (a=0; a<NumCategories; a++)
	{
	if (CategoryData[a].LayerID==LayerID)
		{
		CatIndex = a;
		a = NumCategories; //Causes loop exit
		}
	}

if (CatIndex==-1)
	{
	//Category not found
	CategoryData[NumCategories] = new ResizeData(LayerID, FinalHeight);
	CatIndex = NumCategories;
	NumCategories += 1;
	}

CategoryData[CatIndex].FinalHeight = FinalHeight;

if (!CategoryData[CatIndex].InProgress)
	{
	//Only initiate a resizing loop if there is not already one in progress.
	CategoryData[CatIndex].InProgress = true;
	setTimeout ("ReSize('" + LayerID + "')", Interval);
	}

}

function ReSize(LayerID)
{
var CatIndex = -1;

CategoryLayer = getElementById_s(LayerID);

for (a=0; a<NumCategories; a++)
	{
	if (CategoryData[a].LayerID==LayerID)
		{
		CatIndex = a;
		a = NumCategories; //Causes loop exit
		}
	}

CurrentHeight = parseFloat(CategoryLayer.style.height);

if (CategoryData[CatIndex].FinalHeight != CurrentHeight)
	{
	if (CategoryData[CatIndex].FinalHeight > CurrentHeight)
		{
		//Enlarge
		CategoryLayer.style.height = (CategoryData[CatIndex].FinalHeight < (CurrentHeight + ChangeBy)) ? ((CategoryData[CatIndex].FinalHeight) + 'em') : ((CurrentHeight + ChangeBy) + 'em');
		}
	else
		{
		//Shrink
		CategoryLayer.style.height = (CategoryData[CatIndex].FinalHeight > (CurrentHeight - ChangeBy)) ? ((CategoryData[CatIndex].FinalHeight) + 'em') : ((CurrentHeight - ChangeBy) + 'em');
		}
	setTimeout ("ReSize('" + LayerID + "')", Interval);
	}
else
	{
	CategoryData[CatIndex].InProgress = false;
	}
}

function ShowThis(index, SkipCheck)
{
if (SkipCheck!=1)
	{
	if (CurrentWindow!=null)
		{
		if (index==CurrentWindow.id) return 0;
		}
	}

var ThisObj;
ThisObj = getElementById_s(index);

if (parseFloat(ThisObj.style.height)==OpenHeight)
	{
	//User has clicked on an already open window.
	InitiateReSize(ThisObj, ClosedHeight);
	ThisObj.style.overflow = "hidden";

	InitiateReSize(getElementById_s("SpacingDiv"), OpenHeight);
	
	CurrentHeading = null;
	CurrentWindow = null;
	return true;
	}

if (CurrentWindow==null)
	{
	CollapseAll();
	}
else
	{
	CurrentWindow.style.overflow = "hidden";
	InitiateReSize(CurrentWindow, ClosedHeight);
	}

ThisObj.style.overflow = "auto";
InitiateReSize(ThisObj, OpenHeight);

InitiateReSize(getElementById_s("SpacingDiv"), ClosedHeight);

CurrentHeading = getElementById_s(index + 'Heading');

CurrentWindow = ThisObj;
}

function ShowThisRel(Change) {

if (CurrentWindow!=null)
	{
	var ObjectName = "";
	ObjectName = CurrentWindow.id;
	var CatNum = parseInt(ObjectName.substr(3,ObjectName.length-3)) + Change;

	ObjectName = "Cat" + CatNum;
	if (getElementById_s(ObjectName))
		{
		ShowThis(ObjectName);
		}
	}
}