jQuery(document).ready(function($) {

//	alert('boo');

	var show_hide = '<div class="accordion-show-hide"></div>';
	var hide_link = '<a href="#" class="accordion-hide">- Hide</a>';
	var show_link = '<a href="#" class="accordion-show">+ Show</a>';
	var speed = "slow";

	// setup accordion
	$("#accordion .accordion-section-title").addClass("accordion-active-title");
	$("#accordion .accordion-section-body").addClass("accordion-active-body");
	
	$("#accordion .accordion-section-title").wrapInner('<div class="accordion-title-text"></div>');
	$("#accordion .accordion-section-title").append(show_hide);
	
	// to expand the first one by default
//	$("#accordion .accordion-section:not(:first) .accordion-section-body").hide();
//	$("#accordion .accordion-section:first .accordion-section-title .accordion-show-hide").html(hide_link);
//	$("#accordion .accordion-section:not(:first) .accordion-section-title .accordion-show-hide").html(show_link);
	
	// to collapse all by default
	$("#accordion .accordion-section .accordion-section-body").hide();
	$("#accordion .accordion-section .accordion-section-title .accordion-show-hide").html(show_link);
	
	// action
	$("#accordion .accordion-section-title").click(function() {
	
		if ($(this).children('.accordion-show-hide').children('a').hasClass('accordion-hide')) {
			// hide this one
			$(this).children('.accordion-show-hide').html(show_link);
			$(this).parent().children('.accordion-section-body').slideUp(speed);
			
		} else if ($(this).children('.accordion-show-hide').children('a').hasClass('accordion-show')) {

			// show this one
			$(this).children('.accordion-show-hide').html(hide_link);
			$(this).parent().children('.accordion-section-body').slideDown(speed);
			
		}

		return false;
	});
	
	/* iterate through all accordion text buttons and set height according to height of containing text */
	$("#accordion .accordion-title-text").each(function() {
		var textHeight = $(this).height();
		$(this).parent(".accordion-section-title").css('height', (textHeight - 2));
	});
});

