var topNaviElements = 9;
var topNaviColors = new Array("","#09C","#069","#039","#036","#666","#999","#C99","#C66","#C00");
var topNaviActive = 0;
var topNaviPreload = false;
var mkn1stWin;
var mkn2ndWin;
var mkn3rdWin;
var citeWin;


function commonNav(imgfolder) {
	this.newselection = 0;
	this.oldselection = 0;
	this.itemActive = 0;
	if (!imgfolder) this.imgfolder=""
		else this.imgfolder = imgfolder;
	
	this.on = mon;
	this.off = moff;
	this.sel = selection;
} 

function mon(which) {
	if (document.images) {
		if(document.getElementById) 
			document.getElementById(which).src = this.imgfolder + which + "_on.gif";
		else
			document.images[which].src = this.imgfolder + which + "_on.gif";
		this.itemActive = which;
	}
}
function moff(which) {
	if (document.images) {
		if(this.itemActive!=this.oldselection) {
			if(document.getElementById)
				document.getElementById(which).src = this.imgfolder + which + "_off.gif";
			else
				document.images[which].src = this.imgfolder + which + "_off.gif";
		}
	}
}
function selection(which) {
	this.newselection = which;
	if((this.oldselection!=0)&&(this.newselection!=this.oldselection))
		this.off(this.oldselection);
	this.on(this.newselection);
	this.oldselection=this.newselection;
}

function mknMainNav(imgfolder,dummyImg,imgExt)  {
	// Daten
	this.newselection = 0;
	this.oldselection = 0;
	this.itemActive = 0;
	this.imgfolder=imgfolder;
	if (!imgfolder) this.imgfolder="";
	this.dummy = dummyImg;
	this.ext = imgExt;
	
	// Methoden	
	this.on = actNavi;
	this.off = unactNavi;
	this.sel = lockNavi;
} 

function actNavi(which) 
{
	if (document.images) {
		if(document.getElementById) { 
			document.getElementById(this.dummy).src = this.imgfolder + which + this.ext +".gif";
			document.getElementById(this.ext + which).style.backgroundColor=topNaviColors[which];
		}
		else {
			document.images[this.dummy].src = this.imgfolder + which + this.ext +".gif";
		}
		this.itemActive = which;
	}
}

function unactNavi() 
{
	if (document.images) {
		if(this.itemActive!=this.oldselection) {
			if(document.getElementById) {
				document.getElementById(this.dummy).src = this.imgfolder + this.oldselection + this.ext +".gif";
				document.getElementById(this.ext + this.itemActive).style.backgroundColor='#FFF';
			} else {
				document.images[this.dummy].src = this.imgfolder + this.oldselection + this.ext +".gif";
			}
		}
	}
}


function lockNavi(which) 
{
	this.newselection = which;
	if((this.oldselection!=0)&&(this.newselection!=this.oldselection))
		this.off(this.oldselection) 
	this.on(this.newselection);
	this.oldselection=this.newselection;
}

function newTheme(which) {
     if (document.images) {
          that = new Image();
          that.src = which;
          return that;
     }
}

function preloadImages()
{
  if(document.images)
  {
    if(!document.imageArray) document.imageArray = new Array();
    var i,j = document.imageArray.length, args = preloadImages.arguments;
    
    for(i=0; i<args.length; i++)
    {
      if (args[i].indexOf("#")!=0)
      {
        document.imageArray[j] = new Image;
        document.imageArray[j++].src = args[i];
      }
    }
  }
}

