// Navigation

var arrId = new Array();

function initMenus() {
	//$('ul.menu ul.collapsed').hide('slow');

	$.each($('ul.menu'), function(){
		$('#' + this.id + '.expandfirst ul:first').show('slow');
	});

	$('ul.menu li a').hoverIntent(
		function() {
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;

			if($('#' + parent).hasClass('noaccordion')) {
				$(this).next().slideToggle('slow');
				return false;
			}
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' ul:visible').slideUp('slow');
				}
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp('slow');
				checkElement.slideDown('slow');
				return false;
			}
		}
		, function(){}
	);

}

//suche
	function lookup(query_string) {
		if(query_string.length == 0) {
			// Hide the suggestion box.
			$('#suggestions').hide();
		} else {
			$.post("./suche/autocomplete.php", {queryString: ""+query_string+""}, function(data){
				if(data.length >0) {
					$('#suggestions').show();
					$('#autoSuggestionsList').html(data);
				}
			});
		}
	} // lookup

	function fill(thisValue) {
		$('#query_string').val(thisValue);
		setTimeout("$('#suggestions').hide();", 200);
		if(thisValue!='' && thisValue != 'Suchbegriff eingeben'){
			document.forms['form_suche'].submit();
		}
	}

//Matrix
var bActiveId;
var bOnSelectBox = false;

function hideDiv(idx){
	$("#opt_"+idx).animate({ height: 'hide', opacity: 'hide' }, {duration: 'slow'});
	$("#opt_arrow_"+idx).attr('src', "../design_images/dropdown_pfeil_1.jpg");
}

function showDiv(idx){
	$("#opt_"+idx).animate({ height: 'show', opacity: 'show' }, {duration: 'slow'});
	$("#opt_arrow_"+idx).attr('src', "../design_images/dropdown_pfeil.jpg");
	bActiveId = idx;
	for(i=0;i<arrId.length;i++){
		if(arrId[i]!=idx){
			hideDiv(arrId[i]);
		}
	}
}

function checkForm(myForm){
	var bsubmit = false;
	for(i=0;i<myForm.length;i++){
		if(myForm.elements[i].type=='checkbox'){
			if(myForm.elements[i].checked==true){
				bsubmit = true;
			}
		}
	}
	if(!bsubmit){
		$("#search_msg").html('<span id="msg_error">Bitte w&auml;hlen Sie ein Suchkriterium aus.</span>');
	}
	return bsubmit;
}

function show(opt_layer){
	if (document.getElementById(opt_layer).style.display=="block"){
		document.getElementById(opt_layer).style.display="none";
	}else	document.getElementById(opt_layer).style.display="block";
}
function hide(opt_layer){
	document.getElementById(opt_layer).style.display="none";
}

function clickCheckBox(ele, str){

	if(ele.checked == true){
		removeSearchTerm('error');
		addSearchTerm(str, ele.value);
	}else{
		removeSearchTerm(ele.value);
	}

}

function addSearchTerm(val, idx){
	$("#search_msg").append('<span id="msg_'+idx+'">'+val+'<br/></span>');
}

function removeSearchTerm(idx){
	$("#msg_"+idx).remove();
}

	//suche
	function lookup(query_string) {
		if(query_string.length == 0) {
			// Hide the suggestion box.
			$('#suggestions').hide();
		} else {
			$.post("./suche/autocomplete.php", {queryString: ""+query_string+""}, function(data){
				if(data.length >0) {
					$('#suggestions').show();
					$('#autoSuggestionsList').html(data);
				}
			});
		}
	} // lookup

	function fill(thisValue) {
		$('#query_string').val(thisValue);
		setTimeout("$('#suggestions').hide();", 200);
		if(thisValue!='' && thisValue != 'Suchbegriff eingeben'){
			document.forms['form_suche'].submit();
		}
	}
