$(document).ready(function(){
  
 setFontSize(sessvars.font);
 $.superbox.settings = {
	boxId: "superbox", // Id attribute of the "superbox" element
	boxClasses: "", // Class of the "superbox" element
	overlayOpacity: .8, // Background opaqueness
	boxWidth: "660", // Default width of the box
	boxHeight: "480", // Default height of the box
	loadTxt: "Loading...", // Loading text
	closeTxt: "Schließen" // "Close" button text
	//prevTxt: "Previous",  "Previous" button text
	//nextTxt: "Next" // "Next" button text
};
 $.superbox();


	// Tooltip
	$("a.bubble").jToolTip({
		align: {x: "left", y: "over"},
		offset: {x: -20, y: -10},
		maxHeight: 400
	});

	// Sitemap
	var lx="";
	$('ul.sf-menu').children(":even").each(function() {
		lx+="<ul>"+$(this).html()+"</ul>";
	});
	$("#sitemap-left").html(lx);
	
	var rx="";
	$('ul.sf-menu').children(":odd").each(function() {
		rx+="<ul>"+$(this).html()+"</ul>";
	});
	$("#sitemap-right").html(rx);
		
	// Pathway
	var menu=document.getElementById("menu");
	iterateNodes(menu,1);
	// Page is not on the Menu-Navigation
	if(!done) {
		var pw="<a href='/default.shtml'>Home</a>";
		for(var i=0;i<noMenu.length;i++) {
			if(document.location.href.indexOf(noMenu[i].url) != -1) {
				pw+="<a href='"+noMenu[i].url+"'>"+noMenu[i].title+"</a>";
							
			

			}
		}
		$("#bc-links").html(pw);
	}
		
	// Dropdown menu
	$('ul.sf-menu').superfish({
		delay:       500
		,
		autoArrows: false
	});

	
});


function nwr(x,w,h,t,l,n){
	if (h == "") h = 100;
       if (w == "") w = 100;
       if (t == "") t = 10;
       if (l == "") l = 10;
       if (n == "") n = "login";
       	var xx = "top="+t+",left="+l+",width="+w+ ",height="+h+", directories=0, status=1, scrollbars=1, resizable=1, toolbar=0,menubar=0";
		msgWindow=window.open(x,n,xx);
		msgWindow.focus();
}
function printWin()
{
	window.print();	
}

function setFontSize(t) {
  if (t==undefined) t = "reg";
	sessvars.font=t;
  var i, a;	
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == t) a.disabled = false;
    }
  }
}

var pathway=Array();
var pathwaySeparator="";
var done=false;
var TmpChannel="";
function iterateNodes(n,l) {
	if(done || n.nodeName == "#text" || n.nodeName == "A") return;
	if(n.nodeName == "LI") {
		var icn=0;
		while(n.childNodes[icn].nodeName != "A") icn++;
		var url=n.childNodes[icn].getAttributeNode("href").nodeValue;

		if(document.location.href.indexOf(url) != -1) {
			doPathWay(n);
			pathway.reverse();
			var pw="";
      
			for(var i=0;i<pathway.length;i++) {
		         if (document.location.href.split("/").length-1 == 3) { // startpage only one pw
		           break;
		        }
	

		       TmpChannel=pathway[0].titel;
		       
				pw+="<a href='"+pathway[i].url+"'>"+pathway[i].titel+"</a>";
				// Trenner
				
				if( i < (pathway.length-1) ) pw+=pathwaySeparator;
			}
			// Writes Pathway
			$("#bc-links").html("<a href='/default.shtml'>Home</a>"+pw);

			// highlighting of the first menu item
			$("ul.sf-menu").children().each(function(index) {
				if($("a:first", this).text() == pathway[0].titel) $(this).addClass("current");
			});
			done=true;
		}
	}
	if(n.hasChildNodes()) {
		for(var i=0;i<n.childNodes.length;i++) {
			l++; iterateNodes(n.childNodes[i],l); l--;
		}
	}
}

