/* Julie Field's and Patrick Pohler's nifty accordion plugin */
(function( $ ) {
	$.fn.JAccordion = function() {
		obj = $(this);
		var defaultHeight = $('#rightside').height() + 40;
		
		$(this).children("li").each(function(index) {
			if($(this).height() > 0) //hack, webkit not getting the height for image accordion
				defaultHeight += $(this).height();
			else
				defaultHeight += 57;
		});
		
		$(this).children("li").click(function() {
			if(false == $(this).next().is(':visible')) {
				$(obj).children("ul").slideUp(300);
				$('.down_arrow').removeClass('down_arrow');
			}
			
			if(false == $(this).next().is(':visible')) {
				$(this).addClass('down_arrow');
				$('#rightside').height($(this).next().height() + defaultHeight);
				$('#leftside').height($(this).next().height() + defaultHeight);
			} else {
				$(this).removeClass('down_arrow');
			}

			$(this).next().slideToggle(300);
		});
		
		//show the first element (wrap up in a setting)
		//$(obj).children("ul:eq(0)").addClass('down_arrow');
		$(obj).children("ul:eq(0)").show();

		var loadHeight = $(obj).height();
		$('#rightside').height(loadHeight + defaultHeight);
		$('#leftside').height(loadHeight + defaultHeight);
	};
})( jQuery );



