jQuery(document).ready(function() {
	Cordaan.HomeMenu.Init();
});

if(typeof(Cordaan) == 'undefined') {
	Cordaan = function() {};
}

Cordaan.HomeMenu = function() {};

Cordaan.HomeMenu.Init = function() {
	$('.homeMenu a.arrow').click(Cordaan.HomeMenu.Open);
}

Cordaan.HomeMenu.Open = function() {
	// Unbind click event to prevent overlapping animations
	$(this).unbind('click');

	// Remove the collapse class
	$(this).parents('.homeMenu').removeClass('collapse');

	// Hide the arrow button
	$(this).hide();

	// Show the hidden ul using the jquery blind effect (http://docs.jquery.com/UI/Effects/Blind)
	$('ul.hidden', $(this).parents('.homeMenu')).show(
		'blind',
		{direction: 'vertical'},
		750,
		function() { // On effect end
			// Add the expand class
			var homeMenu = $(this).parents('.homeMenu');
			homeMenu.addClass('expand');

			// Show the arrow button
			$(this).next('a.arrow').show();

			// Add the close function on the onclick event
			var slideLink = $('a.arrow', homeMenu);
			slideLink.click(Cordaan.HomeMenu.Close);
		}
	)
}

Cordaan.HomeMenu.Close = function() {
	// Unbind click event to prevent overlapping animations
	$(this).unbind('click');

	// Remove the expand class
	$(this).parents('.homeMenu').removeClass('expand');

	// Hide the arrow button
	$(this).hide();

	// Hide the hidden ul using the jquery blind effect (http://docs.jquery.com/UI/Effects/Blind)
	$('ul.hidden', $(this).parents('.homeMenu')).hide(
		'blind',
		{direction: 'vertical'},
		750,
		function() { // On effect end
			// Add the collapse class
			var homeMenu = $(this).parents('.homeMenu');
			homeMenu.addClass('collapse');

			// Show the arrow button
			$(this).next('a.arrow').show();

			// Add the close function on the onclick event
			var slideLink = $('a.arrow', homeMenu);
			slideLink.click(Cordaan.HomeMenu.Open);
		}
	)
}