function doPathWay(n) {
	if(n.nodeName=="LI") {
		var icn=0;
		while(n.childNodes[icn].nodeName != "A") icn++;
		url=n.childNodes[icn].getAttributeNode("href").nodeValue;
		titel=n.childNodes[icn].childNodes[0].nodeValue;
		pathway.push({"url":url,"titel":titel});

		var parent=n.parentNode;
		switch(parent.nodeName) {
			// Menu ist entweder in ein <TD> oder in ein <DIV>
			case "TD":
			case "DIV":
				return;
				break;
			case "LI":
//				var A = document.createAttribute("class");
//				A.nodeValue = "current";
//				parent.setAttributeNode(A);
//				parent.setAttribute("class","current");
				$(parent).addClass("current");
				doPathWay(parent);
				break;
			case "UL":
				doPathWay(parent.parentNode);
				break;
			default:
				return;
		}
	}
}


function getGlossar() {
  document.writeln("<a name='glossar-top'></a><table id='glossar_letters'><tr>")
  for(var i=0; i<glossar.length; i++) {
    document.writeln("<td id='letter_"+glossar[i].letter+"' onClick='showTerms(\""+glossar[i].letter+"\")'>"+glossar[i].letter+"</td>");
  }
  document.writeln("<td id='letter_all' onClick='showAllTerms()'>Alle</td>");
  document.writeln("</tr></table>");
  
  for(i=0; i<glossar.length; i++) {
    document.writeln("<div class='glossar_terms' id='terms_"+glossar[i].letter+"'>");
    for(l=0; l<glossar[i].terms.length; l++) {
      document.writeln("<b>"+glossar[i].terms[l].term+"</b><br/>");
      document.writeln("<p>"+glossar[i].terms[l].description+"</p>");
    }
    document.writeln("<div class='glossar-2top'><a href='#glossar-top'>&nbsp;&uarr;&nbsp;nach oben</a></div>");
    document.writeln("</div>");
  }
  if(glossar.length > 0) {
    $("#terms_"+glossar[0].letter).show();
    $("#letter_"+glossar[0].letter).addClass("selected-letter");
  }
}

function showTerms(l) {
  $("[id^=terms_]").removeClass("glossar-border-bottom");
  $("[id^=terms_], .glossar-2top").hide();
  $("#terms_"+l).show();
  $("[id^=letter_]").removeClass("selected-letter");
  $("#letter_"+l).addClass("selected-letter");
}
function showAllTerms(l) {
  $("[id^=terms_], .glossar-2top").show();
  $("[id^=terms_]").addClass("glossar-border-bottom");
  $("[id^=letter_]").removeClass("selected-letter");
  $("#letter_all").addClass("selected-letter");
}

function socialRss() {
  var url="#";
//	document.writeln("<a href='"+url+"' class='rss' target='_blank'>&nbsp;</a>");
}
function socialGoogle() {
  var url="http://www.google.com/bookmarks/mark?";
  url+="op=add&amp;";
  url+="bkmk="+encodeURI(document.location.href)+"&amp;";
  url+="title="+encodeURI(document.title);
	document.writeln("<a href='"+url+"' class='google' target='_blank' title='Google Bookmarks'>&nbsp;</a>");
}
function socialTwitter() {
  var url="http://twitter.com/home?";
  url+="status="+encodeURI(document.location.href);
  document.writeln("<a href='"+url+"' class='twitter' target='_blank' title='Twitter'>&nbsp;</a>")
}
function socialTechnorati() {
  var url="http://technorati.com/favorites/?";
  url+="add="+encodeURI(document.location.href)+"&amp;";  
  url+="tag=";
	document.writeln("<a href='"+url+"' class='technorati' target='_blank' title='Technorati'>&nbsp;</a>");
}
function socialFacebook() {
  var url="http://de.facebook.com/sharer.php?";
  url+="u="+encodeURI(document.location.href);
  url+="&amp;";
  url+="t="+encodeURI(document.title);
  document.writeln("<a href='"+url+"' class='facebook' target='_blank' title='Facebook'>&nbsp;</a>")
}
;
