// Show/Hide Blocks Control v1.0
// Andrew Pettican (December 2009)
//
// NB: The <li> elements within the blocks list must have an
// "open" or "closed" classname and must contain a "hidden_content"
// div in order for this to work. This is to prevent unwanted
// events firing on sublists within the parent list.
//
// Changelog:
// v1.0 - 03/12/2009 - Initial build
//////////////////////////////////////////////////////////////////

// ---------------------------------------------------------------
// Parameters
// ---------------------------------------------------------------



// ---------------------------------------------------------------
// Parameters End
// ---------------------------------------------------------------



// ---------------------------------------------------------------
// Global Vars, Do not change anything below this line!
// ---------------------------------------------------------------



// ---------------------------------------------------------------
// Global Vars End, Do not change anything above this line!
// ---------------------------------------------------------------



// ---------------------------------------------------------------
// JS Events
// ---------------------------------------------------------------

$(document).ready(function()
{
	if($('ul.block_list').length > 0)
	{
		// When the user clicks on a list element, display its related content
		$('ul.block_list li a').click(function()
		{
			// Is there any hidden_content for this list element?
			var parent_li_id = this.parentNode.id;
			var parent_li = this.parentNode;
			if(parent_li !== null && parent_li_id !== "" && $('ul.block_list li#'+parent_li_id+' .hidden_content').length > 0)
			{
				// Is the list element already open?
				if($(parent_li).hasClass('open'))
				{
					// Close this list element
					$(parent_li).toggleClass('open');
					$(parent_li).toggleClass('closed');
					$('ul.block_list li#'+parent_li_id+' .hidden_content').css('display', 'none');
					return false;
				}
				
				// Is the list element closed?
				else if($(parent_li).hasClass('closed'))
				{
					// Open this list element
					$(parent_li).toggleClass('open');
					$(parent_li).toggleClass('closed');
					$('ul.block_list li#'+parent_li_id+' .hidden_content').css('display', 'block');
					return false;
				}
			}
			return true;
		});
	}
});

// ---------------------------------------------------------------
// JS Events End
// ---------------------------------------------------------------



// ---------------------------------------------------------------
// Functions
// ---------------------------------------------------------------



// ---------------------------------------------------------------
// Functions End
// ---------------------------------------------------------------
