/*
	Module: rollover.js
	(c)(P)2001 media++, Karlsruhe

	CSS based Image rollover for DOM-compliant browsers
*/
var ELT_BACK   = "imgMenu";
var ELT_OVER   = "imgMenuOver";
var ELT_ACTIVE = "imgMenuActive";
var AREA_PREFIX ="a_";

/* display hint text-snippets while hovering menu entries? */
var bShowHints  = false;
var TEXT_PREFIX ="txt_";
var CAPTION_HERE="Sie befinden<br>sich hier";

var thisSection = "home";
var activeItem  = AREA_PREFIX+thisSection;

var EVNT_OUT    = 0;
var EVNT_OVER   = 1;
var EVNT_CLICK  = 2;

function clipHookClick(eltArea, clipOnOff) { /* overwrite */ }
function clipHookOver(eltArea, clipOnOff) { /* overwrite */ }
function clipHookOut(eltArea) { /* overwrite */ }

function clipImage(eltArea, clipOnOff) {
/* mouse over, click: set clip-rectangle to area of eltArea.choords
  clipOnOff==1: show hovered item
  clipOnOff==2: show active  item (and keep it)
*/
var x,y,w,h=0;
	var clp     = eltArea.getAttribute("coords");
	var clpRect = GetClipRect(eltArea);
	var section = (eltArea.id.substr(AREA_PREFIX.length)||thisSection);

	if (bShowHints) swapHint(eltArea, clipOnOff);

	if (clipOnOff==EVNT_CLICK) { /* clicked */
		clearImage(eltArea);
		var aItem = document.getElementById(ELT_ACTIVE);

		if (activeItem != "" && document.getElementById(activeItem)) {
			document.getElementById(activeItem).removeAttribute("current");
		}
		aItem.setAttribute("current", "true");

		aItem.style.display = "block";
		aItem.style.clip = clpRect; // "rect(top right bottom left)";

		thisSection = section; // make clicked section the active one
		activeItem = eltArea.id;

		clipHookClick(eltArea, EVNT_CLICK);

	}

	if (clipOnOff==EVNT_OVER) { /* hovered */
		if (eltArea.id==activeItem) return true;
		var hItem = document.getElementById(ELT_OVER);
		hItem.style.display = "block";
		hItem.style.clip = clpRect; // "rect(top right bottom left)";

		clipHookOver(eltArea, EVNT_OVER);
	}
}

function clearImage(eltArea) {
/* mouse out: hide hilited item */
	if (bShowHints) swapHint(eltArea, false);
	document.getElementById(ELT_OVER).style.display="none";
	clipHookOut(eltArea);
}

function swapHint(eltArea, bShowHide) {
/* toggles visibility of navitem hints and sets CAPTION_HERE
   when hovering over the active item
*/
	if (!bShowHide) return bShowHide;

	var section = eltArea.id.substr(AREA_PREFIX.length);
	var hItem = document.getElementById(TEXT_PREFIX+section);
	if (hItem) {
		hItem.style.display=(bShowHide) ? "block" : "none";
		if (bShowHide) {
			var oldText = hItem.getAttribute("caption");
			if (eltArea.id==activeItem) {
				if (oldText==null || oldText=="") {
				// backup innerHTML for later
					hItem.setAttribute("caption", hItem.innerHTML);
				}
				// apply CAPTION_HERE
				hItem.innerHTML=CAPTION_HERE;
			} else {
				// restore backuped HTML
				if (oldText!=null)	hItem.innerHTML=oldText;
			}
		}
	}
}

/**
 * Hilfsroutinen zum Umrechnen der AREA choords x1,y1,x2,y2
 * nach clip:rect(top,right,bottom,left) und xywh[]
 */
function GetClipRect(elt) {
// choords:"x1,y1,x2,y2"
//          l  t  r  b
//          0  1  2  3
// rect(top right bottom left)
	var xy = elt.getAttribute("coords").split(",")
	var trbl= xy.slice(1);
	trbl[3] = xy[0];
	return "rect("+ trbl.join("px ") +"px)";
}
function GetChoordsXYWH(elt) {
// choords:"x1,y1,x2,y2"
//          l  t  r  b
//          0  1  2  3
	var xy = elt.getAttribute("coords").split(",");
	xy[2] -= xy[0]; // x2-x1
	xy[3] -= xy[1]; // y2-y1
	return xy;
}

