// Andy Langton's show/hide/mini-accordion - updated 23/11/2009
// Latest version @ http://andylangton.co.uk/jquery-show-hide

// this tells jquery to run the function below once the DOM is ready
$(document).ready(function() {

// choose text for the show/hide link - can contain HTML (e.g. an image)
var showText='<img class="link" src="./images/expand.png" alt="+" />';
var hideText='<img class="link" src="./images/retract.png" alt="-" />';

// initialise the visibility check
var is_visible = true;

// append show/hide links to the element directly preceding the element with a class of "toggle"
$('.toggle').prev().append(' <a href="#" class="toggleLink">'+showText+'</a>');

// hide all of the elements with a class of 'toggle'
$('.toggle').hide();

// capture clicks on the toggle links
$('a.toggleLink').click(function() {

// check visibility of toggleLink's child
if ( $(this).parent().next('.toggle').is(':visible') )
{
// if toggleLink's child already visible, hide child and toggle show/hide indicator
$(this).parent().next('.toggle').hide('slow');
$('.toggleLink').html( (!is_visible) ? hideText : showText);
}
else
{
if ( $('.toggle').is(':visible') )
{
// if toggleLink's child not visible, hide all 'toggle' elements & toggle all show/hide indicators
$('.toggle').hide('slow');
$('.toggleLink').html( (!is_visible) ? hideText : showText);
};

// toggle the display
$(this).parent().next('.toggle').toggle('slow', function() {
// check visibility
if ( $(this).is(':visible') )
{
is_visible = true;
}
else
{
is_visible = false;
};
// change the link depending on whether the element is shown or hidden
$(this).prev().find('.toggleLink').html( (!is_visible) ? showText : hideText);
});

};

// return false so any link destination is not followed
return false;

});
});
