/* Element Scroll _________________________________________________________________ */

	var LockedID = null;
	
	function Lock(id) {
		LockedID = id;
	}
	
	function UnLock() {
		LockedID = null;
	}
	
	function ScrolltoElement(id, noLock, duration) {
	
		if (noLock == null) {
			noLock = false;
		}
		
		if (duration == null) {
			duration = 1;
		}
		
		if ((LockedID == null) || (noLock)) {
		
		    var left = 0;
		    var top = 0;
			
			var parent = document.getElementById(id).parentNode;
			var target = document.getElementById(id);
	        left -= parent.offsetLeft + target.offsetLeft;
	        top -= parent.offsetTop + target.offsetTop;
			
	        new Effect.Move(parent, {x: left, y: top, mode: 'relative', duration: duration});
			
			if (!noLock) {
				Lock(id);
				setTimeout('UnLock()', duration * 1000);
			}
		}
    }
	
	
/* Element Scroll Gallery ____________________________________________________ */

	/* geht nur für 1 gallery pro seite */
	
	var SetScrollGallerie_idPrefix = '';
	var SetScrollGallerie_nCount = 0;
	var SetScrollGallerie_nDisplay = 0;
	
	function SetScrollGallerie(idPrefix, nCount, duration) {
		SetScrollGallerie_idPrefix = idPrefix;
		SetScrollGallerie_nCount = nCount;
		if (duration == null) {
			duration = 1;
		}
		SetScrollGallerie_duration = duration;
		SetScrollGallerie_nDisplay = 1
	}
	
	function ScrollGallerieNext(idPrefix) {
		
		if ((SetScrollGallerie_idPrefix == idPrefix) && (SetScrollGallerie_nCount > 1) && (SetScrollGallerie_nDisplay != 0) && (LockedID == null)) {
			
			SetScrollGallerie_nDisplay ++;
			if (SetScrollGallerie_nDisplay > SetScrollGallerie_nCount) {
				SetScrollGallerie_nDisplay = 1;
			}
			ScrolltoElement(SetScrollGallerie_idPrefix + SetScrollGallerie_nDisplay, true);
			Lock(SetScrollGallerie_idPrefix + SetScrollGallerie_nDisplay);
			setTimeout('UnLock()', SetScrollGallerie_duration * 1000);
		}
	}
	
	function ScrollGalleriePrevious(idPrefix) {
		
		if ((SetScrollGallerie_idPrefix == idPrefix) && (SetScrollGallerie_nCount > 1) && (SetScrollGallerie_nDisplay != 0) && (LockedID == null)) {
			
			SetScrollGallerie_nDisplay --;
			if (SetScrollGallerie_nDisplay < 1) {
				SetScrollGallerie_nDisplay = SetScrollGallerie_nCount;
			}
			ScrolltoElement(SetScrollGallerie_idPrefix + SetScrollGallerie_nDisplay, true);
			Lock(SetScrollGallerie_idPrefix + SetScrollGallerie_nDisplay);
			setTimeout('UnLock()', SetScrollGallerie_duration * 1000);
		}
	}
	

/* Element Fading __________________________________________________________________ */

	Effect.FadeElementsInLoop = function(element, idPrefix, nCount, i, duration) {

		for (a = 1; a <= nCount; a++) {
			document.getElementById(idPrefix + a).style.display = 'none';
			document.getElementById(idPrefix + a).style.zIndex = '1';
		}

		if (i <= 1) {
			Element.setOpacity(idPrefix + i, 1)
			Element.setOpacity(idPrefix + nCount, 1)
			document.getElementById(idPrefix + i).style.display = 'block';
			document.getElementById(idPrefix + nCount).style.display = 'block';
			document.getElementById(idPrefix + i).style.zIndex = '3';
			document.getElementById(idPrefix + nCount).style.zIndex = '2';
		} else {
			Element.setOpacity(idPrefix + i, 1)
			Element.setOpacity(idPrefix + (i-1), 1)
			document.getElementById(idPrefix + i).style.display = 'block';
			document.getElementById(idPrefix + (i-1)).style.display = 'block';
			document.getElementById(idPrefix + i).style.zIndex = '3';
			document.getElementById(idPrefix + (i-1)).style.zIndex = '2';
		}


		var oldOpacity = Element.getInlineOpacity(element);
		var options = Object.extend({
		from: Element.getOpacity(element) || 1.0,
		to:   0.0,
		afterFinishInternal: function(effect) { with(Element) {

			document.getElementById(idPrefix + i).style.display = 'none';
			document.getElementById(idPrefix + i).style.zIndex = '1';

			if (i <= 1) {
				i = nCount;
			} else {
				i--;
			}

			setTimeout("new Effect.FadeElementsInLoop('" + idPrefix + "" + i + "', '" + idPrefix + "', " + nCount + ", " + i + ", " + duration + ")", duration);

		}}
		}, arguments[1] || {});
		return new Effect.Opacity(element,options);
	}
	

	function FadeElements(idPrefix, nCount, duration) {
		
		if (duration == null) {
			duration = 4000;
		}
		if (nCount > 1) {
			setTimeout("new Effect.FadeElementsInLoop('" + idPrefix + "" + nCount + "', '" + idPrefix + "', " + nCount + ", " + nCount + ", " + duration + ")", duration);
		}
	}	
	
