var menu_punkt = null;
var menu = null;
var hideExecute = null;
var submenu_hide_timeout = 0.5;
var bild_show_arr = [];

function checkNewsletterAnmeldung() {
	if (document.forms.newsletter_form.newsletter_anmelden.value.length > 3) {
		document.forms.newsletter_form.submit();
	}
}

function menu_start(){
	buildAll();
	$('menu').descendants().each(function(top) {
	 if((top.hasClassName("popup_menu")) & ("A" == top.tagName)){
	    if(Element.visible(top)) {
	    	top.onmouseover = link_in;
	    }
	 }
	});
}

function link_in(){
	hideAll();
	menu_punkt = Element.extend(this);
	aparent = menu_punkt.up();
	aparent.descendants().each(function(top) {
	 if((top.hasClassName("popup_hover_js")) & ("UL" == top.tagName)){
		menu = top;
		menu.show();
    	menu.onmouseover = menu_in;
		menu.onmouseout = null;
		menu_punkt.onmouseout = link_out;
	 }
	});	
	return false;
}

function link_out() {
	menu_punkt.onmouseout = null;
	if (menu.onmouseout == null) submenu_tryhide();
}

function menu_out() {
	menu.onmouseout = null;
	if (menu_punkt.onmouseout == null) submenu_tryhide();
}

function menu_in() {
	menu.onmouseout = menu_out;
}

function submenu_tryhide() {
	if (hideExecute) hideExecute.stop();
	hideExecute = new PeriodicalExecuter(submenu_hide, submenu_hide_timeout);
}

function submenu_hide() {
	if (hideExecute) hideExecute.stop();
	if (!menu.onmouseout && !menu_punkt.onmouseout) {
		menu.onmouseover = null;
		hideAll();
	}
}

function hideAll() {
	$('menu').descendants().each(function(top) {
	 if((top.hasClassName("popup_hover_js")) & ("UL" == top.tagName)){
	    if(Element.visible(top)) {
	    	top.hide();
	    }
	 }
	});
}

function buildAll() {
	$('menu').descendants().each(function(top) {
	 if((top.hasClassName("popup_hover")) & ("UL" == top.tagName)){
    	top.hide();
		top.addClassName("popup_hover_js");
		top.removeClassName("popup_hover");
	 }
	});
}

function clearSearch(element) {
	if (element.value == "Suchbegriff eingeben") {
		element.value = "";
	}
}

function bildwechsel_execute() {
	var timestamp = (new Date().getTime()-timejetzt)/1000;
	// alert((bild_show_arr[0][0]*1+bild_show_arr[0][4]*1)+" <= "+timestamp);
	for(var i = 0;i < bild_show_arr.length;i++) {
		if (bild_show_arr[i][0]+bild_show_arr[i][4] <= timestamp) {
			arrImgs = bild_show_arr[i][3];
			Effect.Fade(arrImgs[bild_show_arr[i][1]], { duration: bild_show_arr[i][2] });
			bild_show_arr[i][1]++;
			if (bild_show_arr[i][1] >= arrImgs.length) bild_show_arr[i][1] = 0;
			Effect.Appear(arrImgs[bild_show_arr[i][1]], { duration: bild_show_arr[i][2] });
			bild_show_arr[i][0] = timestamp;
		}
	}
}

function bildwechsel() {
	timejetzt = new Date().getTime();
	$$('.bild_show').each(function(bildShowElement) {
		infos = bildShowElement.readAttribute('rel');
		fade = 0.75;
		secs = infos;
		arrImgs = [];
		bildShowElement = Element.extend(bildShowElement);
		if (infos.indexOf(" ") > 0) {
			fade = infos.slice(infos.indexOf(" ") + 1) * 1;
			secs = secs.slice(0,secs.indexOf(" "));
		}
		secs = secs * 1;
		bildShowElement.select('img').each(function(imgs) {
			arrImgs.push(imgs);
			imgs.hide();
			imgs.setStyle({position : 'absolute' });
			if (imgs.hasClassName("default")) {
				imgs.removeClassName("default");
			}			
		});
		
		bildShowElement.select('div').each(function(imgs) {
			arrImgs.push(imgs);
			imgs.hide();
			imgs.setStyle({position : 'absolute' });
			if (imgs.hasClassName("default")) {
				imgs.removeClassName("default");
			}			
		});
		
		bildShowElement.removeClassName("bild_show");
		if (arrImgs.length > 1) {
			bild_show_arr.push([0,0,fade,arrImgs,secs]);
		}
		if (arrImgs.length > 0) Effect.Appear(arrImgs[0], { duration: fade });
		
	});
	
	my_execute = new PeriodicalExecuter(Object.extend(bildwechsel_execute), 0.1);
}

script_loaded = true;


