var OrderForm = {
	init: function()
	{
		OrderForm.form = this;
		
		$('a.product').click(function(e){
		 	TB_show(this.title, '/productinfo.php?width=600&height=500&id=' + this.id, false);
		  	this.blur();
		  	e.preventDefault();
		  	return false;
		});

		// add expand/collapse behaviour to categories
		$('tr.category2', OrderForm.form)
			.each(OrderForm.categoryHide)
			.click(OrderForm.categoryClick);

		$('tr.category3', OrderForm.form)
			.each(OrderForm.categoryHide)
			.click(OrderForm.categoryClick);

		// show any categories with active rows
		$('tr.highlight', OrderForm.form)
		.parents('table').each(function() {
			$(this).show();

			// locate the category header
			re = /group\d+/;
			matches = this.className.match(re);
			if ( matches ) 
			{
				groupid = matches[0];
				$('tr#'+groupid+' th', OrderForm.form).addClass('open');
			}
		});
	},

	categoryClick: function() {
		$('th', this).toggleClass('open');
		$('table.'+this.id, OrderForm.form).toggle();
	},

	categoryHide: function() {
		$('table.'+this.id+':visible', OrderForm.form).hide();
		$('th.open', this).removeClass('open');
	},

	categoryShow: function() {
		$('table.'+this.id+':hidden', OrderForm.form).show();
		$('th', this).addClass('open');
	}
};

document.write('<style type="text/css">table.productgroup table { display: none; } </style>');

$(document).ready(function(){
	// initialize the order form
	$('#orderform').each(OrderForm.init);
});
