/*
	menu.js 
	Accordion effect from http://www.learningjquery.com/2007/03/accordion-madness
	Author Mike Birch 17 May 2007
*/
// stripe the table rows
var stripe = function () {
	$('div#toggleable> table tr:even').addClass("alt");
};

var accordion = function() {
	
	// show/hide tables if more than one table
	if ($('div#toggleable> table').length > 1 ) {
		$('div#toggleable> table:gt(0)').hide();
		$('div#toggleable> h3:gt(0)').addClass('pseudo-link');
		$('div#toggleable> h3').click(function() {
			$('div#toggleable> h3').addClass('pseudo-link');
			$(this).removeClass('pseudo-link');
			var $nextTable = $(this).next('table');
			var $visibleSiblings = $nextTable.siblings('table:visible');
			if ($visibleSiblings.length ) {
				$visibleSiblings.slideUp('slow', function() {
					$nextTable.slideToggle('slow');
				});
			} else {
				$nextTable.slideToggle('slow');
			}
		});
		// display link to show the complete menu
		allmenu();
	}
};

// show the complete menu
var allmenu = function () {
	// display link to show the complete menu
	$('div#toggleable').append('<p id="allmenu"><a href="#" id="allmenulink">Show</a> the complete Menu</p>');
	$('#allmenulink').click(function() {
		$('div#toggleable> h3').removeClass('pseudo-link');	
		$('div#toggleable> table').show();
		$('div#toggleable> h3').unbind("click");	
		$('#allmenu').hide();
		return false;
	});
};

// display link to print, and add onclick to show print dialog 
var printmenu = function() {
	$('div#toggleable').append('<p id="printmenu"><a href="#" id="printmenulink">Print</a> this menu (printer friendly version)</p>');
	$('#printmenulink').click(function() {
		window.print();		
		return false;
	});	
};

$(document).ready(function() {
	stripe();	
	accordion();
	printmenu();
});
