// Browsertests
var ns = (navigator.appName.search(/etscape+/) != -1);
var ns4 = (ns) & (navigator.appVersion.substring(0,1) == "4");

// aktiver hauptnavigationspunkt, z.b. wir_ueber_uns, produkte
active_navigation = 'null';
active_subnavigation = 'null';
current_navigation = 'null';

dynamic_static = 'static';

// variablen zur speicherung der navigationselemente
var main_navi = new main_navi_item();
var sub_navi = new sub_navi_item();

// daten der subnavigation
// !!!!!!!!!!!!!!!!!! bei absoluten pfad die punkte weglassen !!!!!!!!!!!!!!!!!!!!!!
new_main('home', '');
new_main('wir_ueber_uns', '/01_wir_ueber_uns/');
 new_sub('wir_ueber_uns', 'Das Unternehmen', '01_das_unternehmen.html');
 new_sub('wir_ueber_uns', 'Geschichte', '02_geschichte.html');
 new_sub('wir_ueber_uns', 'Qualit&auml;t', '03_qualitaet.html');
 new_sub('wir_ueber_uns', 'H&auml;ufige Fragen', '04_haeufige_fragen.html');
 //new_sub('wir_ueber_uns', 'Ern&auml;hrungs-Coach', '05_coach.php');
 new_sub('wir_ueber_uns', 'Werbung', '06_werbung.html');
new_main('produkte', '/02_produkte/');
 new_sub('produkte', 'Fish & Dip ', '01_fish_dip.html');
// new_sub('produkte', 'Fish & Dip Snack-Format', '09_fish_dip_snack.html');
 new_sub('produkte', 'Meeres-St&auml;bchen', '03_meeres_staebchen.html');
 new_sub('produkte', 'Meeres-Aufschnitt', '04_meeres_aufschnitt.html');
  new_sub('produkte', 'Fisch-Frikadellen', '15_frikadellen.html');
 new_sub('produkte', 'Kaufinfo', '05_kaufinfo.html');
 //new_sub('produkte', 'Aktuelles', '14_aktuelles.html');
// new_sub('produkte', 'Meeres-Raspel', '13_meeres_raspel.html');
 //new_sub('produkte', 'Meeres-Salate', '07_meeres_salate.html');
 //new_sub('produkte', 'Meeres-Aufstrich', '10_meeres_aufstrich.html');

new_main('kreative_kueche', '/03_kreative_kueche/');
 new_sub('kreative_kueche', 'Fish & Dip', '01_rezepte_fish_dip.html');
 new_sub('kreative_kueche', 'Meeres-St&auml;bchen', '03_rezepte_meeres_staebchen.html');
 new_sub('kreative_kueche', 'Meeres-Aufschnitt', '04_rezepte_meeres_aufschnitt.html');
 //new_sub('kreative_kueche', 'Meeres-Raspel', '13_rezepte_meeres_raspel.html');
 //new_sub('kreative_kueche', 'Meeres-Salate', '07_rezepte_meeres_salate.html');
 //new_sub('kreative_kueche', 'Meeres-Aufstrich', '10_rezepte_meeres_aufstrich.html');
 new_sub('kreative_kueche', 'Tipps', '05_tipps.html');
new_main('fit_mit_coraya', '/04_fit_mit_coraya/');
 new_sub('fit_mit_coraya', 'Gesund genie&szlig;en', '01_gesund_geniessen.html');
 new_sub('fit_mit_coraya', 'N&auml;hrwertangaben', '02_naehrwertangaben.html');
new_main('presse', '/05_presse/');
 new_sub('presse', 'Pressemitteilungen', '01_pressemitteilungen_01.html');
//new_sub('presse', 'Presse Archiv', '02_presse_archiv_01.html');
 new_sub('presse', 'Fotomaterial', '03_fotomaterial_01.html');
 new_sub('presse', 'Pressekontakt', '04_pressekontakt.php');
new_main('kontakt', '/06_kontakt/');
 new_sub('kontakt', 'Impressum', '01_impressum.html');
 new_sub('kontakt', 'Rechtlicher Hinweis', '02_rechtlicher_hinweis.html');

// mousevents
var mouse_x, mouse_y;
var mouse_controler = false;

function handlerMM(e) {
	mouse_x = ns ? e.pageX : document.body.scrollLeft + event.clientX;
	mouse_y = ns ? e.pageY : document.body.scrollTop + event.clientY;
}

if (ns4)
	document.captureEvents(Event.MOUSEMOVE);

