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


function mouseoverGaleryImage(bild) {
	bild.style.border = "1px solid #eeeeee";
	bild.style.background = "#c8c8c8";
}

function mouseoutGaleryImage(bild) {
	bild.style.border = "1px solid #c0c0c0";
	bild.style.background = "#c0c0c0";
}

function showGallery(num) {
	var galerieDivs = $$('.galerie_box');
	for (var i=0; i<galerieDivs.length; i++) {
		galerieDivs[i].hide();
	}
	$('galerie_box'+num).show();
	var aktiveSeite = $$('.galerySeitenLink');
	for (var i=0; i<aktiveSeite.length; i++) {
		aktiveSeite[i].style.background = "#962e33";
	}
	$('galerie_seite'+num).style.background = "#a75448";
}

/*
window.onload = init_scripts;
window.onunload = exit_scripts;

function include_dom(script_filename) {
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
    return false;
}

function exit_scripts() {
}

function init_scripts() {
}
*/

/*
function bild_links_active() {
	if ($('boxen')) {
		$('boxen').descendants().each(function(top) {
			if("A" == top.tagName){
				top.onmouseover = bild_switch;
			}
		});
	}
}

function bild_switch() {
	link = Element.extend(this);
	link.childElements().each(function(top) {
		if (top.hasClassName("imgon")) {
			top.removeClassName("imgon");
			top.addClassName("imgoff");
		} else if (top.hasClassName("imgoff")) {
			top.removeClassName("imgoff");
			top.addClassName("imgon");
		}
	});
	if (link.onmouseover == bild_switch) {
		link.onmouseover = null;
		link.onmouseout = bild_switch;
	} else {
		link.onmouseover = bild_switch;
		link.onmouseout = null;
	}
}
*/

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' });
			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);
}

/*
function bildwechsel(){
	logos = 0;
	alert($('boxen').readAttribute('rel'));
	$('rechts_oben').childElements().each(function(top) {
		if (top.hasClassName("logo_hidden")) {
			top.hide();
			top.removeClassName("logo_hidden");
			logos++;
		}
	});
	Effect.Appear('logo_switch0', { duration: 0.75 });
	$('logo_switch0').addClassName("logo_used");
	if (logos > 1) {
		$('rechts_oben').onmouseover = bildwechsel_stop;
		bild_wechsel = new PeriodicalExecuter(bildwechsel_execute, 5.0);
	}
	
	logos = 0;
	$('boxen').childElements().each(function(top) {
		if (top.hasClassName("logo_hidden")) {
			top.hide();
			top.removeClassName("logo_hidden");
			logos++;
		}
	});
	Effect.Appear('logo_switch0', { duration: 0.75 });
	$('logo_switch0').addClassName("logo_used");
	if (logos > 1) {
		$('rechts_oben').onmouseover = bildwechsel_stop;
		bild_wechsel = new PeriodicalExecuter(bildwechsel_execute, 5.0);
	}
}

function bildwechsel_stop() {
	if (bild_wechsel) bild_wechsel.stop();
	$('rechts_oben').onmouseout = bildwechsel_resume;	
}

function bildwechsel_resume() {
	bild_wechsel = new PeriodicalExecuter(bildwechsel_execute, 5.0);
	$('rechts_oben').onmouseout = null;	
}

function bildwechsel_execute(){
	var i = 0;
	var finish = false;
	while($('logo_switch'+i) && !finish) {
		if (!$('logo_switch'+i).hasClassName("logo_used")) {
			Effect.Appear('logo_switch'+i, { duration: 0.75 });
			Effect.Fade('logo_switch'+(i-1), { duration: 0.75 });
			$('logo_switch'+i).addClassName("logo_used");
			finish = true;
		}
		i++;
	}
	if (!finish) { //alle Bilder durch, bild 0 einblenden
		$('rechts_oben').childElements().each(function(top) {
			if (top.hasClassName("logo_used")) {
				top.removeClassName("logo_used");
			}
		});
		$('logo_switch0').addClassName("logo_used");
		Effect.Fade('logo_switch'+(i-1), { duration: 0.75 });
		Effect.Appear('logo_switch0', { duration: 0.75 });
	}
}		
*/
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 modemov() {
	// $('box_klein_overlay_'+id).style.display = "none";
}

function showMarken() {
  //new Effect.Opacity('markenDiv', {from: 0.0, to: 1.0, duration: 1 });
  $('markenDiv').show();
}

function hideMarken() {
  //new Effect.Opacity('markenDiv', {from: 1.0, to: 0.0, duration: 1 });
  $('markenDiv').hide();
}

script_loaded = true;
