function getElement(id)
{
	if (document.getElementById)
		return document.getElementById(id);
	else
		return document.all[id];
}




function createCookie(name,value,days)
{
	var expires = "";
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ')
			c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0)
			return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}



function CoffeeCup(drink, where)
{
	this.drink = drink;
	this.left = getElement('coffee_left');
	this.right = getElement('coffee_right');
	this.discarded = getElement('coffee_discarded');
	this.where = "";

	this.discard =	function ()		{ this.moveTo("discarded"); createCookie("nocafe","y",0); }
	this.retrieve =	function ()		{ this.moveTo("right"); eraseCookie("nocafe"); }
	this.moveTo =	function (where)
					{
						if (this.where!="" && this[this.where]!=null)
							this[this.where].style.visibility = "hidden";

						this.where = where;

						if (this.drink!="" && this.where!="" && this[this.where]!=null)
							this[this.where].style.visibility = "visible";
					}
	this.changeHands =	function()
						{
							if (this.drink == "")
								return;

							if (this.where == "left")
								this.moveTo("right");
							else if (this.where == "right")
								this.moveTo("left");
						}

	this.moveTo(where); // move to initial position
}
