﻿EqsSoftpopupOptions = Object.extend({

    overlayOpacity: 0.4,									// Durchsichtbarkeit des Overlays
	overlayOpacitySpeed: 0.25,								// Geschwindigkeit in der der Overlay faded

	resizeSpeed: 0.5,

	marginTop: 20											// Abstand nach oben (in px)

}, window.EqsSoftpopupOptions || {});


var EqsSoftpopup = Class.create();

EqsSoftpopup.prototype = {

	divElements: [],
	
	contentElement: undefined,
	infoTitle: '',
	closerText: '',
	htmlFontSize: '12',

	htmlWidth: '950',

	initialize: function() {
		// Erstellt ein onclick der die methode start() aufruft bei jedem Link mit dem rel="lightbox"
		this.createOnclick();

		// Erstellte divs werden am Ende vom Body erzeugt, ca. der folgende Code:
		// <div id="softpopupOverlay"></div>
		// <div id="softpopupWindow">
		//       <div id="softpopupTitle">
		//             <div id="softpopupHeadline"><span id="softpopupHeadlineText"></span></div>
		//             <a href="#" id="softpopupCloser"><span id="softpopupCloserText"></span></a>
		//             <div class="clear"></div>
		//       </div>
		//       <div id="softpopupBody">
		//             <div id="softpopupContent">
		//             </div>
		//       </div>
		// </div>
		// <table id="softpopupPreContent">
		//      <tr id="softpopupPreContentTr">
		//            <td id="softpopupPreContentTd">
		//            </td>
		//      </tr>
		// </table>

		// Erstellt das <div id="softpopupOverlay"> und speichert das element in body
		this.divElements['softpopupOverlay'] = new Element('div', { 'id' : 'softpopupOverlay' });
		$$('body')[0].appendChild(this.divElements['softpopupOverlay']);

		// Erstellt das <div id="softpopupWindow"> und speichert das element in body
		this.divElements['softpopupWindow'] = new Element('div', { 'id' : 'softpopupWindow' });
		$$('body')[0].appendChild(this.divElements['softpopupWindow']);
		
		// Erstellt das <div id="softpopupBorder"> und speichert das element in body
		this.divElements['softpopupBorder'] = new Element('div', { 'id' : 'softpopupBorder' });
		this.divElements['softpopupWindow'].appendChild(this.divElements['softpopupBorder']);

		// Erstellt die <table id="softpopupPreContent"> und speichert das element in body
		this.divElements['softpopupPreContent'] = new Element('table', { 'id' : 'softpopupPreContent' });
		$$('body')[0].appendChild(this.divElements['softpopupPreContent']);

		// Erstellt die <table id="softpopupPreContentTbody"> und speichert das element in this.divElements['softpopupPreContentTbody']
		this.divElements['softpopupPreContentTbody'] = new Element('tbody', { 'id' : 'softpopupPreContentTbody' });
		this.divElements['softpopupPreContent'].appendChild(this.divElements['softpopupPreContentTbody']);

		// Erstellt die <table id="softpopupPreContentTr"> und speichert das element in this.divElements['softpopupPreContentTr']
		this.divElements['softpopupPreContentTr'] = new Element('tr', { 'id' : 'softpopupPreContentTr' });
		this.divElements['softpopupPreContentTbody'].appendChild(this.divElements['softpopupPreContentTr']);

		// Erstellt die <table id="softpopupPreContentTd"> und speichert das element in this.divElements['softpopupPreContentTd']
		this.divElements['softpopupPreContentTd'] = new Element('td', { 'id' : 'softpopupPreContentTd' });
		this.divElements['softpopupPreContentTr'].appendChild(this.divElements['softpopupPreContentTd']);
		
		// Erstellt das <div id="softpopupBorderTop"> und speichert das element in this.divElements['softpopupBorderTop']
		this.divElements['softpopupBorderTop'] = new Element('div', { 'id' : 'softpopupBorderTop' });
		this.divElements['softpopupBorder'].appendChild(this.divElements['softpopupBorderTop']);

		// Erstellt das <div class="softpopupBorderLeft"> und speichert das element in this.divElements['softpopupBorderTop_left']
		this.divElements['softpopupBorderTop_left'] = new Element('div', { 'class' : 'softpopupBorderLeft' });
		this.divElements['softpopupBorderTop'].appendChild(this.divElements['softpopupBorderTop_left']);

		// Erstellt das <div class="softpopupBorderCenter"> und speichert das element in this.divElements['softpopupBorderTop_center']
		this.divElements['softpopupBorderTop_center'] = new Element('div', { 'class' : 'softpopupBorderCenter' });
		this.divElements['softpopupBorderTop'].appendChild(this.divElements['softpopupBorderTop_center']);

		// Erstellt das <div class="softpopupBorderRight"> und speichert das element in this.divElements['softpopupBorderTop_right']
		this.divElements['softpopupBorderTop_right'] = new Element('div', { 'class' : 'softpopupBorderRight' });
		this.divElements['softpopupBorderTop'].appendChild(this.divElements['softpopupBorderTop_right']);

		// Erstellt das <div id="softpopupBorderLeft"> und speichert das element in this.divElements['softpopupBorderLeft']
		this.divElements['softpopupBorderLeft'] = new Element('div', { 'id' : 'softpopupBorderLeft' });
		this.divElements['softpopupBorder'].appendChild(this.divElements['softpopupBorderLeft']);

		// Erstellt das <div class="softpopupBorderCenter"> und speichert das element in this.divElements['softpopupBorderLeft_center']
		this.divElements['softpopupBorderLeft_center'] = new Element('div', { 'class' : 'softpopupBorderCenter' });
		this.divElements['softpopupBorderLeft'].appendChild(this.divElements['softpopupBorderLeft_center']);
		
		// Erstellt das <div id="softpopupContentOutline"> und speichert das element in this.divElements['softpopupContentOutline']
		this.divElements['softpopupContentOutline'] = new Element('div', { 'id' : 'softpopupContentOutline' });
		this.divElements['softpopupBorder'].appendChild(this.divElements['softpopupContentOutline']);

		// Erstellt das <div id="softpopupTitle"> und speichert das element in this.divElements['softpopupTitle']
		this.divElements['softpopupTitle'] = new Element('div', { 'id' : 'softpopupTitle' });
		this.divElements['softpopupContentOutline'].appendChild(this.divElements['softpopupTitle']);

		// Erstellt das <div id="softpopupHeadline"> und speichert das element in this.divElements['softpopupHeadline']
		this.divElements['softpopupHeadline'] = new Element('div', { 'id' : 'softpopupHeadline' });
		this.divElements['softpopupTitle'].appendChild(this.divElements['softpopupHeadline']);

		// Erstellt den <span id="softpopupHeadline"> und speichert das element in this.divElements['softpopupHeadlineText']
		this.divElements['softpopupHeadlineText'] = new Element('span', { 'id' : 'softpopupHeadlineText' });
		this.divElements['softpopupHeadline'].appendChild(this.divElements['softpopupHeadlineText']);

		// Erstellt das <a id="softpopupHeadline"> und speichert das element in this.divElements['softpopupHeadline']
		this.divElements['softpopupCloser'] = new Element('a', { 'id' : 'softpopupCloser', 'href' : '#' });
		this.divElements['softpopupTitle'].appendChild(this.divElements['softpopupCloser']);

		// Erstellt den <span id="softpopupCloserText"> und speichert das element in this.divElements['softpopupCloserText']
		this.divElements['softpopupCloserText'] = new Element('span', { 'id' : 'softpopupCloserText' });
		this.divElements['softpopupCloser'].appendChild(this.divElements['softpopupCloserText']);

		// Erstellt das <div class="clear"> und speichert das element in this.divElements['clear']
		this.divElements['clear'] = new Element('div', { 'class' : 'clear' });
		this.divElements['softpopupTitle'].appendChild(this.divElements['clear']);
		
		// Erstellt das <div id="softpopupBorderRight"> und speichert das element in this.divElements['softpopupBorderRight']
		this.divElements['softpopupBorderRight'] = new Element('div', { 'id' : 'softpopupBorderRight' });
		this.divElements['softpopupBorder'].appendChild(this.divElements['softpopupBorderRight']);

		// Erstellt das <div class="softpopupBorderCenter"> und speichert das element in this.divElements['softpopupBorderRight_center']
		this.divElements['softpopupBorderRight_center'] = new Element('div', { 'class' : 'softpopupBorderCenter' });
		this.divElements['softpopupBorderRight'].appendChild(this.divElements['softpopupBorderRight_center']);
		
		// Erstellt das <div id="softpopupBorderBottom"> und speichert das element in this.divElements['softpopupBorderBottom']
		this.divElements['softpopupBorderBottom'] = new Element('div', { 'id' : 'softpopupBorderBottom' });
		this.divElements['softpopupBorder'].appendChild(this.divElements['softpopupBorderBottom']);

		// Erstellt das <div class="softpopupBorderLeft"> und speichert das element in this.divElements['softpopupBorderBottom_left']
		this.divElements['softpopupBorderBottom_left'] = new Element('div', { 'class' : 'softpopupBorderLeft' });
		this.divElements['softpopupBorderBottom'].appendChild(this.divElements['softpopupBorderBottom_left']);

		// Erstellt das <div class="softpopupBorderCenter"> und speichert das element in this.divElements['softpopupBorderBottom_center']
		this.divElements['softpopupBorderBottom_center'] = new Element('div', { 'class' : 'softpopupBorderCenter' });
		this.divElements['softpopupBorderBottom'].appendChild(this.divElements['softpopupBorderBottom_center']);

		// Erstellt das <div class="softpopupBorderRight"> und speichert das element in this.divElements['softpopupBorderBottom_right']
		this.divElements['softpopupBorderBottom_right'] = new Element('div', { 'class' : 'softpopupBorderRight' });
		this.divElements['softpopupBorderBottom'].appendChild(this.divElements['softpopupBorderBottom_right']);

		// Erstellt das <div id="softpopupBody"> und speichert das element in this.divElements['softpopupBody']
		this.divElements['softpopupBody'] = new Element('div', { 'id' : 'softpopupBody' });
		this.divElements['softpopupContentOutline'].appendChild(this.divElements['softpopupBody']);

		// Erstellt das <div id="softpopupContent"> und speichert das element in this.divElements['softpopupContent']
		this.divElements['softpopupContent'] = new Element('div', { 'id' : 'softpopupContent' });
		this.divElements['softpopupBody'].appendChild(this.divElements['softpopupContent']);

		// Hide <div id="softpopupOverlay"> und erstellt ein onclick der die methode end() aufruft
		this.divElements['softpopupOverlay'].hide().observe('click', (function() { this.end(); }).bind(this));
		// Hide <div id="softpopupWindow">
		this.divElements['softpopupWindow'].hide().observe('click', (function(event) { if (event.element().id == 'softpopupWindow') this.end(); }).bind(this));
		// Erstellt einen onclick der die methode end() aufruft auf <a id="softpopupCloser">
		this.divElements['softpopupCloser'].observe('click', (function(event) { event.stop(); this.end(); }).bind(this));

		this.divElements['softpopupPreContent'].hide();
	},

	startImage: function(linkElement) {
		this.globalStart(linkElement);
		
		this.contentElement = new Element('img', { 'title' : linkElement.title, 'alt' : linkElement.title} );
		this.updateInfoText();
		this.divElements['softpopupContent'].insert(this.contentElement);
		this.contentElement.setStyle({ display: 'none' });

		var oldFontSize = this.htmlFontSize;
		this.checkForGivenParam(linkElement.rel, 'htmlFontSize');
		var endFontSize = this.htmlFontSize;
		this.htmlFontSize = oldFontSize;

		var imgPreloader = new Image();
		imgPreloader.onload = (function(){
			this.contentElement.src = linkElement.href;
			this.resizeSoftpopupContent(imgPreloader.width, (imgPreloader.height + this.divElements['softpopupTitle'].getHeight() - 30), endFontSize, false);
		}).bind(this);
		imgPreloader.src = linkElement.href;
	},

	startContent: function(linkElement) {
		this.globalStart(linkElement);
		this.divElements['softpopupPreContent'].setStyle({ display: 'inline' });
		var contentId = linkElement.href.substr(linkElement.href.indexOf('#') + 1, linkElement.href.length);

		this.contentElement = new Element('div');
		this.updateInfoText();
		
		this.divElements['softpopupContent'].insert(this.contentElement);
		this.contentElement.setStyle({ display: 'none', marginTop: '20px' });
		
		var oldHtmlWidth = this.htmlWidth;
		this.checkForGivenParam(linkElement.rel, 'htmlWidth');
		var oldFontSize = this.htmlFontSize;
		this.checkForGivenParam(linkElement.rel, 'htmlFontSize');
		
		this.divElements['softpopupPreContent'].setStyle({ opacity : '0.00001' , width : this.htmlWidth + 'px', fontSize : this.htmlFontSize + 'px'});
		this.divElements['softpopupPreContentTd'].update($(contentId).innerHTML);

		this.contentElement.update($(contentId).innerHTML);
		this.resizeSoftpopupContent((parseInt(this.htmlWidth)+60), (this.divElements['softpopupPreContent'].getHeight() + this.divElements['softpopupTitle'].getHeight() - 60), this.htmlFontSize, true);
		this.divElements['softpopupPreContentTd'].update('');

		this.htmlFontSize = oldFontSize;
		this.htmlWidth  = oldHtmlWidth;
	},

	globalStart: function(linkElement) {
		$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' });
		this.divElements['softpopupTitle'].hide();

		this.checkForGivenParam(linkElement.rel, 'infoTitle');
		
		if (this.infoTitle.length == '') {
			this.infoTitle = linkElement.title;
		}

		var pageSizeArray = this.getPageSize();
		this.divElements['softpopupOverlay'].setStyle({ height: pageSizeArray[1] + 'px' });
		new Effect.Appear(this.divElements['softpopupOverlay'], { duration: EqsSoftpopupOptions.overlayOpacitySpeed, from: 0.0, to: EqsSoftpopupOptions.overlayOpacity });
		
		var arrayPageScroll = document.viewport.getScrollOffsets();
		this.divElements['softpopupWindow'].setStyle({ display: 'block', top: arrayPageScroll[1] + EqsSoftpopupOptions.marginTop + 'px' });

		var oldCloserText = this.closerText;
		this.checkForGivenParam(linkElement.rel, 'closerText');
		if (this.closerText != oldCloserText && this.closerText != '') {
			this.divElements['softpopupCloserText'].update(this.closerText);
			this.closerText = oldCloserText;
		} else if (this.closerText != '') {
			this.divElements['softpopupCloserText'].update(this.closerText);
		}
	},

	checkForGivenParam: function(rel, paramKey) {
		if (rel.include('?')) {
			var allParamsString = rel.substr(rel.indexOf('?') + 1, rel.length);
			var allParamsArray = allParamsString.split('&');
			

			var bindParamFunction = this.bindParam.bind(this);

			allParamsArray.each(function(value, index) { 
				if (value.startsWith('amp;')) {
					value = value.sub('amp;', '', 1);
				}
				var paramsSplit = value.split('='); 
				if (paramKey == paramsSplit[0]) {
					bindParamFunction(paramKey, paramsSplit[1]);
				}
			});
		}
	},

	bindParam: function(paramKey, value) {
		switch(paramKey) {
			case 'infoTitle':
				this.infoTitle = value;
				break;
			case 'closerText':
				this.closerText = value;
				break;
			case 'htmlFontSize':
				this.htmlFontSize = value;
				break;
			case 'htmlWidth':
				this.htmlWidth = value;
				break;
		}
	},
	
	end: function() {
		this.divElements['softpopupContent'].update('');
		this.infoTitle = '';
		
		var bodyHeight = this.divElements['softpopupBody'].getHeight();
		this.divElements['softpopupBorderLeft'].setStyle({ height: bodyHeight + "px" });
   	    this.divElements['softpopupBorderRight'].setStyle({ height: bodyHeight + "px" });
   		this.divElements['softpopupBorderLeft_center'].setStyle({ height: bodyHeight + "px" });
   	    this.divElements['softpopupBorderRight_center'].setStyle({ height: bodyHeight + "px" });
		
		new Effect.Fade(this.divElements['softpopupOverlay'], {
			duration: EqsSoftpopupOptions.overlayOpacitySpeed,
			afterFinish: (function() { this.divElements['softpopupOverlay'].setStyle({ height: '0px;', width: '0px;' }) }).bind(this)
		});
		this.divElements['softpopupWindow'].hide();
		this.divElements['softpopupPreContent'].hide();
		$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'visible' });
	},

	updateInfoText: function() {
		/*this.divElements['softpopupTitle'].hide();*/
		this.divElements['softpopupHeadlineText'].innerHTML = this.infoTitle;
		this.divElements['softpopupContent'].insert('<div id="softpopupHeadline"><span class="left">' + this.infoTitle + '</span><div class="right" onclick="eqs.end();">X</span></div>');
		
		/*
		new Effect.Parallel(
            [ 
                new Effect.SlideDown(this.divElements['softpopupTitle'], {
                	sync: true,
					duration: EqsSoftpopupOptions.resizeSpeed,
					delay: EqsSoftpopupOptions.resizeSpeed,
                	from: 0.0,
                	to: 1.0
                }), 
                new Effect.Appear(this.divElements['softpopupTitle'], {
                	sync: true,
					duration: EqsSoftpopupOptions.resizeSpeed,
					delay: EqsSoftpopupOptions.resizeSpeed
                }) 
            ], 
            { 
				duration: EqsSoftpopupOptions.resizeSpeed,
				delay: EqsSoftpopupOptions.resizeSpeed, 
                afterFinish: (function() {
	                // update overlay size and update nav
	                var pageSizeArray = this.getPageSize();
	                this.divElements['softpopupOverlay'].setStyle({ height: pageSizeArray[1] + 'px' });
                }).bind(this)
            } 
        );
        
        if(this.divElements['softpopupBorderLeft'].getHeight() != (this.divElements['softpopupTitle'].getHeight() + 1 + this.divElements['softpopupBody'].getHeight())){
	        var oldHeight = this.divElements['softpopupBorderLeft'].getHeight();
	        var newHeight = this.divElements['softpopupBody'].getHeight() + this.divElements['softpopupTitle'].getHeight() + 1;
	        var scale = (newHeight / oldHeight) * 100;
	        
	        new Effect.Scale(this.divElements['softpopupBorderLeft'], scale, {
				scaleX: false,
				duration: EqsSoftpopupOptions.resizeSpeed,
				delay: EqsSoftpopupOptions.resizeSpeed
			});
			
			new Effect.Scale(this.divElements['softpopupBorderLeft_center'], scale, {
				scaleX: false,
				duration: EqsSoftpopupOptions.resizeSpeed,
				delay: EqsSoftpopupOptions.resizeSpeed
			});
			
			new Effect.Scale(this.divElements['softpopupBorderRight'], scale, {
				scaleX: false,
				duration: EqsSoftpopupOptions.resizeSpeed,
				delay: EqsSoftpopupOptions.resizeSpeed
			});
			
			new Effect.Scale(this.divElements['softpopupBorderRight_center'], scale, {
				scaleX: false,
				duration: EqsSoftpopupOptions.resizeSpeed,
				delay: EqsSoftpopupOptions.resizeSpeed
			});
		}*/
	},

	// Method showContent();
	// Lässt den Content langsam erscheinen
	showContent: function() {
		new Effect.Appear(this.contentElement, { 
            duration: EqsSoftpopupOptions.resizeSpeed, 
            queue: 'end'
        });
	},

	// Method resizeSoftpopupContent();
	// @param	contentWidth	Breite die der Content haben wird
	// @param	contentHeight	Höhe die der Content haben wird
	// vergrößert das <div id="softpopupBody"> auf die Breite des Contents plus dem padding des <div id="softpopupContent">
	resizeSoftpopupContent: function(contentWidth, contentHeight, endFontSize, isHtml) {
		var softpopupContentPaddingLeft = parseInt(parseFloat(this.divElements['softpopupContent'].getStyle('padding-left')));
		var softpopupContentPaddingRight = parseInt(parseFloat(this.divElements['softpopupContent'].getStyle('padding-right')));
		var softpopupContentPaddingTop = parseInt(parseFloat(this.divElements['softpopupContent'].getStyle('padding-top')));
		var softpopupContentPaddingBottom = parseInt(parseFloat(this.divElements['softpopupContent'].getStyle('padding-bottom')));
		
		var widthCurrent  = this.divElements['softpopupBody'].getWidth();
		var heightCurrent = this.divElements['softpopupBody'].getHeight();

		var widthNew  = (contentWidth + softpopupContentPaddingLeft + softpopupContentPaddingRight);
		var heightNew = (contentHeight + softpopupContentPaddingTop + softpopupContentPaddingBottom);

		if(isHtml == true) {
			widthNew = contentWidth;
		}
		
		var xScaleBorder = ((parseInt(widthNew)+40) / this.divElements['softpopupBorder'].getWidth()) * 100;
		var yScaleBorder = ((parseInt(heightNew)+40) / this.divElements['softpopupBorder'].getHeight()) * 100;
		
		var xScale = (widthNew  / widthCurrent)  * 100;
		var yScale = (heightNew / heightCurrent) * 100;

		var wDiff = widthCurrent - widthNew;
		var hDiff = heightCurrent - heightNew;

		if (hDiff != 0) new Effect.Scale(this.divElements['softpopupBody'], yScale, {
			scaleX: false,
			duration: EqsSoftpopupOptions.resizeSpeed,
			delay: EqsSoftpopupOptions.resizeSpeed,
			afterFinish: (function() {
				this.divElements['softpopupBody'].setStyle({ fontSize: endFontSize + 'px' });
			}).bind(this)
		});
		
		if (hDiff != 0) new Effect.Scale(this.divElements['softpopupBorderLeft_center'], yScale, {
			scaleX: false,
			duration: EqsSoftpopupOptions.resizeSpeed,
			delay: EqsSoftpopupOptions.resizeSpeed
		});
		
		if (hDiff != 0) new Effect.Scale(this.divElements['softpopupBorder'], yScaleBorder, {
			scaleX: false,
			duration: EqsSoftpopupOptions.resizeSpeed,
			delay: EqsSoftpopupOptions.resizeSpeed
		});
		
		if (hDiff != 0) new Effect.Scale(this.divElements['softpopupBorderLeft'], yScale, {
			scaleX: false,
			duration: EqsSoftpopupOptions.resizeSpeed,
			delay: EqsSoftpopupOptions.resizeSpeed
		});
		
		if (hDiff != 0) new Effect.Scale(this.divElements['softpopupBorderRight_center'], yScale, {
			scaleX: false,
			duration: EqsSoftpopupOptions.resizeSpeed,
			delay: EqsSoftpopupOptions.resizeSpeed
		});
		
		if (hDiff != 0) new Effect.Scale(this.divElements['softpopupBorderRight'], yScale, {
			scaleX: false,
			duration: EqsSoftpopupOptions.resizeSpeed,
			delay: EqsSoftpopupOptions.resizeSpeed
		});
		
        if (wDiff != 0) new Effect.Scale(this.divElements['softpopupBody'], xScale, {
			scaleY: false,
			duration: EqsSoftpopupOptions.resizeSpeed,
			delay: EqsSoftpopupOptions.resizeSpeed
		});
		
		if (wDiff != 0) new Effect.Scale(this.divElements['softpopupBorderTop_center'], xScale, {
			scaleY: false,
			duration: EqsSoftpopupOptions.resizeSpeed,
			delay: EqsSoftpopupOptions.resizeSpeed
		});
		
		if (wDiff != 0) new Effect.Scale(this.divElements['softpopupBorder'], xScaleBorder, {
			scaleY: false,
			duration: EqsSoftpopupOptions.resizeSpeed,
			delay: EqsSoftpopupOptions.resizeSpeed
		});
		
		if (wDiff != 0) new Effect.Scale(this.divElements['softpopupBorderTop'], xScaleBorder, {
			scaleY: false,
			duration: EqsSoftpopupOptions.resizeSpeed,
			delay: EqsSoftpopupOptions.resizeSpeed
		});
		
		if (wDiff != 0) new Effect.Scale(this.divElements['softpopupBorderBottom_center'], xScale, {
			scaleY: false,
			duration: EqsSoftpopupOptions.resizeSpeed,
			delay: EqsSoftpopupOptions.resizeSpeed
		});
		
		if (wDiff != 0) new Effect.Scale(this.divElements['softpopupBorderBottom'], xScaleBorder, {
			scaleY: false,
			duration: EqsSoftpopupOptions.resizeSpeed,
			delay: EqsSoftpopupOptions.resizeSpeed
		});
		
		var timeout = 0;
        if ((hDiff == 0) && (wDiff == 0)){
            timeout = 100;
            if (Prototype.Browser.IE) timeout = 250;
        }

		(function(){
			this.divElements['softpopupTitle'].setStyle({ width: widthNew + 'px' });
			this.showContent();
        }).bind(this).delay(timeout / 1000);
	},

	// Method: createOnclick();
	// Sucht den DOM nach <a rel="lightboxImage"> ab und erstellt einen onclick auf die Methode startImage()..
	createOnclick: function() {
		var lightboxAs = $$(".lightboxLink");
		
		for(var i = 0; i<lightboxAs.length; i++){
			lightboxAs[i].observe('click', (function(event){
				var htmlTarget = event.findElement('a[rel^=lightboxHTML]');
				if (htmlTarget) {
					event.stop();
					this.startContent(htmlTarget);
				}
				if(!htmlTarget){
					var imageTarget = event.findElement('a[rel^=lightboxImage]') || event.findElement('a[rel^=lightbox]');
					if (imageTarget) {
						event.stop();
						this.startImage(imageTarget);
					}
				}
			}).bind(this));
		}
	},
	
	getPageSize: function() {
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
		
		// for small pages with total height less then height of the viewport
		pageHeight = (yScroll < windowHeight) ? windowHeight: yScroll;
	
		// for small pages with total width less then width of the viewport
		pageWidth = (xScroll < windowWidth) ? xScroll : windowWidth;

		return [pageWidth,pageHeight];
	}

}
var eqs;
document.observe('dom:loaded', function () { eqs = new EqsSoftpopup(); });