document.onmousemove = handlerMM;

	
// &uuml;berwacht den mauszeiger, bei markierung von men&uuml;punkten	
function start_mouse_controle() {
	mouse_controler = true;
	eval("x = getImageX(window.document.navi_wir_ueber_uns)-5;");	
	eval("y = getImageY(window.document.navi_wir_ueber_uns)-5;");
	navi_area_x1 = x;
	navi_area_y1 = y+5;
	navi_area_x2 = x+800;
	navi_area_y2 = (dynamic_static == 'dynamic') ? y+40 : y+23;
	
	if (current_navigation != active_navigation) {
		if ((mouse_x < navi_area_x1) || (mouse_x > navi_area_x2))
			navi_event(current_navigation, 'norm');
		else if ((mouse_y < navi_area_y1) || (mouse_y > navi_area_y2))
			navi_event(current_navigation, 'norm');
		timer = setTimeout("start_mouse_controle();", 100);
	}
	else mouse_controler = false;
}

// HAUPTNAVIGATION

// vorladegrafiken 
/*
status: NORMal, mouseOVER, mouseDOWN
grafikname_norm = new Image(); grafikname_norm.src = "../shared/navigation/grafikname.gif";
grafikname_over = new Image(); grafikname_over.src = "../shared/navigation/grafikname_over.gif";
grafikname_down = new Image(); grafikname_down.src = "../shared/navigation/grafikname_down.gif";
*/

wir_ueber_uns_norm = new Image(); wir_ueber_uns_norm.src = "/shared/navigation/wir_ueber_uns.gif";
wir_ueber_uns_over = new Image(); wir_ueber_uns_over.src = "/shared/navigation/wir_ueber_uns_over.gif";
wir_ueber_uns_down = new Image(); wir_ueber_uns_down.src = "/shared/navigation/wir_ueber_uns_down.gif";

produkte_norm = new Image(); produkte_norm.src = "/shared/navigation/produkte.gif";
produkte_over = new Image(); produkte_over.src = "/shared/navigation/produkte_over.gif";
produkte_down = new Image(); produkte_down.src = "/shared/navigation/produkte_down.gif";

kreative_kueche_norm = new Image(); kreative_kueche_norm.src = "/shared/navigation/kreative_kueche.gif";
kreative_kueche_over = new Image(); kreative_kueche_over.src = "/shared/navigation/kreative_kueche_over.gif";
kreative_kueche_down = new Image(); kreative_kueche_down.src = "/shared/navigation/kreative_kueche_down.gif";

fit_mit_coraya_norm = new Image(); fit_mit_coraya_norm.src = "/shared/navigation/fit_mit_coraya.gif";
fit_mit_coraya_over = new Image(); fit_mit_coraya_over.src = "/shared/navigation/fit_mit_coraya_over.gif";
fit_mit_coraya_down = new Image(); fit_mit_coraya_down.src = "/shared/navigation/fit_mit_coraya_down.gif";

presse_norm = new Image(); presse_norm.src = "/shared/navigation/presse.gif";
presse_over = new Image(); presse_over.src = "/shared/navigation/presse_over.gif";
presse_down = new Image(); presse_down.src = "/shared/navigation/presse_down.gif";

kontakt_norm = new Image(); kontakt_norm.src = "/shared/navigation/kontakt.gif";
kontakt_over = new Image(); kontakt_over.src = "/shared/navigation/kontakt_over.gif";
kontakt_down = new Image(); kontakt_down.src = "/shared/navigation/kontakt_down.gif";

// wechselt grafiken der navigationselement aus
function navi_event(navi_img, m_event) {
	// bei mouseover wird der derzeit markierte punkt demarkiert
	if ((current_navigation != 'null') & (current_navigation != navi_img))
		navi_event(current_navigation, 'norm');
	// nur wenn der men&uuml;punkt nicht (!norm) auf normal gestellt wird, wird current_navigation gesetzt
	if (m_event != 'norm')
		current_navigation = navi_img;
	// bei markierung eines punktes wird der mausbereichs-controler aktiviert
	if ((mouse_controler == false) & (active_navigation != current_navigation)) 
		start_mouse_controle(); 

	if (active_navigation != navi_img) {
		img = eval("window.document.navi_"+navi_img);
		if (img) { // abfanen, ob grafik existiert/geladen ist
			img_new = eval(navi_img+"_"+m_event);
			img.src = img_new.src;
			// subbnavigation einblenden
			if ((dynamic_static == 'dynamic') & (!ns4)) {
				eval("x = getImageX(window.document.navi_wir_ueber_uns)-5;");	
				eval("y = getImageY(window.document.navi_wir_ueber_uns)-5;");	
				dhtml_setX('sub_'+navi_img, x+5);
				dhtml_setY('sub_'+navi_img, y+22);
				dhtml_show('sub_'+navi_img); 
				if (m_event == 'norm') 
					dhtml_hide('sub_'+navi_img);
			} 
		}
	}
}

