var initExpanders = function () {
	// Initialise the expanders
	$('.autoExpander a').click(function () {
		$(this).parent().next('div').slideToggle('fast');
		$(this).toggleClass('active');
		return false;
	});
	
	// Initially the content is expanded so they are in active state
	var scrollToAnchor;
	$('.autoExpander a').each(function (i, element) {
		if (window.location.hash != '#'+$(element).attr('id')) {
			$(element).addClass('active');
			$(element).click();
		} else {
			scrollToAnchor = element;
		}
	});
	
	if (scrollToAnchor) {
		//scrollToAnchor.scrollIntoView(true);
	}
};

var init = function () {
	var chart = initGraphTables(); // This function will return the chart instance of the last instantiated chart
	
	if ($.browser.mozilla && chart) {
		// Only a problem in firefox
		// This needs triggered after google visualizations has finished loading to allow the axis text to automatically rotate diagonally when too long - (Called at the end of initGraphTables())
		google.visualization.events.addListener(chart, 'ready', initExpanders);
	} else {
		initExpanders();
	}
};

$(document).ready(init);

