/*
infoexpand.js

Javascript file for expanding menu effect on:
-What We Offer: Meeting Space
-...and other pages (to be listed)
*/

//allow use of other JS Frameworks
jQuery.noConflict();

jQuery(document).ready(init);

function init() {
	//wrap all info_blocks in accordion menu wrapper
	jQuery("div.info_block").wrapAll("<div class=\"accordion_menu\"></div>");
	//dynamically insert accordion menu controls
	jQuery("div.accordion_menu").prepend("<a class=\"infoexpand_nav\" href=\"javascript:showAllInfoBlocks()\">show all</a> <a class=\"infoexpand_nav\" href=\"javascript:closeAllInfoBlocks()\">close all</a>");

	//on page load, hide all blocks except the first
	jQuery("div.info_block_content:not(:first)").hide();
	//set the first info_block to active
	jQuery("div.info_block:first").addClass("active");
	
	//for accessibility make sure heading contains a link so that it is actionable by the keyboard
	jQuery("div.info_block h4").wrapInner("<a class=\"toggle_link\" href=\"javascript:void(0);\"></a>");
	//set click event for header links to toggle info_block_content visibility
	jQuery("div.info_block h4 > a").click(toggleInfoBlockContent);
	
}

function toggleInfoBlockContent() {
	// applied to links nested in h4 elements; this->parent->parent is div.info_block
	
	//remove active class from all other info_blocks; add active class to current info_block
	jQuery("div.info_block").removeClass("active");
	jQuery(this).parent().parent().addClass("active");
	
	//hide all other info_block_content in sibling info_blocks, and hide or display the relevant info block
	if(jQuery(this).parent().parent().siblings().children("div.info_block_content").is(":visible")) {
		//if other info_block_content divs are showing (i.e. via "show all") hide them
		jQuery(this).parent().parent().siblings().children("div.info_block_content").slideUp();
	}
	jQuery(this).parent().parent().children("div.info_block_content").slideDown();
	
}

//accordion menu control functions----------------------------------------
function closeAllInfoBlocks() {
	jQuery("div.info_block").removeClass("active");
	jQuery("div.info_block_content").slideUp();	
}

function showAllInfoBlocks() {
	jQuery("div.info_block").addClass("active");
	jQuery("div.info_block_content").slideDown();
}