/* Auf und Zuklappen ____________________________________________________________ */
	
    function Slide(id) {
        new Effect.toggle(document.getElementById(id),'slide');
    }
	
    function SlideUp(id) {
        new Effect.SlideUp(document.getElementById(id));
    }
	
    function SlideDown(id) {
        new Effect.SlideDown(document.getElementById(id));
    }

    function Hide(id) {
		Element.hide($(id));
    }
	

function Extended (Objectname) {

/* Sperren der Elemente ____________________________________________________________ */

	var extended = this;
	
	this.id = '';
	this.elementID = '';
	this.lAnzahl = 0;
	this.zuruck = '';
	this.weiter = '';
	this.bStart = true;
	this.lVisibleElements = 1;
	

	/* Lock zum sperren des Input (Private) */
	
	this.LockedID = null;
	this.Objectname = Objectname;
	
	this.OpacityMin = 0.01;
	this.OpacityMax = 1.0;
	
	this.Scroll = 'none';
	this.Scrollx = 10;
	this.Scrolly = 10;
	
	
	this.Lock = function(id) {
		this.LockedID = id;
	}
	
	this.UnLock = function() {
		this.LockedID = null;
	}
	
	this.SetID = function(id) {
		this.id = id;
	}
	
	this.GetID = function() {
		return this.id;
	}
	
	this.GetCount = function() {
		return this.SetScrollGallerie_nCount;
	}
	
	this.SetElementID = function(elementID) {
		this.elementID = elementID;
	}
	
	this.SetAnzahl = function(lAnzahl) {
		this.lAnzahl = lAnzahl;
	}
	
	this.SetZuruckID = function(zuruck) {
		this.zuruck = zuruck;
	}
	
	this.SetWeiterID = function(weiter) {
		this.weiter = weiter;
	}
	
	this.SetVisibleElements = function(lVisibleElements) {
		this.lVisibleElements = lVisibleElements;
	}
	
/* Ajax Request ___________________________________________________________________ */

    this.ajax = false;
    
    this.AjaxInit = function() {
    
        this.ajax = false;
        
        if (window.XMLHttpRequest) {
            this.ajax = new XMLHttpRequest();
        } else {
            if (window.ActiveXObject) {
                try {
                    this.ajax = new ActiveXObject('Msxml2.XMLHTTP');
                } catch (e) {
                    try {
                        this.ajax = new ActiveXObject('Microsoft.XMLHTTP');
                    } catch (e) {}
                }
            }
        }
        
        if (!this.ajax) {
            alert('No Ajax Browser');
            return null;
        }
    }
	
	
// Send With Callback
	
    this.AjaxRequest = function(url) {
		url = url.replace(/&amp;/g, '&');
        this.AjaxInit();
		
        this.ajax.onreadystatechange = function () { 
			WriteData();
		};
		
		this.ajax.open('GET', url, true);
        this.ajax.send(null);
    }
	
	
// Callback Function
	
	function WriteData(){
		extended.WriteData();
	}
	
    this.WriteData = function() {
        if ((this.ajax.readyState == 4) && (this.ajax.status == 200)) {
            if(this.ajax.responseText != '') {
				this.SetScrollGallerie_nCount++;
				var newdiv = document.createElement('div');
				newdiv.setAttribute('id', this.elementID + '' + this.SetScrollGallerie_nCount);
				newdiv.className = 'innendrin';
				newdiv.innerHTML = this.ajax.responseText;
                document.getElementById(this.id).appendChild(newdiv);
				var margin = 0;
				if(!isNaN(parseInt(Element.Methods.getStyle(this.elementID + "1", 'marginRight')))){
					margin = parseInt(Element.Methods.getStyle(this.elementID + "1", 'marginRight'));
				}
				var width = parseInt(Element.Methods.getWidth(this.elementID + (this.SetScrollGallerie_nCount-1))) + margin;
				document.getElementById(this.id).style.width = (Element.Methods.getWidth(this.id) + width) + 'px';
				myLightbox.updateImageList();
				if(bLoad) {
					bLoad = false;
					myLightbox.updateLightbox();
					myLightbox.changeImage(activeImage + 1);
				}
				this.ScrollGallerieNext();
            }
        }
    }
	
	
// Send With Callback
	
    this.FirstLoadAjaxRequest = function(url) {
		url = url.replace(/&amp;/g, '&');
        this.AjaxInit();
		
        this.ajax.onreadystatechange = function () { 
			FirstLoadWriteData(); 
		};
		
		this.ajax.open('GET', url, true);
        this.ajax.send(null);
    }
	
	
// Callback Function
	
	function FirstLoadWriteData() {
		extended.FirstLoadWriteData();
	}
	
    this.FirstLoadWriteData = function() {
        if ((this.ajax.readyState == 4) && (this.ajax.status == 200)) {
            if(this.ajax.responseText != '') {
				this.SetScrollGallerie_nCount++;
				var newdiv = document.createElement('div');
				newdiv.setAttribute('id', this.elementID + '' + this.SetScrollGallerie_nCount);
				newdiv.className = 'innendrin';
				newdiv.innerHTML = this.ajax.responseText;
                document.getElementById(this.id).appendChild(newdiv);
				myLightbox.updateImageList();
            }
        }
    }



/* Element Scroll _________________________________________________________________ */
	
	
	/* Scroll zum element mit der ID, opt: dauer (sec), lock (bool) */ 
	
	this.ScrolltoElement = function(id, duration, noLock) {
	
		if (noLock == null) {
			noLock = false;
		}
		
		if (duration == null) {
			duration = 1;
		}
		
		if ((this.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) {
				this.Lock(id);
				window.setTimeout(this.Objectname + '.UnLock()', duration * 1000);
			}
		}
    }
	
	
/* Element Scroll Gallery ____________________________________________________ */

	
	/* ScrollGallerie IDPrefix, Counter, opt: dauer (sec) */ 
	
	this.SetScrollGallerie_idPrefix = '';
	this.SetScrollGallerie_nCount = 0;
	this.SetScrollGallerie_nDisplay = 0;
	
	this.SetScrollGallerie = function(idPrefix, nCount, duration) {
	
		if (duration == null) {
			duration = 1;
		}
		
		this.SetScrollGallerie_idPrefix = idPrefix;
		this.SetScrollGallerie_nCount = nCount;
		this.SetScrollGallerie_duration = duration;
		this.SetScrollGallerie_nDisplay = 1
		
	}
	
	
	this.ScrollGalleriePrevious = function() {
		
		if ((this.SetScrollGallerie_nCount > 1) && (this.SetScrollGallerie_nDisplay != 0) && (this.LockedID == null)) {
			
			this.SetScrollGallerie_nDisplay --;
			if (this.SetScrollGallerie_nDisplay <= 1) {
				document.getElementById(this.zuruck).style.display = 'none';
				this.SetScrollGallerie_nDisplay = 1;
			}
			
			document.getElementById(this.weiter).style.display = 'inline';
			
			this.ScrolltoElement(this.SetScrollGallerie_idPrefix + this.SetScrollGallerie_nDisplay, this.SetScrollGallerie_duration, true);
			this.Lock(this.SetScrollGallerie_idPrefix + this.SetScrollGallerie_nDisplay);
			window.setTimeout(this.Objectname + '.UnLock()', this.SetScrollGallerie_duration * 1000);
		}
	}
	
	
	this.ScrollGallerieNextAjax = function(url) {
	
		if ((this.SetScrollGallerie_nDisplay < this.SetScrollGallerie_nCount) && (this.SetScrollGallerie_nCount < this.lAnzahl)) {
			this.AjaxRequest(url);
		} else {
			if(bLoad) {
				bLoad = false;
				myLightbox.changeImage(activeImage + 1);
			}
			if(this.lAnzahl > this.lVisibleElements){
				this.ScrollGallerieNext();
			}
		}
	}
	
	
	this.ScrollGallerieCheck = function() {
	
		if (this.lAnzahl <= this.lVisibleElements) {
			document.getElementById(this.weiter).style.display = 'none';
		}
	}
	
	
	this.LoadScrollGallerieAjax = function(url) {
		
		if (this.bStart) {
			if (this.lAnzahl <= this.lVisibleElements) {
				document.getElementById(this.weiter).style.display = 'none';
			}
			this.FirstLoadAjaxRequest(url);
			this.bStart = false;
		}
	}
	
	
	this.ScrollGallerieNext = function() {
	
		if ((this.SetScrollGallerie_nCount > 1) && (this.SetScrollGallerie_nDisplay != 0) && (this.LockedID == null)) {
			
			this.SetScrollGallerie_nDisplay ++;
			if (this.SetScrollGallerie_nDisplay >= ((this.SetScrollGallerie_nCount - this.lVisibleElements) + 1)) {
				document.getElementById(this.weiter).style.display = 'none';
				this.SetScrollGallerie_nDisplay = ((this.SetScrollGallerie_nCount - this.lVisibleElements) + 1);
			}
			
			document.getElementById(this.zuruck).style.display = 'inline';
			
			this.ScrolltoElement(this.SetScrollGallerie_idPrefix + this.SetScrollGallerie_nDisplay, this.SetScrollGallerie_duration, true);
			this.Lock(this.SetScrollGallerie_idPrefix + this.SetScrollGallerie_nDisplay);
			window.setTimeout(this.Objectname + '.UnLock()', this.SetScrollGallerie_duration * 1000);
		}
	}
	
	
	this.FadeIn = function(id, duration) {
		
		if (duration == null) {
			duration = 1.5;
		}
		
		Effect.Appear(id, {duration: duration, from: this.OpacityMin, to: this.OpacityMax});
	}
	
	
	this.FadeOut = function(id, duration) {
		
		if (duration == null) {
			duration = 1.5;
		}
		
		Effect.Fade(id, {duration: duration, form: this.OpacityMax, to: this.OpacityMin});
	}
	
	this.StartScrollUp = function(id, duration) {
	
		if (duration == null) {
			duration = 0.1;
		}
		
		this.Scroll = 'up';
		this.ScrollUp(id, duration)
		
	}
	
	this.StartScrollDown = function(id, duration) {
	
		if (duration == null) {
			duration = 0.1;
		}
		
		this.Scroll = 'down';
		this.ScrollDown(id, duration)

	}
	
	this.ScrollUp = function(id, duration) {
	
		if (duration == null) {
			duration = 0.1;
		}
		if (parseInt($(id).getStyle('top')) < 0) {
			new Effect.Move(id, {x: 0, y: this.Scrollx, mode: 'relative', duration: duration});
		}
		
		if (this.Scroll == 'up') {
			window.setTimeout(this.Objectname + '.ScrollUp("' + id + '",' + duration + ')', duration * 1000);
		}
		
	}
	
	this.ScrollDown = function(id, duration) {
	
		if (duration == null) {
			duration = 0.1;
		}
		
		var nPos
		
		nPos = 0;
		
		if (Element.Methods.getHeight(id) != null) {
			nPos += parseInt(Element.Methods.getHeight(id));
		}
		
		if ($(id).getStyle('top') != null) {
			nPos += parseInt($(id).getStyle('top'));
		}
		
		if ($(id).parentNode.clientHeight != null) {
			nPos -= parseInt($(id).parentNode.clientHeight);
		}
		
		if (nPos > 0) {		
			new Effect.Move(id, {x: 0, y: -this.Scrollx, mode: 'relative', duration: duration});
		}
		
		if (this.Scroll == 'down') {
			window.setTimeout(this.Objectname + '.ScrollDown("' + id + '",' + duration + ')', duration * 1000);
		}

	}
	
	this.ScrollStop = function() {
	
		this.Scroll = 'none';
	
	}
	
}

/* Element Fading __________________________________________________________________ */

	/* Fading Funktion idPrefix, count, opt: dauer (sec) */

	function FadeElements(idPrefix, nCount, duration) {
		
		if (duration == null) {
			duration = 4000;
		}
		if (nCount > 1) {
			window.setTimeout("new Effect.FadeElementsInLoop('" + idPrefix + "" + nCount + "', '" + idPrefix + "', " + nCount + ", " + nCount + ", " + duration + ")", duration);
		}
	}
	
	
	/* Private */
	
	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--;
			}
			
			window.setTimeout("new Effect.FadeElementsInLoop('" + idPrefix + "" + i + "', '" + idPrefix + "', " + nCount + ", " + i + ", " + duration + ")", duration);
		
		}}
		}, arguments[1] || {});
		return new Effect.Opacity(element,options);
	}
	