var $j = jQuery.noConflict();
$j(document).ready(function(){
	//hide all accordions except the open ones
	$j('.accordion:not(.opened)').hide();
	//make links trigger the accordion stuff
	$j('.accordion_container a').click(function(){
		//get level
		var level = $j(this).attr('class');
			//trigger accordion stuff only for links that have an accordion
		var next = $j(this).next('.accordion');
		var other = $j('.'+level).next();
			//is the accordion opened ?
		if (next.hasClass('opened')) {
			next.slideUp('fast');
		} else {
			//accordion is closed, loop through others
			other.each(function(i,el){
				if ($j(el).hasClass('opened')){
					$j(el).slideUp('fast').removeClass('opened');
				}
			});
			
			if (level == 'level1'){
				//hide all the other accordions at higher levels
				$j('.level2').next().removeClass('opened').hide();
			}
			next.slideDown('fast');
		}
		next.toggleClass('opened');
		//remove selected from level links and set clicked link as selected
			$j('.'+level).removeClass('selected');
			$j(this).addClass('selected');

		// this prevents the browser from opening the link associated with the accordion header
		// if (next.hasClass('accordion')) {
		// 			return false;
		// 		}
	});
});