var $j = jQuery.noConflict();
var contentBackground = 'mysite/images/bg_accordion_a.png';
var minHeight = 0;
var maxHeight = 250;
var activeElement;

$j(document).ready(
	function() {
		
		$j('#accordion li').each(
			function(i) {
				if($j(this).height() > minHeight) {
					minHeight = $j(this).height();
				}
				var c = $j($j(this).find('div.accordion_content')[0]);
				var cw = c.outerWidth();
				var ch = c.outerHeight();
				$j(this).append('<div style="background:url(\''+contentBackground+'\');width:'+cw+'px;height:'+ch+'px;position:absolute;bottom:0px;left:0px;z-index:0;"></div>');
				var l = $j(this).find('a.title');
				l.bind(
					'click',
					function() {
						if(activeElement && activeElement != this) {
							$j($j(activeElement).parent().find('div.accordion_content')[0]).fadeOut(250);
							$j(activeElement).parent().animate(
								{
									height: minHeight
								},
								1000
							);
						}
						$j($j(this).parent().find('div.accordion_content')[0]).fadeIn(500);
						$j(this).parent().animate(
							{
								height: maxHeight
							},
							1000
						);
						activeElement = this;
						return false;
					}
				);
				if(i == 0) {
					c.show();
					$j(this).height(maxHeight);
					activeElement = l;
				}
			}
		);
		
	}
);