/**
 * 
 * 
 */

$(document).ready(function() {

	var showContent = function(e){
		e.preventDefault();
		var that = $(this);
		that.unbind();
		if ($.browser.msie && $.browser.version > 6) {
			that.parent().siblings().find('p:visible').css('display', 'none').parent().siblings('h3').unbind('click').click(showContent).hover(mouseOver, mouseOut).css('background-position', '0 0');
		} else {
			that.parent().siblings().find('p:visible').animate({
				height: 1
			}, 300, function(){
				$(this).css({
					display: 'none',
					height: 'auto'
				});
				$(this).parent().siblings('h3').unbind('click').click(showContent).hover(mouseOver, mouseOut).css('background-position', '0 0');
			});
		}
		var contentBody = $(this).siblings('.body');
		var content = $('p', contentBody);
		that.css('background-position', '0 -9px');
		var ch = $('<div/>').css({
			position: 'absolute',
			top: -9999,
			left: -9999,
			fontSize: '11px',
			width: contentBody.width()
		}).html('<p style="margin:0">' + content.text() + '</p>').appendTo($(document.body));
		var nh = ch.height();
		ch.remove();
		if ($.browser.msie && $.browser.version > 6) {
			content.css('display', 'block');
			that.click(hideContent);
		} else {			
			content.stop().css({
				height: 1,
				display: 'block'
			}).animate({
				height: nh
			}, 300, function(){
				$(this).css('height', 'auto');
				that.click(hideContent);
			});			
		}
	};
	
	var hideContent = function(e){
		e.preventDefault();
		var that = $(this);
		that.unbind('click');
		var contentBody = $(this).siblings('.body');
		if ($.browser.msie && $.browser.version > 6) {
			$('p', contentBody).css('display', 'none');
			that.css('background-position', '0 0').click(showContent).hover(mouseOver, mouseOut);
		} else {
			$('p', contentBody).stop().animate({
				height: 1
			}, 300, function(){
				$(this).css({
					display: 'none',
					height: 'auto'
				});
				that.css('background-position', '0 0').click(showContent).hover(mouseOver, mouseOut);
			});
		}
	};

	var mouseOver = function(){
		$(this).css('background-position', '0 -9px');
	};
	
	var mouseOut = function(){
		$(this).css('background-position', '0 0');
	};

	$('.accordion h3').click(showContent).hover(mouseOver, mouseOut);

});