var tg_list = new Array();


function tg(opener, element_nr){
	stopHide();

	element = $('s'+element_nr);

	$('menu_wrap').descendants().each(function(top) {
	 if(("sub" == top.className) & ("UL" == top.tagName)){
	    if(Element.visible(top)) {
	    	//$('mutsu').hasClassName('fruit');
	    	top.hide();
	    }
	 }

	});

	$('menu').descendants().each(function(top) {
	 if(("aktiv3" == top.className) & ("A" == top.tagName)){
	 	//alert('t: ' + top.up(0));
	 	//if (top.up(0) != undefined) {
		    if (top.up(0).className != 'top') {
		    	top.className = 'aktiv2';
		    }
		    else top.className = 'top';
	 	//}
	 }

	});

	if (element) {
		//var offset = Position.positionedOffset(opener);
		//element.style.top = offset[1] + "px";
		//element.style.top = (element_nr * 20) + "px";

		opener.className = 'aktiv3';
		element.show();
	}

	hideAllTop();

	//$('s'+element_nr).onmouseout = function () {
	//	triggerHide();
	//};
	//$('s'+element_nr).onmouseover = function () {
	//	stopHide()
	//}

	return false;
}


function hideAll() {
	$('menu_wrap').descendants().each(function(top) {
	 if(("sub" == top.className) & ("UL" == top.tagName)){
	    if(Element.visible(top)) {
	    	//$('mutsu').hasClassName('fruit');
	    	top.hide();
	    }
	 }

	});

	$('menu').descendants().each(function(top) {
	 if(("aktiv3" == top.className) & ("A" == top.tagName)){
	    if (top.up(0).className != 'top') {
	    	top.className = 'aktiv2';
	    }
	    else top.className = 'top';
	 }

	});
}

function hideAllTop() {
	for (var i=1;i<=4;i++) {
		//if (i != sub_id) {
			$('b'+i).style.display = 'none';
			if (i!=gruppe) $('ba'+i).style.display = 'none';
			//Effect.Fade("b" + i, {duration: 0.2});
		//}
	}
}

function toggleSub (sub_id) {
	stopHide();

	hideAll();

	$('b'+sub_id).style.display = 'block';
	$('ba'+sub_id).style.display = 'block';

	for (var i=1;i<=4;i++) {
		if (i != sub_id) {
			$('b'+i).style.display = 'none';
			$('b'+i).onmouseout = '';
			$('b'+i).onmouseover = '';
			if (i!=gruppe) $('ba'+i).style.display = 'none';
			//Effect.Fade("b" + i, {duration: 0.2});
		}
	}

	$('b'+sub_id).onmouseout = function () {
		triggerHide();
	};
	$('b'+sub_id).onmouseover = function () {
		stopHide()
	}

	debugInfo('toggleSub');
}

var trigger_interval = 0;

function setTrigger( elem ) {
	elem.onmouseout = function() {
		triggerHide();
		this.onmouseout = '';
	}
}

function triggerHide() {
	debugInfo('triggerHide');
	stopTrigger();
	trigger_interval = window.setInterval('triggerHideDo()', 300);
}

function triggerHideDo() {
	clearInterval(trigger_interval);
	debugInfo('triggerHideDo');
	hideAll();
	hideAllTop();
}

function stopTrigger() {
	if (trigger_interval) clearInterval(trigger_interval);
}

function stopHide() {
	debugInfo('stopHide');
	clearInterval(trigger_interval);
}

function debugInfo(text) {
	//$('debug').innerHTML = text;
}

var text_state = 0;
function toggleText() {
	if (text_state == 0) {
		$('info_text').style.display = 'none';
		$('info_liste').style.display = 'block';
		text_state = 1;

		$('toggle_link').innerHTML = 'Details ausblenden';
	}
	else {
		$('info_liste').style.display = 'none';
		$('info_text').style.display = 'block';
		text_state = 0;
		$('toggle_link').innerHTML = 'Details einblenden';
	}
}

window.onload = function() {
	if ($('links_wrap')) {
		$('links_wrap').onclick = function() {
			hideAll();
			hideAllTop();
		}
	}
	if ($('content_wrap')) {
		$('content_wrap').onclick = function() {
			hideAllTop();
		}
	}
	if ($('grafik')) {
		$('grafik').onclick = function() {
			hideAll();
		}
	}
	if ($('text_links')) {
		$('text_links').onclick = function() {
			hideAll();
		}
	}
}

var gal_pos = 0;
var gal_interval = false;
var cur_gal_anz = 0;
function showGalerie (anz) {
	$('lbOverlay').style.backgroundColor = Element.getStyle('ba'+gruppe, 'backgroundColor');

	if (anz > 1) {
		myLytebox.start($('img1'), true);
	}
	else myLytebox.start($('img1'), false);

}

function gotoUrl(url) {
	window.location.href = url;
}

function showGalerieNext() {
	gal_pos++;

	if (cur_gal_anz > gal_pos) {
		myLightbox.changeImage(gal_pos);
	}
	else clearInterval(gal_interval);
}