var timeOptions = new TimeOptions()

/////////////////////////////////////////////////////////////
// TimeOptions Class ////////////////////////////////////////
/////////////////////////////////////////////////////////////

function TimeOptions()
{
	this.container = null;
	this.field = null;
	this.hideTimer = null;
	this.onSelectHandler = null;
	this.shim = null;

	this.attachToField = timeOptions_attachToField;
	this.hide = timeOptions_hide;
	this.initialize = timeOptions_initialize;
	this.initiateHide = timeOptions_initiateHide;
	this.select = timeOptions_select;
	this.show = timeOptions_show;
}

function timeOptions_attachToField(field, handler)
{	
	//set reference to field
	this.field = field;
	this.onSelectHandler = handler;	
}

function timeOptions_hide()
{
	this.container.style.display = "none";
	this.shim.style.display = "none";
}

function timeOptions_initiateHide()
{
	this.container.hideTimer = window.setTimeout("timeOptions.hide();", 300);
}

function timeOptions_initialize(id)
{
	this.container = document.getElementById(id);
	this.shim = document.getElementById(id + "_Shim");
}

function timeOptions_select(time)
{
	this.field.value = time;
	if (this.onSelectHandler)
		eval(this.onSelectHandler.replace(/this/g,"this.field"));
	this.field.select();
	this.hide()
}

function timeOptions_show(field, handler)
{
	var newField = false;

	//clear timer, attach to provided field
	if (this.container.hideTimer)
		window.clearTimeout(this.container.hideTimer);
	if (field && field != this.field)
	{
		this.attachToField(field, handler);
		newField = true;
	}
	
	//show shim and container
	item_reposition(field, this.container, true);
	if (this.container.style.display != "block")
	{		
		this.container.style.display = "block";	
		
		//set up the shim to cover windowed elements (i.e. select boxes)
		this.shim.style.width = this.container.offsetWidth + "px";
		this.shim.style.height = this.container.offsetHeight + "px";
		this.shim.style.left = this.container.style.left;
		this.shim.style.top = this.container.style.top;
		this.shim.style.display = "block";	
		
		//finally, scroll container to 8 AM
		if (newField)
			this.container.scrollTop = this.container.scrollHeight/3;
	}
}