// implement nugget selection

function Nugget(image,url)
{
	this.image = image;
	this.url = url;
	this.used = 0;
	this.write = Nugget_write;
}

function Nugget_write()
{
	return '<a href="' + this.url + '"><img src="' + this.image + '"></a>';
}

function Nuggets()
{
	this.items = new Array();
	this.add = Nuggets_add;
	this.writeSpecific = Nuggets_writeSpecific;
	this.writeRandom = Nuggets_writeRandom;
}

function Nuggets_add(image,url)
{
	this.items[this.items.length] = new Nugget(image,url);
}

function Nuggets_writeSpecific(i)
{
	return this.items[i].write();
}

function Nuggets_writeRandom()
{
	// until we get one that hasn't been picked
	var nTries = 0, nMaxTries = 100;
	while(nTries < nMaxTries) {
		var i = Math.floor(Math.random() * this.items.length);
		if(this.items[i].used == 0) {
			this.items[i].used = 1;
			return this.items[i].write();
		}
		nTries++;
	}
}