function setNavPositions() {
/* move (absolute) ELT_OVER and ELT_ACTIVE ontop of (relative) ELT_BACK */
var _elt=document.getElementById(ELT_BACK);
	if (!_elt){return true;}
	alignLayers(document.getElementById(ELT_OVER), _elt);
	alignLayers(document.getElementById(ELT_ACTIVE), _elt);
	return true;
}
function alignLayers(srcElt, destElt) {
	var oTop =destElt.offsetTop ;
	var oLeft=destElt.offsetLeft ;
	var elt = destElt.offsetParent ;
	while (elt) {
		oTop +=elt.offsetTop ;
		oLeft+=elt.offsetLeft ;
		elt = elt.offsetParent ;
	}

	if (srcElt){
		srcElt.style.zIndex = 10 + destElt.style.zIndex ;
		srcElt.style.position="absolute";
		srcElt.style.display="block";
		srcElt.style.top=oTop+"px";
		srcElt.style.left=oLeft+"px";
	}
}
function alignElement(eltChild) {
/* move eltImg.parentElement (DIV) ontop of ELT_BACK
   use this in img.onload
*/
var _elt=document.getElementById(ELT_BACK);
	if (!_elt){return true;}
	alignLayers(eltChild.parentElement, _elt);
}

function showActiveItem(section) {
/* hilite active nav-item based on 'section' with fallback to thisSection */
	if (typeof(section)=="undefined") {
		if (typeof(thisSection)=="undefined") return true;
		if (!section) section=thisSection;
	}
	if (typeof(section)=="string") {
		var eltArea = document.getElementById(AREA_PREFIX+section);
		if (eltArea) {
			clipImage(eltArea, EVNT_CLICK);
		} else {
			document.getElementById(ELT_OVER).style.display = "none";
			document.getElementById(ELT_ACTIVE).style.display = "none";
			activeItem = "gibtsnicht";
		}
	} else {
		return true;
	}
	return true;
}

/* enable multiple onload-functions */
function _LoadFunction(fncName){this.name=fncName, this.argv=new Array()};
_LoadFunction.prototype.toString = function() {return this.name};
_LoadFunction.prototype.valueOf  = function() {return this.name};
var onLoadFunctions=new Array();

function registerOnLoad(fncName) {
	// add functionname to the list
	var l = onLoadFunctions.length
	onLoadFunctions[l] = new _LoadFunction(fncName);
}

function initPage() {
	// call onload-functions
	if (document.layers) return false;
	var result;
	for (var l=0; l<onLoadFunctions.length; l++) {
		var argList = onLoadFunctions[l].argv.join(",");
//		try {
			eval("result = " + onLoadFunctions[l].name + "()");
//		} catch(lfErr) { alert(lfErr.description) }
	}
	return true;
}

function linkDeBlur() {
if(document.all)
for(var i in document.links) document.links[i].onfocus=document.links[i].blur;
}

// disable non IE Styles
if (document.all && window.clientInformation && document.styleSheets) {
	if (document.styleSheets["corens6"]) {
		document.styleSheets["corens6"].disabled=true;
	}
}

/* begin extensions */

var hookImg     = new Image(17, 13);
var hookImgOver = new Image(17, 13);
var hookLastImg = null;
var hlPath      = "top/";
hookImg.src     = "nav_wm.gif";
hookImgOver.src = "nav_wm_ov.gif";
function clipHookClick(eltArea, clipOnOff) {
	return;
/* changes add. images on nav-item-click */
	var section  = eltArea.id.substr(AREA_PREFIX.length);
	var topImage = hlPath + "top_" + section + ".gif";
	document.images["nav_"+section].src = (clipOnOff==EVNT_CLICK) ? hookImgOver.src : hookImg.src;
	document.images["top_title"].src = topImage;
	if (hookLastImg) hookLastImg.src = hookImg.src;
	hookLastImg  = document.images["nav_"+section];
}


function fixPositions() {
 setNavPositions();
 showActiveItem();
}
/* end of extension */


registerOnLoad("setNavPositions");
registerOnLoad("showActiveItem");
registerOnLoad("linkDeBlur");

onload=initPage;
onresize=fixPositions;
