// *** COMMON CROSS-BROWSER COMPATIBILITY CODE ***

// This is taken from the "Modular Layer API" available on my site.
// See that for the readme if you are extending this part of the script.

/*
 * HLupe
 */

function HLupe(myName)
{
	this.classReplace = true;
	this.className = 'lupe';
	this.showDelay = 0;
	this.hideDelay = 100;

	// Animation speeds: set to a number between 0 and 1. Larger = faster. 1 = disabled.
	this.animInSpeed = 0.2;
	this.animOutSpeed = 0.2;
	this.animations = [];

	this.myName = myName;
	this.timer = [];
	this.lupeArr = [];
	this.show = function(triggerId)
	{
		with(this)
		{
			if(lupeArr[triggerId])
			{
				if(timer[triggerId]) clearTimeout(timer[triggerId]);
				timer[triggerId] = setTimeout(myName + '.setVisible("' + triggerId + '", true)', this.showDelay);
				return;
			}
			//
			//  Lupe erzeugen
			//
			if(!(triggerRef = getRef(triggerId))) return;
			if(!(origRef = triggerRef.parentNode)) return;
			if(!(parentRef = origRef.parentNode)) return;
			copyRef = origRef.cloneNode(true);
			copyRef.setAttribute('id', myName+'_s_'+triggerId);
			parentRef.appendChild(copyRef);
			//
			// Ereignisbehandlung
			//
			var hShow = new Function(myName+'.show("'+triggerId+'");');
			var evtProp = navigator.userAgent.indexOf('Safari') > -1 || isOp ? 'safRtnVal' : 'returnValue';
			var hHide = new Function('event', 'if (event.'+evtProp+' != false) '+myName+'.hide("'+triggerId+'");');
			addEvent(copyRef, 'mouseover', hShow);
			addEvent(copyRef, 'mouseout', hHide);
			//
			// Positionierung und Eigenschaften
			//
			lupeArr[triggerId] = copyLyr = getLyr(myName+'_s_'+triggerId);
			copyLyr.sty.position = 'absolute';
			copyLyr.sty.display = 'none';
			copyRef.className = (classReplace || copyRef.className.length == 0) ? className : copyRef.className + ' ' + className;
			copyLyr.x(origRef.offsetLeft);
			copyLyr.y(origRef.offsetTop);
			//
			// anzeigen
			//
			show(triggerId);
		}
	}

	this.hide = function(triggerId)
	{
		with(this)
		{
			if(timer[triggerId]) clearTimeout(timer[triggerId]);
			timer[triggerId] = setTimeout(myName + '.setVisible("' + triggerId + '", false)', this.hideDelay);
		}
	}

	this.setVisible = function(triggerId, sh)
	{
		copyLyr = this.lupeArr[triggerId];
		with(this)
		{
			copyLyr.timer = copyLyr.timer || 0;
			copyLyr.counter = copyLyr.counter || 0;
			with(copyLyr)
			{
				clearTimeout(timer);
				if (sh && !counter) sty.display = 'block';
				var speed = sh ? animInSpeed : animOutSpeed;
				if (isDOM && speed < 1)
				{
					for (var a = 0; a < animations.length; a++) animations[a](ref, counter, sh);
				}
				counter += speed*(sh?1:-1);
				if (counter>1) { counter = 1;}
				else if (counter<0) { counter = 0; sty.display = 'none';}
				else if (isDOM)
				{
					timer = setTimeout(myName + '.setVisible("' + triggerId + '", ' + sh + ')', 50);
				}
			}
		}
	}
}

HLupe.animFade = function(ref, counter, show)
{
	// Use IE's ActiveX alpha filter or the W3C/Mozilla 'opacity' to fade menu.
	var done = (counter == 1);
	if (ref.filters)
	{
		var alpha = !done ? ' alpha(opacity=' + parseInt(counter * 100) + ')' : '';
		if (ref.style.filter.indexOf("alpha") == -1) ref.style.filter += alpha;
		else ref.style.filter = ref.style.filter.replace(/\s*alpha\([^\)]*\)/i, alpha);
	}
	else ref.style.opacity = ref.style.MozOpacity = counter / 1.001;
};

HLupe.animSwipeDown = function(ref, counter, show)
{
	// Backup original top/margin-top, then 'swipe' movement + clipping.
	if (show && (counter == 0))
	{
		ref._fsm_styT = ref.style.top;
		ref._fsm_styMT = ref.style.marginTop;
		ref._fsm_offT = ref.offsetTop || 0;
	}
	var cP = Math.pow(Math.sin(Math.PI * counter / 2), 0.75);
	var clipY = ref.offsetHeight * (1 - cP);
	ref.style.clip = (counter == 1 ?
	((window.opera || navigator.userAgent.indexOf('KHTML') > -1) ? '' :
	'rect(auto, auto, auto, auto)') :
	'rect(' + clipY + 'px, ' + ref.offsetWidth + 'px, ' + ref.offsetHeight + 'px, 0)');
	if (counter == 1 || (counter < 0.01 && !show))
	{
		ref.style.top = ref._fsm_styT;
		ref.style.marginTop = ref._fsm_styMT;
	}
	else
	{
		ref.style.top = ((0 - clipY) + (ref._fsm_offT)) + 'px';
		ref.style.marginTop = '0';
	}
};

// verschachtelte Ids vermeiden !!! keine Id in triggerIdArr darf Kindknoten eines anderen Knotens aus triggerIdArr sein
HLupe.prototype.activate = function(triggerIdArr)
{
	if (!isDOM || !document.documentElement) return;
	with(this)
	{
		for(var i=0; i<triggerIdArr.length; i++)
		{
			var triggerId = triggerIdArr[i];
			var hShow = new Function(myName+'.show("'+triggerId+'");');
			var evtProp = navigator.userAgent.indexOf('Safari') > -1 || isOp ? 'safRtnVal' : 'returnValue';
			var hHide = new Function('event', 'if (event.'+evtProp+' != false) '+myName+'.hide("'+triggerId+'");');
			addEvent(getRef(triggerId), 'mouseover', hShow);
			addEvent(getRef(triggerId), 'mouseout', hHide);
		}
	}
}

HLupe.prototype.activateByTagName = function (rootId, tagName)
{
	if (!isDOM || !document.documentElement) return;
	var elArr = getRef(rootId).getElementsByTagName(tagName);
	var idArr = new Array();
	for(var i = 0; i < elArr.length; i++)
	{
		imgId = this.myName + '_' + tagName + '_' + i;
		if(elArr[i].id) imgId = elArr[i].id;
		elArr[i].setAttribute('id', imgId);
		idArr[idArr.length] = imgId;
	}
	this.activate(idArr);
}
