$(document).ready(function(){
		
	var anchorSelected = false;
	
	// Category Menu JS 
	$('ul.accordion-container > li > a').click(function() {
		var $next = $(this).next();
		var hidden = $next.is(':hidden');
		$('.accor_a').each(function(){
			$(this).removeClass('accor_a_select');
			$(this).next().hide();
		});
		
		if( hidden ){
			$(this).addClass('accor_a_select');
			//$('ul.accordion-container li > ul:visible').hide();
			$next.show();
		} else {
			$(this).removeClass('accor_a_select');
			$next.hide();
		}
		if ($(this).attr('href') == '#') {
			return false;
		} else {
			if (!anchorSelected) {
				document.location.href = $(this).attr('href');
				anchorSelected = true;
				return false;
			}
		}
		return true;
	});

	$('.accor_b_menu,.accor_b_menu_select').click(function() {
		// return the value of the rotation to the anchor for link following
		return openAccordionMenu( $(this) );
	});
	
	$('.accor_b,.accor_b_menu,.accor_c').click(function() {
		if (!anchorSelected) {
			document.location.href = $(this).attr('href');
			anchorSelected = true;
		}
		return false;
	});
	
	if ( $(document).data("partner") != null ) {
		$('#st_cmpt_browse a').each(function() {
			if ( $.trim( $(this).attr('href') ) != '#' ) {
				$(this).attr('target', '_top').attr('href', $(this).attr('href') + '#top-anchor');
			}
		});		
	}
	
	if (!$(document).data('currentParameterCategory')) {
		$(document).data('currentParameterCategory', 0);
	}
	
	expandAccordian( $(document).data('currentParameterCategory'), true );
	//$('#st_cmpt_browse').css('display', 'block');
	
});

function deactivateCategory(element, toggle) {
	$(element).attr('disabled', toggle ? 'true' : 'false');
	return true;
}

function expandAccordian( id, open ) {
	var element = $('#n' + id);
	if ( element.attr("id") == undefined ) { return; }

	var cl = $(element).attr('class');
	
	element.parents('ul.accordion-menu').css('display', 'block');
	element.addClass(cl + '_select');
	
	if ( cl.indexOf('accor_c') > -1 ) {	
		element.parents('ul:first').prev('.accor_b_menu').addClass('accor_b_menu_select_passive');
	}

	if ( cl.indexOf('accor_b_menu') > -1 ) {
		element.parent().next().css('display', 'block');
		element.addClass('accor_b_menu_select');
	}
	element.parents('ul').prev('.accor_a').addClass('accor_a_select');		
}

function openAccordionMenu(element) {
	currentUL = $(element).parent().next('ul');
	if(currentUL.is(':hidden')){
		currentUL.show();
		$(element).addClass('accor_b_menu_select');
		// return false;
		return true;
	} else {
		currentUL.hide();
		$(element).removeClass('accor_b_menu_select');
		$(element).removeClass('accor_b_menu_select_passive');
		// closing the menu, don't follow the href'd url
		return false;
	}
}