function MM_preloadImages() 
{
	var d=document;
	if(d.images) 
	{ 
		if(!d.MM_p) d.MM_p=new Array();
		var j=d.MM_p.length;
		for(var i=0; i<arguments.length; i++)
		{
			d.MM_p[j]=new Image;
			d.MM_p[j++].src=arguments[i];
		}
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() 
{
	var i,j=0,x;
	document.MM_sr=new Array;
	for(i=0;i<(arguments.length-2);i+=3)
		if ((x=MM_findObj(arguments[i]))!=null)
		{
			document.MM_sr[j++]=x;
			if(!x.oSrc) x.oSrc=x.src; 
			x.src=arguments[i+2];
		}
}

function openMknWin(url,no)
{
	var size_x;
	var size_y;
	if (no == 1) {
		if(opener) {
			top.opener.location.href=url;
			setTimeout('top.opener.focus()',200);
		} else {
			mkn1stWin = window.open(url,'mkn1stWin','toolbar=1,location=1,directories=1,status=1,menubar=1,resizable=1,scrollbars=1,titlebar=1,top=0,left=0');
			setTimeout('mkn1stWin.focus()',200);
			if (mkn2ndWin) mkn2ndWin.close();
		}
	} else if (no == 3) {
		mkn3rdWin = window.open(url,'mkn3rdWin','toolbar=1,location=1,directories=1,status=1,menubar=1,resizable=1,scrollbars=1,titlebar=1,top=0,left=0');
 		setTimeout('mkn3rdWin.focus()',200);
	} else if (no == 4) {
		// size_x = getMaxWidth(10);
		// size_y = getMaxHeight(10);
		size_x = 800;
		size_y = 600;
 		mknPicView = eval("window.open(url,'mknPicView','toolbar=0,location=0,directories=0,status=1,menubar=0,resizable=1,scrollbars=1,titlebar=1,top=10,left=10,width=" + size_x +",height=" + size_y + "')");
 		setTimeout('mknPicView.focus()',200);
	} else {
		// size_x = getMaxWidth(50);
		// size_y = getMaxHeight(155);
		size_x = 800;
		size_y = 600;
 		mkn2ndWin = eval("window.open(url,'mkn2nWin','toolbar=1,location=1,directories=0,status=1,menubar=0,resizable=1,scrollbars=1,titlebar=1,top=155,left=50,width=" + size_x +",height=" + size_y + "')");
 		setTimeout('mkn2ndWin.focus()',200);
	}
}

function layerControl(id,anz)
{
	this.sel = null;
	if (anz) this.anz = anz
		else anz = 1;
	if (id) this.id = id
		else id = "r_div";
		
	this.hide = function hideLayer(which) {
		if (document.getElementById) {
			if (this.sel) {
				which = this.sel
				document.getElementById(which).style.visibility = "hidden";
				document.getElementById(which).style.display = "none";
			} 
		}
	}
	this.hideAll = function hideAllLayers() {
		if (document.getElementById) {
			for (var i=1; i<= this.anz; i++) {
				document.getElementById(id+i).style.visibility = "hidden";
				document.getElementById(id+i).style.display = "none";
			}
		}
	}
	this.show = function showLayer(which) {
		if (document.getElementById) {
			this.hide(this.sel);
			document.getElementById(which).style.visibility = "visible";
			document.getElementById(which).style.display = "block";
			this.sel = which;
		}
	}
}

function mknReiter(anz,id,loc) {
	this.img = new commonNav(loc);
	this.div = new layerControl(id,anz);
	
	this.clicked = function clicked(imgName,divName) {
		this.div.hideAll();
		this.img.sel(imgName);
		this.div.show(divName);
	}
}


function highlight(disable)  {
	// Daten
	this.imgborder_off = "solid 2px #fff";
	this.imgborder_on = "solid 2px #09c";
	this.textcolor_off = "#09c";
	this.textcolor_on = "#fff";
	this.textback_off = "#fff";
	this.textback_on = "#09c";
	this.disable = disable;
	
	// Methoden	
	this.forget = forget;
	this.activate = activate;
		
 	// BEISPIEL:
	// <a href="#" onmouseout="high.forget('img',4,5);high.forget('txt',4)" onmouseover="high.show('img',4,5);high.show('txt',4)">test</a>
	// Textlink "test" (mit Index 4) bezieht sich auf Bilder 4 und 5 und aktiviert diese bei Mouseover.
} 


function forget() 
{
	if(document.getElementById && !this.disable) 
	{
	for(var i = 1; i < arguments.length; i++)
		{
			var image;
			var text;

			if (arguments[0]=="img")
			{
				image = "image" + arguments[i];
				document.getElementById(image).style.border = this.imgborder_off;
			}
			else if (arguments[0]=="txt")
			{
				text = "text" + arguments[i];
				document.getElementById(text).style.color= this.textcolor_off;
				document.getElementById(text).style.background= this.textback_off;
			}
			if (arguments[0]=="vv")
			{
				image = "image" + arguments[i];
				document.getElementById(image).style.border = this.imgborder_off;
				text = "text" + arguments[i];
				document.getElementById(text).style.color= this.textcolor_off;
				document.getElementById(text).style.background= this.textback_off;
			}
		}
	}
}

function activate() 
{
	if(document.getElementById && !this.disable) 
	{
		var image;
		var text; 
		for(var i = 1; i < arguments.length; i++)
		{
			if (arguments[0]=="img")
			{
				image = "image" + arguments[i];
				document.getElementById(image).style.border = this.imgborder_on;
			}
			if (arguments[0]=="txt")
			{
				text = "text" + arguments[i];
				document.getElementById(text).style.color= this.textcolor_on;
				document.getElementById(text).style.background= this.textback_on;
			}
			if (arguments[0]=="vv")
			{
				image = "image" + arguments[i];
				document.getElementById(image).style.border = this.imgborder_on;
				text = "text" + arguments[i];
				document.getElementById(text).style.color= this.textcolor_on;
				document.getElementById(text).style.background= this.textback_on;
			}
				
		}
	}
}

function getSel(uri, title, author, year, lang)
{
	var sel;
	if (window.getSelection) sel = window.getSelection();
	else if (document.getSelection) sel = document.getSelection();
	else if (document.selection) sel = document.selection.createRange().text;
	if(sel != false) 
	{
	 sel = replaceSpecialChars(sel);
	 title = replaceSpecialChars(title);
	 url = "/mkn_zitatgenerator.php?sel=" + escape(sel) + "&uri=" + encodeURI(uri) + "&t=" + escape(title) + "&a=" + escape(author) + "&y=" + escape(year) + "&l=" + escape(lang);
	 citeWin = window.open(url,"zitat","width=550,height=450,left=0,top=0,resizable=no,scrollbars=yes,location=no");
	 setTimeout('citeWin.focus()',200);
	}
	else
	{
		var message = "Um ein Zitat zu erstellen, markieren Sie bitte zuerst den gewünschten Textabschnitt mit der Maus und klicken dann auf das Zitat-Icon.";
		if(lang == "en") message = "If you wish to generate a quote, please use the mouse to mark the respective text, then click on the quote-icon.";
		alert (message);
	}
}

function replaceSpecialChars(where)
{
	// das sollte man irgenwann mal zusammenfassen
	where = "" + where + "";
	out = "";
	for(n = 0; n < where.length; n++)
	{
		c=where.charAt(n);
		if(c == String.fromCharCode(8734)) c = "&#8734;" // unendlich
		if(c == String.fromCharCode(8594)) c = "&#8594;" // Rechtspfeil
		out = out + c;
	}
	where = out;
	where = where.replace(/¡/g, "&iexcl;");
	where = where.replace(/¢/g, "&cent;");
	where = where.replace(/£/g, "&pound;");
	where = where.replace(/¤/g, "&curren;");
	where = where.replace(/¥/g, "&yen;");
	where = where.replace(/¦/g, "&brvbar;");
	where = where.replace(/§/g, "&sect;");
	where = where.replace(/¨/g, "&uml;");
	where = where.replace(/©/g, "&copy;");
	where = where.replace(/ª/g, "&ordf;");
	where = where.replace(/«/g, "&laquo;");
	where = where.replace(/¬/g, "&not;");
	where = where.replace(/­/g, "&shy;");
	where = where.replace(/®/g, "&reg;");
	where = where.replace(/¯/g, "&macr;");
	where = where.replace(/°/g, "&deg;");
	where = where.replace(/±/g, "&plusmn;");
	where = where.replace(/²/g, "&sup2;");
	where = where.replace(/³/g, "&sup3;");
	where = where.replace(/´/g, "&acute;");
	where = where.replace(/µ/g, "&micro;");
	where = where.replace(/¶/g, "&para;");
	where = where.replace(/·/g, "&middot;");
	where = where.replace(/¸/g, "&cedil;");
	where = where.replace(/¹/g, "&sup1;");
	where = where.replace(/º/g, "&ordm;");
	where = where.replace(/»/g, "&raquo;");
	where = where.replace(/¼/g, "&frac14;");
	where = where.replace(/½/g, "&frac12;");
	where = where.replace(/¾/g, "&frac34;");
	where = where.replace(/¿/g, "&iquest;");
	where = where.replace(/À/g, "&Agrave;");
	where = where.replace(/Á/g, "&Aacute;");
	where = where.replace(/Â/g, "&Acirc;");
	where = where.replace(/Ã/g, "&Atilde;");
	where = where.replace(/Ä/g, "&Auml;");
	where = where.replace(/Å/g, "&Aring;");
	where = where.replace(/Æ/g, "&AElig;");
	where = where.replace(/Ç/g, "&Ccedil;");
	where = where.replace(/È/g, "&Egrave;");
	where = where.replace(/É/g, "&Eacute;");
	where = where.replace(/Ê/g, "&Ecirc;");
	where = where.replace(/Ë/g, "&Euml;");
	where = where.replace(/Ì/g, "&Igrave;");
	where = where.replace(/Í/g, "&Iacute;");
	where = where.replace(/Î/g, "&Icirc;");
	where = where.replace(/Ï/g, "&Iuml;");
	where = where.replace(/Ð/g, "&ETH;");
	where = where.replace(/Ñ/g, "&Ntilde;");
	where = where.replace(/Ò/g, "&Ograve;");
	where = where.replace(/Ó/g, "&Oacute;");
	where = where.replace(/Ô/g, "&Ocirc;");
	where = where.replace(/Õ/g, "&Otilde;");
	where = where.replace(/Ö/g, "&Ouml;");
	where = where.replace(/×/g, "&times;");
	where = where.replace(/Ø/g, "&Oslash;");
	where = where.replace(/Ù/g, "&Ugrave;");
	where = where.replace(/Ú/g, "&Uacute;");
	where = where.replace(/Û/g, "&Ucirc;");
	where = where.replace(/Ü/g, "&Uuml;");
	where = where.replace(/Ý/g, "&Yacute;");
	where = where.replace(/Þ/g, "&THORN;");
	where = where.replace(/ß/g, "&szlig;");
	where = where.replace(/à/g, "&agrave;");
	where = where.replace(/á/g, "&aacute;");
	where = where.replace(/â/g, "&acirc;");
	where = where.replace(/ã/g, "&atilde;");
	where = where.replace(/ä/g, "&auml;");
	where = where.replace(/å/g, "&aring;");
	where = where.replace(/æ/g, "&aelig;");
	where = where.replace(/ç/g, "&ccedil;");
	where = where.replace(/è/g, "&egrave;");
	where = where.replace(/é/g, "&eacute;");
	where = where.replace(/ê/g, "&ecirc;");
	where = where.replace(/ë/g, "&euml;");
	where = where.replace(/ì/g, "&igrave;");
	where = where.replace(/í/g, "&iacute;");
	where = where.replace(/î/g, "&icirc;");
	where = where.replace(/ï/g, "&iuml;");
	where = where.replace(/ð/g, "&eth;");
	where = where.replace(/ñ/g, "&ntilde;");
	where = where.replace(/ò/g, "&ograve;");
	where = where.replace(/ó/g, "&oacute;");
	where = where.replace(/ô/g, "&ocirc;");
	where = where.replace(/õ/g, "&otilde;");
	where = where.replace(/ö/g, "&ouml;");
	where = where.replace(/÷/g, "&divide;");
	where = where.replace(/ø/g, "&oslash;");
	where = where.replace(/ù/g, "&ugrave;");
	where = where.replace(/ú/g, "&uacute;");
	where = where.replace(/û/g, "&ucirc;");
	where = where.replace(/ü/g, "&uuml;");
	where = where.replace(/ý/g, "&yacute;");
	where = where.replace(/þ/g, "&thorn;");
	where = where.replace(/ÿ/g, "&yuml;");
	where = where.replace(/ƒ/g, "&fnof;");
	where = where.replace(/•/g, "&bull;");
	where = where.replace(/…/g, "&hellip;");
	where = where.replace(/™/g, "&trade;");
	where = where.replace(/"/, "&quot;");
	where = where.replace(/</g, "&lt;");
	where = where.replace(/>/g, "&gt;");
	where = where.replace(/Œ/g, "&OElig;");
	where = where.replace(/œ/g, "&oelig;");
	where = where.replace(/Š/g, "&Scaron;");
	where = where.replace(/š/g, "&scaron;");
	where = where.replace(/Ÿ/g, "&Yuml;");
	where = where.replace(/ˆ/g, "&circ;");
	where = where.replace(/˜/g, "&tilde;");
	where = where.replace(/–/g, "&ndash;");
	where = where.replace(/—/g, "&mdash;");
	where = where.replace(/‘/g, "&lsquo;");
	where = where.replace(/’/g, "&rsquo;");
	where = where.replace(/‚/g, "&sbquo;");
	where = where.replace(/“/g, "&ldquo;");
	where = where.replace(/”/g, "&rdquo;");
	where = where.replace(/„/g, "&bdquo;");
	where = where.replace(/†/g, "&dagger;");
	where = where.replace(/‡/g, "&Dagger;");
	where = where.replace(/‰/g, "&permil;");
	where = where.replace(/‹/g, "&lsaquo;");
	where = where.replace(/›/g, "&rsaquo;");
	where = where.replace(/€/g, "&euro;");
	return where;
}


function changeClass(id,cssClass){
    var elem = document.getElementById(id);
	elem.className = cssClass;
 }
 
 function switchClass() {
	this.newselection = 0;
	this.oldselection = 0;
	this.itemActive = 0;
	this.show = linkhigh;
	this.hide = linklow;
	this.sel = linkactive;
	this.newCss = changeClass;
} 

function linkhigh(id,cssClass) {
	if(document.getElementById) {
		this.newCss(id,cssClass)
	}
	this.itemActive = id;
}

function linklow(id,cssClass) {
	if(document.getElementById) {
		if(this.itemActive!=this.oldselection)
			this.newCss(id,cssClass)
	}
}

function linkactive(id) {
	if(document.getElementById) {
		this.newselection = id;
		if((this.oldselection!=0)&&(this.newselection!=this.oldselection))
			this.hide(this.oldselection,"off");
		this.show(this.newselection,"on");
		this.oldselection=this.newselection;
		}
}

function getXPos(deltaX) {
	xpos = screen.width - screen.availWidth + deltaX;
	return xpos;
}

function getYPos(deltaY) {
	xpos = screen.height - screen.availHeight + deltaY;
	return xpos;
}

function getMaxWidth(deltaX,mult) {
	if (!mult) mult = 1;
	w = Math.round(w = mult*(screen.availWidth)); //- getXPos(deltaX)
	if (w > 800) w = 800;
	return w;
}

function getMaxHeight(deltaY,mult) {
	if (!mult) mult = 1;
	h = Math.round(mult*(screen.availHeight)); // - getYPos(deltaY)
	if (h > 600) h = 600;
	return h;
}

function switchImage(imgName, imgSrc) 
{
  if (document.images)
  {
    if (imgSrc != "none")
    {
      document.images[imgName].src = imgSrc;
    }
  }
}