var PriceGuide = Class.create();

PriceGuide.prototype =
{
	initialize: function (element)
	{
		this.div = element;
		this.anchor = element.getElementsByTagName('a')[0];
		this.anchor.innerHTML = 'Show full price guide';
		this.table = element.getElementsByTagName('table')[0];
		Event.observe(this.anchor, 'click', this.toggleDiv.bind(this));
	},
	toggleDiv: function (event)
	{
		Event.stop(event);
		this.anchor.blur();
		this.table.style.display =
			this.table.style.display == 'none' ? 'block' : 'none';
	}
}

Event.observe(
	window,
	'load',
	function ()
	{
		$$('div.price-guide').each(
			function (element)
			{
				new PriceGuide(element);	
			}		
		);
		$$('div.price-guide table a').each(
			function (element)
			{
				Event.observe(
					element,
					'click',
					function (event)
					{ 
						var el = Event.element(event);
						var table = el.parentNode.parentNode;
						while (table.tagName != 'table' && table.tagName != 'TABLE')
						{
							table = table.parentNode;						
						}
						table.style.display = "none";
					}
				);
			}
		);
	}
);