var menu_punkt = null;
var menu = null;
var hideExecute = null;
var submenu_hide_timeout = 0.5;

	var schiene_position = 0;
	var schiene_height = 0;
	var schiene_div;
	var schiene_last_time;
	var pause_schiene = false;

	function schiene_laufen() {
		schiene_div = $('img_laufleiste_bilder_wrap').firstDescendant();
		if(schiene_div != null)
		{
			if(newSchieneHeight == undefined)
			{
				schiene_height = (schiene_div.getHeight() / 2) + 5; // 5 px border
			}
			else
			{
				schiene_height = newSchieneHeight;
			}
			
			Element.extend(schiene_div).onmouseover = pauseSchiene;
			schiene_last_time = 0;
			new PeriodicalExecuter(schiebSchiene, (1/40));
		}
	}

	function pauseSchiene() {
		pause_schiene = true;
		Element.extend(schiene_div).onmouseout = resumeSchiene;
	}

	function resumeSchiene() {
		pause_schiene = false;
		schiene_div.onmouseout = "";
	}

	function schiebSchiene() {
		var time = new Date().getTime();
		
		if (schiene_last_time == 0 || pause_schiene) {
			schiene_last_time = time;
			return;
		}
		
		var diff = time - schiene_last_time;
		schiene_position -= (20 * (diff / 1000));
		schiene_last_time = time;
		if (schiene_position <= -schiene_height) {
			schiene_position = 0;
		}
		schiene_text = Math.round(schiene_position)+'px';
		schiene_div.setStyle({'top':schiene_text});
	}

function checkNewsletterAnmeldung() {
	if (document.forms.newsletter_form.newsletter_anmelden.value.length > 3) {
		document.forms.newsletter_form.submit();
	}
}

function checkNewsletterAbmeldung() {
	if (document.forms.newsletter_form.email.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 = '';
	}
}

var bild_show_arr = [];

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(top) {
		infos = top.readAttribute('rel');
		fade = 0.75;
		secs = infos;
		arrImgs = [];
		if (infos.indexOf(" ") > 0) {
			fade = infos.slice(infos.indexOf(" ") + 1) * 1;
			secs = secs.slice(0,secs.indexOf(" "));
		}
		secs = secs * 1;
		top.select('img').each(function(imgs) {
			arrImgs.push(imgs);
			imgs.hide();
			imgs.setStyle({position : 'absolute' });
			imgs.setStyle({ left: '0', top: '0'	});
			if (imgs.hasClassName("default")) {
				imgs.removeClassName("default");
			}
		});
		top.select('div').each(function(imgs) {
			arrImgs.push(imgs);
			imgs.hide();
			imgs.setStyle({position : 'absolute' });
			if (imgs.hasClassName("default")) {
				imgs.removeClassName("default");
			}			
		});
		top.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;