// setzt den aktiven hauptnavigationspunkt, z. b. wir_ueber_uns
function set_active_navigation(n, d_s) {
	active_navigation = n;
	if (d_s != null) 
		dynamic_static = d_s;
}

// HAUPTNAVIGATION END


// SUBNAVIGATION

// setzt den aktiven subnavigationspunkt, z. b. rezeptansicht
function set_active_subnavigation(n) {
	active_subnavigation = n;
}

// vorladegrafiken 
sub_arrow_norm = new Image(); sub_arrow_norm.src = "../shared/pfeil_weiss.gif";
sub_arrow_over = new Image(); sub_arrow_over.src = "../shared/pfeil_blau.gif";

// setzt den subnavigationspunkt, die pfeilgrafik
function sub_navi_event(nr, m_event) { 
	img = eval("window.document.sub_arrow_"+nr);
	img_new = eval("sub_arrow_"+m_event);
	if (!ns4)
		img.src = img_new.src;
}

// funktionalitaet der subnavigation
function main_navi_item() {
	this.pos = 0;
	this.name = new Array();
	this.url = new Array();
	return this;
}

function sub_navi_item() {
	this.pos = 0;
	this.main = new Array();
	this.name = new Array();
	this.url = new Array();
	return this;
}

function new_main(name, url) {
	main_navi.name[main_navi.pos] = name;
	main_navi.url[main_navi.pos] = url;
	main_navi.pos++;
}

function new_sub(main, name, url) {
	sub_navi.main[sub_navi.pos] = main;
	sub_navi.name[sub_navi.pos] = name;
	sub_navi.url[sub_navi.pos] = url;
	sub_navi.pos++;
}

//maximal-anzahl der subnavigationselemente (pro zeile)
sub_max = 6;
sub_percentage = Math.round((100)/sub_max);

// schreibe dynamische subnavigation
function write_sub_navi(active_sub) {
		for (var d=0; d<main_navi.pos; d++) 
			// bug bei netscape 4: netscape 4 stuertzt ab, wenn write_sub ausgefuehrt wird; grund unbekannt; rekursionstiefe wurde kontrolliert
			//if (((ns4) & (main_navi.name[d] == active_sub)) | (!ns4))
			if (main_navi.name[d] == active_sub)
				write_sub(d, active_sub);

}

function write_sub(i, active_sub) { 
	var saved_url = document.URL; 
	
	if (main_navi.name[i] != active_sub) 
		document.write('\n<div id="sub_'+main_navi.name[i]+'" style="position: absolute; visibility:hidden; left:0px; top:0px">');
	
	document.write('<table width="800" border="0" bgcolor="#81ABD3" cellspacing="0" cellpadding="0">');
	subcount = 0;
	firstrow = true;	// 
	for (var j=0; j<sub_navi.pos; j++) {
		
		if (main_navi.name[i] == sub_navi.main[j]) {
			if ((subcount%6 == 0) && firstrow ) document.write('<tr>');
			//alert("for " + subcount + " von " + sub_navi.pos);
			subcount++;
			if (subcount==7 ) { 
				subcount=0;
				firstrow = false;
			}
			//alert("for " + subcount);
			document.write('<td height="15" width="'+sub_percentage+'%" bgcolor="#81ABD3">');
			// markiert aktiven submen&uuml;punkt
			if (saved_url.search(sub_navi.url[j]) != -1) {
				document.write('<a href="#top" class="subnavidown">');
				document.write('<img name="sub_arrow_0'+j+'" src="../shared/pfeil_blau.gif" border="0" width="14" height="8">');
				document.write(sub_navi.name[j].replace(/ /g,"&nbsp;")+'</a></td>');
			}
			else if (active_subnavigation.search(sub_navi.url[j]) != -1) {
				document.write('<a href="'+main_navi.url[i]+sub_navi.url[j]+'" class="subnavidown">');
				document.write('<img name="sub_arrow_0'+j+'" src="../shared/pfeil_blau.gif" border="0" width="14" height="8">');
				document.write(sub_navi.name[j].replace(/ /g,"&nbsp;")+'</a></td>');
			}
			else {
				document.write('<a href="'+main_navi.url[i]+sub_navi.url[j]+'" onMouseOut="sub_navi_event(\'0'+j+'\', \'norm\')" onMouseOver="sub_navi_event(\'0'+j+'\', \'over\')" class="subnavi">');
				document.write('<img name="sub_arrow_0'+j+'" src="../shared/pfeil_weiss.gif" border="0" width="14" height="8">');
				document.write(sub_navi.name[j].replace(/ /g,"&nbsp;")+'</a></td>');
			}
			if (subcount < sub_max)
				document.write('<td width="1" bgcolor="#81ABD3" align="right"><img src="../shared/pixel_weiss.gif" width="1" height="15"></td>');	
				
			if (subcount==6) document.write('</tr><tr><td height="1" bgcolor="#ffffff" colspan="99"></td></tr>');
		}
		
	}
	while (subcount < sub_max) {
		subcount++;
		//alert("while " + subcount);
		document.write('<td width="'+sub_percentage+'%" bgcolor="#81ABD3">');
		document.write('<img src="../shared/pixel.gif" width="14" height="8">');
		document.write('</td>');
		if (subcount < sub_max)
			document.write('<td width="1" bgcolor="#81ABD3" align="right"><img src="../shared/pixel.gif" width="1" height="15"></td>');		
	}
	document.write('</tr></table>');
	if (main_navi.name[i] != active_sub)
		document.write('</div>');	
}


function getImageX ( image ) {
	// calculate horizontal position of an image
	var xPos = 0;
	if (document.layers) {
		xPos = image.x;
	}
	else {
		do {
			xPos += image.offsetLeft;
			image = image.offsetParent;
		} while ( image );
	}
	return xPos;
}

function getImageY ( image ) {
	// calculate vertical position of an image
	var yPos = 0;
	if (document.layers) {
		yPos = image.y;
	}
	else {
		do {
			yPos += image.offsetTop; 
			image = image.offsetParent;
		} while ( image );
	}
	return yPos;
}

function dhtml_support() {
  return (document.layers || 
          document.all || 
          document.getElementById)
}
function dhtml_obj(id) {
  if (document.layers)
    return document.layers[id];
  else if (document.all)
    return document.all[id];
  else if (document.getElementById)
    return document.getElementById(id);
}
function dhtml_style(id) {
  if (document.layers)
    return dhtml_obj(id);
  else if (document.layers || document.getElementById)
    return dhtml_obj(id).style;
}
function dhtml_hide(id) {
  if (dhtml_support())
    dhtml_style(id).visibility = "hidden";
}
function dhtml_show(id) {
  if (dhtml_support())
    dhtml_style(id).visibility = "visible";
}
function dhtml_getX(id) {
  if (dhtml_support())
    if (document.layers || document.getElementById)
      return dhtml_style(id).left;
    else
      return dhtml_style(id).posLeft;
}
function dhtml_getY(id) {
  if (dhtml_support())
    if (document.layers || document.getElementById)
      return dhtml_style(id).top;
    else
      return dhtml_style(id).posTop;
}
function dhtml_setX(id, n) {
  if (dhtml_support())
    if (document.layers) 
      dhtml_style(id).left = n;
    else if (document.getElementById)
      dhtml_style(id).left = n + "px";
    else
      dhtml_style(id).posLeft = n + "px";
}
function dhtml_setY(id, n) {
  if (dhtml_support())
    if (document.layers)
      dhtml_style(id).top = n;
    else if (document.getElementById)
      dhtml_style(id).top = n + "px";
    else
      dhtml_style(id).posTop = n + "px";
}
function dhtml_moveTo(id, x, y) {
  if (dhtml_support()) {
    dhtml_setX(id, x);
    dhtml_setY(id, y);
  }
}
function dhtml_moveBy(id, deltaX, deltaY) {
  if (dhtml_support()) {
    var x = parseInt(dhtml_getX(id));
    var y = parseInt(dhtml_getY(id));
    x += deltaX;
    y += deltaY;
    dhtml_setX(id, x);
    dhtml_setY(id, y);
  }
}
function dhtml_text(id, text) {
  if (dhtml_support())
    if (document.layers)
      with (document.layers[id].document) {
        open();
        write(text);
        close();
      }
    else
      dhtml_obj(id).innerHTML = text;
}
function dhtml_breite() {
  if (window.innerWidth)
    return window.innerWidth;
  else if (document.body)
    return document.body.clientWidth;
}
function dhtml_hoehe() {
  if (window.innerHeight)
    return window.innerHeight;
  else if (document.body)
    return document.body.clientHeight;
}
function dhtml_style_breite(id) {
  if (document.layers)
    return dhtml_obj(id).document.width;
  else if (document.all || document.getElementById)
    return dhtml_obj(id).offsetWidth;
}
function dhtml_style_hoehe(id) {
  if (document.layers)
    return dhtml_obj(id).document.height;
  else if (document.all || document.getElementById)
    return dhtml_obj(id).offsetHeight;
}

// SUBNAVIGATION END
