 /**
  * Silbentrennung starten
  */
Hyphenator.config({
	displaytogglebox : false,
	minwordlength : 4,
	onerrorhandler : function (e) { /* do nothing */ }
});

Hyphenator.run()
	
/**
 * Verlustrechner
 */

// Hauptfunktion f�r Renditeberechnung
function showRevenue() {
	var refExchange = document.getElementById('exchange');
	var refYield = document.getElementById('yield');
	var refResult = document.getElementById('result');
	var refWastage = document.getElementById('wastage');
	var refMinimizedResult = document.getElementById('minimizedResult');
//	var refMoreExchange = document.getElementById('moreExchange');
	var refResultSummary = document.getElementById('resultSummary');
	var refTotalMoreExchange = document.getElementById('totalMoreExchange');
	
	var yield = parseFloat(refYield.value);
	var wastage = parseFloat(refWastage.value);
	var exchange = parseFloat(refExchange.value);
	var wastagePercent = yield-wastage;	

	var result = parseFloat(calculateRevenue(exchange, yield));
	
	if (!isNaN(result)) {
		var roundedResult = roundPercent(result);
		refResult.innerHTML = roundedResult;
		refResultSummary.innerHTML = roundedResult;
		
		// Falls Forderungsausfall berechnet werden kann
		if (wastage) {
			var minimizedResult = calculateRevenue(exchange, wastagePercent);
			if (minimizedResult) {
				refMinimizedResult.innerHTML = roundPercent(minimizedResult);
			} else {
				refMinimizedResult.innerHTML = '--';
			}

			// Ben�tigter Mehrumsatz
			if (minimizedResult && minimizedResult) {
				var newPercent = roundPercent(yield / wastagePercent);
//				refMoreExchange.innerHTML = roundPercent(exchange * newPercent - exchange);
				refTotalMoreExchange.innerHTML = roundPercent(exchange * newPercent)+'&nbsp;�';
			}
		}

	} else {
		refResult.innerHTML = '--';
	}
}

// Rendite berechnen
function calculateRevenue(exchange, yield) {
	return exchange / 100 * yield;
}

/**
 * Verringerten Gewinn berechnen
 *
 * @param revenue number Gewinnsumme, Ganzzahl
 * @param wastage number Prozent
 */
 /* 
function calculateMinimizedRevenue(revenue, wastage) {
	var wastageRounded = roundPercent(parseFloat(wastage));
	return roundPercent(revenue - revenue * wastage / 100);
}
*/
/**
 * roundPercent
 * Rundet auf zwei Stellen hinter dem Komma
 *
 * @param number float/integer Zahl, die auf zwei Stellen hinter dem Komma gerundet werden soll
 * @return float
 */
function roundPercent(number) {
	number = parseInt(number*100)/100;
	return number.toFixed(2)
}


/**
 * function activateSlider()
 * aktiviert einen angeklickten Reiter
 *
 * @param sliderID string ID des zu aktivierenden Reiters
 * @param toogleSliderID object IDs aller Slider, die ausgeblendet werden sollen als JSON-Objekt
 * @return float
  */
function activateSlider(sliderID, toogleSliderID, contentID, toogleContentID) {
	
	// Reiter aktivieren
	refActiveSlider = document.getElementById(sliderID);
	if (refActiveSlider != undefined) {
		refActiveSlider.className = 'sliderActive';
		refActiveSlider.blur();
	}
	
	// andere Reiter deaktivieren
	for (el in toogleSliderID) {
		refSliderInActive = document.getElementById(toogleSliderID[el]);
		if (refSliderInActive != undefined) {
			refSliderInActive.className = 'sliderInActive';
		}
	}

	// Content aktivieren
	refActiveContent = document.getElementById(contentID);
	if (refActiveContent != undefined) {
		refActiveContent.style.display = 'block';
	}
	
	// anderen Content deaktivieren
	for (el in toogleContentID) {
		refContentInActive = document.getElementById(toogleContentID[el]);
		if (refContentInActive != undefined) {
			refContentInActive.style.display = 'none';
		}
	}
}

/* ---------------------------------------------------
 * 
 * 	Methoden f�r UI (Modalfenster, etc.)
 * 
   ---------------------------------------------------*/

/*
	script.aculo.us EffectResize.js
	Copyright(c) 2007 - Frost Innovation AS, http://ajaxwidgets.com

	EffectResize.js is freely distributable under the terms of an MIT-style license.
	For details, see the script.aculo.us web site: http://script.aculo.us/

	Modified by Elijah Lofgren to work with Prototype 1.4.0_rc3
	Helper Effect for resizing elements...
*/

Effect.ReSize = Class.create();
Object.extend(Object.extend(Effect.ReSize.prototype, Effect.Base.prototype), {
	initialize: function(element) {
    	this.element = element;
		if(!this.element) throw(Effect._elementDoesNotExistError);
		var options = Object.extend({ amount: 100, direction: 'vert', toSize:null }, arguments[1] || {});
		if (options.direction == 'vert') {
			this.originalSize = options.originalSize || parseInt(this.element.getHeight());
		} else {
			this.originalSize = options.originalSize || parseInt(this.element.getWidth());
		}

		if( options.toSize != null ) {
			options.amount = options.toSize - this.originalSize;
		}

		this.start(options);
	},
	
	setup: function() {
    	// Prevent executing on elements not in the layout flow
		if(this.element.style.display == 'none') { this.cancel(); return; }
	},
	
	update: function(position) {
		if( this.options.direction == 'vert' ){
			this.element.setStyle({
				height: this.originalSize + (this.options.amount * position) + 'px'
			});
		} else {
			this.element.style.width = this.originalSize+(this.options.amount * position)+'px';
		}
	},
	
	
	finish: function(){
		if( this.options.direction == 'vert' ){
			this.element.style.height = this.originalSize+this.options.amount+'px';
		} else {
			this.element.style.width = this.originalSize+this.options.amount+'px';
		}
	}
});

Effect.ReSize.Direct = function(element, options){
	switch(options.direction){
		case 'vert':
			var oldHeight = parseInt(element.style.height, 10);
			oldHeight += options.amount;
			element.style.height = (oldHeight+'px');
			break;
		
		case 'horz':
			var oldWidth = parseInt(element.style.width, 10);
			oldWidth += options.amount;
			element.style.width = (oldWidth+'px');
			break;
		default:
			throw "Unsupported enum in Effect.ReSize.Direct�!!";
	}
}

/**
 * Erweiterung prototype-Ajax-update-Methode: 
 * Eigene Methode f�r Ajax-HTML-Updates mit Ladegrafik
 * 
 */
Element.addMethods({
	ajaxUpdate: function(element, url, options){
		element = $(element);
/*
		height = element.getHeight();
		
		spinnerContainer = document.createElement('div');
		spinnerContainer.addClassName('cmtInProgress');
		spinnerContainer.setStyle({height: height+'px'});

		element.appendChild(spinnerContainer);
*/	
		new Ajax.Updater(element, url, options);
	    return element;
	  }
});

var cmtUI = Class.create();
	
	// Array f�r Fensterreferenzen
	cmtUI.registeredWindows = new Array();
	
	/**
	 * cmtUI.registerWindow
	 * Registriert die Referenz eines Fensterobjektes im �bergeordneten cmtUI-Objekt
	 *
	 * @params Object Referenz auf das Fensterobjekt
	 * @return void
	 */
	cmtUI.registerWindow = function (refObj) {
		this.registeredWindows.push(refObj);
	}
	
	/**
	 * cmtUI.getRegisteredWindows
	 * Gibt ein Array mit den regisitrieren Fensterobjektreferenzen zur�ck
	 *
	 * @params void
	 * @return Array Alle registrierten Referenzen in einem Array
	 */
	cmtUI.getRegisteredWindows = function () {
		return this.registeredWindows;
	}	
	
/* ------------------------------------------------
	Overlay: Start
   ------------------------------------------------ */
	/**
	 * function initOverlay();
	 * Initialisert die Overlay-Fl�che
	 *
	 * @param void
	 * @return void
	 */
	cmtUI.overlay = Class.create();
	
	cmtUI.overlay.prototype = {
		initialize: function(params){
		
			this.params = Object.extend({
				appearSpeed: 0.3,
				fadeSpeed: 0.3,
				opacity: 0.4,
				className: 'cmtOverlay',
				onShow: function(ev) {},
				onHide: function(ev) {},
				bindObject: this
			}, params)

			this.overlayIsVisible = false;
			
			Event.observe(document, 'dom:loaded', this.initOverlay.bindAsEventListener(this));
		},
		
		/**
		 * function initOverlay();
		 * Initialisert die Overlay-Fl�che
		 *
		 * @param void
		 * @return void
		 */
		initOverlay: function(){
	
			this.overlay = new Element('div', {
				id: 'cmtOverlay',
				className: this.params.className
			});

			// Overlay an Body h�ngen
			$(document.body).insert(this.overlay);
			
			// Event-Observer: bei Klick ausblenden
			this.overlay.observe('click', this.hideOverlay.bindAsEventListener(this))

			// anfangs ausblenden
			this.overlay.hide();
			
		},
		
		/**
		 * function hideOverlay();
		 * Blendet die Overlay-Fl�che aus
		 *
		 * @param void
		 * @return void
		 */
		hideOverlay: function(){

			this.overlayIsVisible = false;		
			
			// Fenster schlie�en
			var win = cmtUI.getRegisteredWindows();
			
			win.each(
				function(el) {
					el.closeWindow(null, false);
				},
				this
			
			)

			
			Effect.Fade(this.overlay, {
				duration: this.params.fadeSpeed,
				from: this.params.opacity,
				to: 0,
				afterFinish: this.params.onHide.bind(this)
			});
			
		},
		
		/**
		 * function showOverlay();
		 *
		 * Zeigt die Overlay-Fl�che
		 *
		 * @param void
		 * @return void
		 */
		showOverlay: function(params){
			
			params = Object.extend(this.params, params)
			
			this.overlayIsVisible = true;
			
			this.overlay.setStyle({
				position: 'fixed',
				width: '100%',
				height: '100%',
				top: 0,
				left: 0
			});

			Effect.Appear(this.overlay, {
				duration: this.params.appearSpeed,
				from: 0,
				to: this.params.opacity,
				afterFinish: params.onShow.bind(params.bindObject)
			});
		}
	}
	
	cmtUI.overlayHandler = new cmtUI.overlay();
	
/* ------------------------------------------------
	Modal-Fenster: Start
   ------------------------------------------------ */
	cmtUI.modalWindow = Class.create();

	cmtUI.modalWindow.prototype = {
		
		/**
		 * function initialize()
		 * Initialisiert das Modalfenster
		 * 
		 * @params {Object} Objekt mit Parametern - wird derzeit nicht genutzt
		 *
		 * @return void
		 */
		initialize: function(params){
		
			// 2010-08-18: Wird derzeit nicht genutzt
			this.params = Object.extend({
				className: '',
				overlay: true,
				onShow: function(ev) {},
				onHide: function(ev) {}
			}, params)

			this.paramsCache = new Object();
			this.initWindow();
		},
		
		initWindow: function(ev) {

			// Variablen
			this.windowIsVisible = false;

			// Overlay-Inhalts-DIV erzeugen
			// Wrapper-Container
			this.windowWrapper = new Element('div', {
				id: 'cmtModalWinWrapper'
			});
			if (cmtUI.overlayHandler) {
				this.windowWrapper.observe('click', this._checkClosingClick.bindAsEventListener(cmtUI.overlayHandler))
			}
			
			// Fenster-Container: Das eigentliche Fenster
			this.windowContainer = new Element('div', {
				id: 'cmtModalWinContainer'
				//className: this.params.className
			});

			// Kopf
			this.windowHead = new Element('div', {
				id: 'cmtModalWinHead'
			});
			
			// Kopf: Titel-Container
			this.windowHeadTitle = new Element('div', {
				id: 'cmtModalWinHeadTitle'
			});

			// Kopf: Close-Knopf
			this.windowHeadClose = new Element('div', {
				id: 'cmtModalWinHeadClose'
			});
			// Close-Knopf �berwachen
			Event.observe(this.windowHeadClose, 'click', this.closeWindow.bindAsEventListener(this, false));

			// Fensterinhalt
			this.windowContent = new Element('div', {
				id: 'cmtModalWinContent'
			});
			this.windowContentInner = new Element('div', {
				id: 'cmtModalWinContentInner'
			});
			this.windowContent.insert(this.windowContentInner);
			
			// Kn�pfe: Container
			this.windowButtons = new Element('div', {
				id: 'cmtModalWinButtonsContainer',
				className: 'clearfix'
			});
			this.windowButtons.hide();

			// Knopf 1: OK bei Fenstertyp Message
			this.windowButtonOK = new Element('a', {
				id: 'cmtModalWinButtonClose',
				href: 'Javascript: void(0);',
				className: 'cmtModalWinButtonOK'
			});
			this.windowButtonOK.update('OK!');
			this.windowButtonOK.hide();
			Event.observe(this.windowButtonOK, 'click', this.closeWindow.bindAsEventListener(this, true));
			this.windowButtons.insert(this.windowButtonOK);
			
			// Knopf 2: Best�tigen bei Fenstertyp Confirm
			this.windowButtonConfirm = new Element('a', {
				id: 'cmtModalWinButtonConfirm',
				href: 'Javascript: void(0);',
				className: 'cmtModalWinButtonConfirm'
			});
			this.windowButtonConfirm.update('Best�tigen!');
			this.windowButtonConfirm.hide();
			Event.observe(this.windowButtonConfirm, 'click', this.closeWindow.bindAsEventListener(this, true));
			this.windowButtons.insert(this.windowButtonConfirm);

			// Knopf 3: Abbrechen bei Fenstertyp Confirm
			this.windowButtonCancel = new Element('a', {
				id: 'cmtModalWinButtonCancel',
				href: 'Javascript: void(0);',
				className: 'cmtModalWinButtonCancel'
			});
			this.windowButtonCancel.update('Abbrechen!');
			this.windowButtonCancel.hide();
			Event.observe(this.windowButtonCancel, 'click', this.closeWindow.bindAsEventListener(this, false));
			this.windowButtons.insert(this.windowButtonCancel);			
			// Kn�pfe an Inhalt h�ngen
			this.windowContent.insert(this.windowButtons);
				
			// 1. Fensterkopf
			//this.windowHeadTitle.insert(this.params.title);
			this.windowHead.insert(this.windowHeadTitle);
			this.windowHead.insert(this.windowHeadClose);
			
			// 2. Gesamtfenster
			this.windowContainer.insert(this.windowHead);
			this.windowContainer.insert(this.windowContent);
			//Event.observe(window, 'resize', this.refreshWindowPosition.bindAsEventListener(this));
			
			// 3. Einf�gen
			this.windowWrapper.insert(this.windowContainer);
			$(document.body).insert(this.windowWrapper);
			this.windowContainer.hide();
			
			cmtUI.registerWindow(this);
			
			this._showWindowAfterLoad();
		},

		showWindowAfterLoad: function(params) {
			Object.extend(this.paramsCache, params)
		},
		
		_showWindowAfterLoad: function() {
			// schlechte L�sung. Besser die L�nge des Cache ermittelnt
			if (typeof this.paramsCache.type != 'undefined') {
				this.showWindow(this.paramsCache);
			}
		},
		
		/**
		 * function showWindow();
		 * Zeigt das Fenster
		 *
		 * @params {Object} params Objekt mit folgenden Parametern:
		 * - content {String} Inhalt des Modalfensters
		 * - contentURL {String} URL der Seite, die als Inhalt per Ajax-Request geladen werden soll
		 * - title {String} Titeltext des Modalfensters
		 * - type {String} M�gliche, vordefinierte Typen: confirm, alert, message
		 * - className {String} Zus�tzlicher CSS-Selektor f�r den Modalfenster-Container
		 * - appearSpeed {Float} Einblendgeschwindigkeit des Modalfensters in Sekunden
		 * - timeout {Float} Sekunden, nach denen das Modalfenster automatisch ausgeblendet werden soll
		 * - overlay {Boolean} Bestimmt, ob ein Overlay hinter das Modalfenster gelegt werden soll
		 * - showButton {String} 'message' oder 'alert' zeigen 'OK'-Knopf, 'confirm' zeigt 'Abbruch'- und 'Best�tigen'-Knopf
		 * - buttonConfirmText {String} Inhalt des 'Best�tigen'-Knopfes
		 * - buttonCancelText {String} Inhalt des 'Abbrechen'-Knopfes
		 * - buttonOKText {String} Inhalt des 'OK'-Knopfes
		 * - buttonConfirmClassName {String} zus�tzlicher CSS-Selektor des 'Best�tigen'-Knopfes
		 * - buttonCancelClassName {String} zus�tzlicher CSS-Selektor des 'Abbrechen'-Knopfes
		 * - buttonOKClassName {String} zus�tzlicher CSS-Selektor des 'OK'-Knopfes
		 * - onShow {Function} Funktion wird ausgef�hrt nach Einblenden des Fensters
		 * - onClose {Function} Funktion wird ausgef�hrt nach Schlie�en des Fensters
		 * - onAbort {Function} Funktion wird ausgef�hrt beim Klick auf den 'Abbrechen'-Knopf (showButton = 'confirm')
		 * - onConfirm {Function} Funktion wird ausgef�hrt beim Klick auf den 'Best�tigen'-Knopf (showButton = 'confirm')
		 *
		 * @return void
		 */
		showWindow: function(params) {
	
			this.windowParams = Object.extend({
				content: null,
				contentURL: null,
				title: '',
				type: '',
				className: '',
				appearSpeed: 0.1,
				timeout: 0,
				overlay: true,
				showButton: '',
				dontShowButtons: false,
				onShow: function(ev) {},
				onClose: function(ev) {},
				onAbort: function(ev) {},
				onConfirm: function(ev) {},
				onCancel: function(ev) {}
			}, params)

			// Variablen setzen
			this.currentHeight = -1;
			this.currentWidth = -1;
			this.windowIsVisible = true;
			
			//this.windowWrapper.addClassName(this.windowParams.className);
			
			// Optionen
			// 1. Muss ein Overlay-Fenster angezeigt werden?
			if (this.windowParams.overlay) {
				cmtUI.overlayHandler.showOverlay({onShow: this._showWindow.bind(this), bindObject: this});
				//this.windowContainer.show();
			} else {
				this.windowContainer.show();
			}
			
			// 2. Fenster nach einer Weile automatisch ausblenden?
			if (this.windowParams.timeout) {
				this.pE = new PeriodicalExecuter(this.closeWindow.bind(this, false), this.windowParams.timeout);
			}
			
			// 3. Fenstertyp
			switch (this.windowParams.type) {
				
				case 'alert':
					this.windowContainer.addClassName('cmtWinAlert');
					this.windowParams.overrideResizeEffects = true;
					this.windowParams.showButton = 'message';

					if (this.windowParams.buttonOKText) {
						this.windowButtonOK.update(this.windowParams.buttonOKText);
					}
					
					if (this.windowParams.buttonOKClassName) {
						this.windowButtonOK.addClassName(this.windowParams.buttonOKClassName);
					}
					break;
					
				case 'confirm':
					this.windowContainer.addClassName('cmtWinConfirm');
					this.windowParams.overrideResizeEffects = true;
					this.windowParams.showButton = 'confirm';
					
					if (this.windowParams.buttonConfirmText) {
						this.windowButtonConfirm.update(this.windowParams.buttonConfirmText);
					}
					if (this.windowParams.buttonCancelText) {
						this.windowButtonCancel.update(this.windowParams.buttonCancelText);
					}
					
					if (this.windowParams.buttonCancelClassName) {
						this.windowButtonCancel.addClassName(this.windowParams.buttonCancelClassName);
					}
					
					if (this.windowParams.buttonConfirmClassName) {
						this.windowButtonConfirm.addClassName(this.windowParams.buttonConfirmClassName);
					}
					break;
				
				case 'message':
					this.windowContainer.addClassName('cmtWinMessage');
					this.windowParams.overrideResizeEffects = true;
					this.windowParams.showButton = 'message';

					if (this.windowParams.buttonOKText) {
						this.windowButtonOK.update(this.windowParams.buttonOKText);
					}
					
					if (this.windowParams.buttonOKClassName) {
						this.windowButtonOK.addClassName(this.windowParams.buttonOKClassName);
					}
					break;
				
				default:
					this.windowParams.overrideResizeEffects = false;
					break;
			}
			
			// 4. Fenstertitel
			this.windowHeadTitle.update(this.windowParams.title);
			
			// 5. Kn�pfe anzeigen
			if (!this.windowParams.dontShowButtons && this.windowParams.showButton) {
				this.windowButtons.show();
				
				switch (this.windowParams.showButton) {
				
					case 'confirm':
						this.windowButtonConfirm.show();
						this.windowButtonCancel.show();
						break;
					
					default:
					case 'message':
						this.windowButtonOK.show();
						if (this.windowParams.buttonOKText) {
							this.windowButtonOK.update(this.windowParams.buttonOKText);
						}
						if (this.windowParams.buttonOKClassName) {
							this.windowButtonOK.addClassName(this.windowParams.buttonOKClassName);
						}
						break;
				}
			}
			
			// 6. individueller CSS-Selektor
			if (typeof this.windowParams.className != 'undefined') {
				this.windowContainer.addClassName(this.windowParams.className);
			}
		},

		/**
		 * function _showWindow();
		 * Hilfsfunktion: Blendet das Fenster ein
		 *
		 * @params void
		 * @return void
		 */		
		_showWindow: function() {
			
			if (!this.windowParams.overrideResizeEffects) {
				Effect.Appear(this.windowContainer, {
					duration: this.windowParams.appearSpeed,
					from: 0,
					to: 1,
					transition: Effect.Transitions.sinoidal,
					afterFinish: this._showWindowContent.bind(this)
				});
			} else {
				this.windowContainer.show();
				this._showWindowContent();
				this.refreshWindowWidth({
					afterFinish: (this.refreshWindowHeight).bind(this)
				});
			}
		},

		/**
		 * function _showWindowContent();
		 * Hilfsfunktion: Blendet den Fensterinhalt ein, bzw. L�dt die Inhalte nach
		 *
		 * @params void
		 * @return void
		 */			
		_showWindowContent: function() {
			
			// Fensterinhalt anzeigen/ laden
			
			// URL
			if (this.windowParams.contentURL) {
				this.getAjaxWindowContent();
			}

			// Referenz auf Element oder Textinhalte
			if (this.windowParams.content) {
				var newContent = $(this.windowParams.content).clone(true);
				newContent.id = '';
				newContent.setStyle({
					display: 'block',
					visibility: 'visible'
				});

				this.windowContentInner.update(newContent);
				this.windowContentInner.show();
				this.windowContentInner.setStyle({visibility: 'visible'});
			}			
		},
		
		_displayWindowContent: function () {
			this.windowContentInner.setOpacity(0);
			this.windowContentInner.setStyle({visibility: 'visible'});
			Effect.Appear(this.windowContentInner, {
				duration: 0.2,
				transition: Effect.Transitions.sinoidal
			});

		},
		
		_hideWindowContent: function() {
			this.windowContentInner.setStyle({visibility: 'hidden'})
		},
		
		/**
		 * function closeWindow();
		 * Zeigt das Fenster
		 *
		 * @params Object Objekt mit folgenden Parametern:
		 * - content string Inhalt des Modalfensters
		 * - title string Titeltext des Modalfensters
		 * - className string Zus�tzlicher CSS-Selektor f�r den Modalfenster-Container
		 * - overlay boolean Bestimmt, ob ein Overlay hinter das Modalfenster gelegt werden soll
		 *
		 * @return void
		 */	
		closeWindow: function(ev, ret) {

			// Events
			switch (this.windowParams.type) {
				
				case 'confirm':
					if (ret) {
						this.windowParams.onConfirm();
					} else {
						this.windowParams.onCancel();
					}
					break;
					
				default:
					this.windowParams.onClose();
					break;
			}
			
			// Kn�pfe verstecken
			this.windowButtons.hide();
			this.windowButtonOK.hide();
			this.windowButtonCancel.hide();
			this.windowButtonConfirm.hide();
			
			// ausblenden
			Effect.Fade(this.windowContainer, {
				duration: 0.2,
				transition: Effect.Transitions.sinoidal,
				afterFinish: this._hideWindowContentImmediatly.bind(this)
			});			

			if (this.windowParams.overlay && cmtUI.overlayHandler.overlayIsVisible) {
				cmtUI.overlayHandler.hideOverlay();
			}

			// Falls Fenster nach Zeitspanne ausgeblendet werden muss, Executer l�schen
			if (this.windowParams.timeout && this.pE) {
				this.pE.stop();
			}

			// Fensterstatus
			this.windowIsVisible = false;
			
			this.windowContainer.removeClassName(this.windowParams.className);
			
			return ret;
		},
		
		_hideWindowContentImmediatly: function() {
			
			this.windowContainer.setStyle({ 
				width: ''
			});
			
			this.windowContent.setStyle({ 
				height: ''
			});

			this.currentHeight = -1;
			this.currentWidth = -1;

			this.windowContentInner.setStyle({visibility: 'hidden'});
			this.windowContentInner.update('');

			// Fenstertyp? Aufr�umen
			switch (this.windowParams.type) {
				
				case 'alert':
					this.windowContainer.removeClassName('cmtWinAlert');
					this.windowButtonOK.removeClassName(this.windowParams.buttonOKClassName);
					break;
					
				case 'confirm':
					this.windowContainer.removeClassName('cmtWinConfirm');
					this.windowButtonConfirm.removeClassName(this.windowParams.buttonConfirmClassName);
					this.windowButtonCancel.removeClassName(this.windowParams.buttonCancelClassName);
					break;
				
				case 'message':
					this.windowContainer.removeClassName('cmtWinMessage');
					this.windowButtonOK.removeClassName(this.windowParams.buttonOKClassName);
					break;
					
				default:
					
					break;
					
			}
		},
		
		refreshWindowDimensions: function(params) {
			
			params = Object.extend(params, {afterFinish: (this.refreshWindowHeight).bind(this)});
			this.refreshWindowWidth(params);
		},
		
		/**
		 * function refreshWindowWidth();
		 * Aktualisiert die Breite des Fensters anhand der Breite der Inhalte
		 *
		 * @params {Object} params Parameter als Objekt:
		 * - refElement {Object} Referenz auf Element innerhalb des Inhalts (z.B. Grafik), dessen Breite ausschlaggebend sein soll
		 *
		 * @return void
		 */	
		refreshWindowWidth: function(params) {
			
			// H�he und Breite ermitteln
			var contentDimensions = new Object ();

			// Wurde eine Referenz auf ein Element �bergeben, dessen Dimensionen ma�geblich sind?
			if (params.refElement) {
				var contentDimensions = $(params.refElement).getDimensions();
			
			}
			
			// Wurde Breite mit �bergeben?
			if (params.width) {
				contentDimensions.width = params.width;
			}
			
			// Wurde H�he mit �bergeben?
			if (params.height) {
				contentDimensions.height = params.height;
			}
 
			// Fallback: Dimensionen des Fensterinhalts nehmen
			if (!contentDimensions.width) {
				contentDimensions.width = this.windowContentInner.getWidth();
			}
			
			if (!contentDimensions.height) {
				contentDimensions.height = this.windowContentInner.getHeight();
			}

			var paddingLeft = parseInt(this.windowContainer.getStyle('paddingLeft')) + parseInt(this.windowContent.getStyle('paddingLeft'));
			var paddingRight = parseInt(this.windowContainer.getStyle('paddingRight')) + parseInt(this.windowContent.getStyle('paddingRight'));			
			
			var contentWidth = parseInt(contentDimensions.width);

			var cumulatedWidth = contentWidth + paddingLeft + paddingRight;

			if (cumulatedWidth != this.currentWidth) {
			
				if (!this.windowParams.overrideResizeEffects) {
					new Effect.ReSize(this.windowContainer, {
						direction:'hor',
						toSize: cumulatedWidth,
						duration: 0.3,
						transition: Effect.Transitions.sinoidal,
						afterFinish: params.afterFinish,
						afterFinishOptions: params
					});
				} else {

					this.windowContainer.setStyle({
						width: cumulatedWidth+'px'
					});

					if (typeof params.afterFinish == 'function') {
						params.afterFinish(params);
					}					
				}
				
				this.currentWidth = cumulatedWidth;
			} else {
				if (typeof params.afterFinish == 'function') {
					params.afterFinish(params);
					console.info(params)
				}					
			}
		},

		/**
		 * function refreshWindowHeight();
		 * Aktualisiert die H�he des Fensters anhand der H�he der Inhalte
		 *
		 * @params void
		 * @return void
		 */	
		refreshWindowHeight: function(params) {
			
			if (typeof params == 'undefined') {
				params = new Object();
			}
			
			if (typeof params.options != 'undefined' && typeof params.options.afterFinishOptions != 'undefined' ) {
				var contentHeight = parseInt(params.options.afterFinishOptions.height);
			} else {
				var contentDimensions = this.windowContentInner.getDimensions();
				var contentHeight = parseInt(contentDimensions.height);				
			}


			if (this.windowButtons.getStyle('display') != 'none') {
				var buttonsDimensions = this.windowButtons.getDimensions();
				var buttonsHeight = parseInt(buttonsDimensions.height);
			} else {
				var buttonsHeight = 0;
			}
			
			var paddingTop = parseInt(this.windowContent.getStyle('paddingTop'));
			var paddingBottom = parseInt(this.windowContent.getStyle('paddingBottom'));

			var cumulatedHeight = contentHeight + buttonsHeight;

			if (cumulatedHeight != this.currentHeight) {

				if (!this.windowParams.overrideResizeEffects) {
					new Effect.ReSize(this.windowContent, {
						direction:'vert',
						toSize: cumulatedHeight,
						duration: 0.3,
						transition: Effect.Transitions.sinoidal,
						afterFinish: (this._displayWindowContent).bind(this)
					});
				
				} else {
					this.windowContent.setStyle({
						height: cumulatedHeight+'px'
					});
				}
				this.currentHeight = cumulatedHeight;
			}
		},

		refreshWindowContent: function(params) {
			this.windowParams = Object.extend(this.windowParams, params);
			this._hideWindowContent();
			this._showWindowContent();
		},
		
		
		/**
		 * function getAjaxWindowContent();
		 * F�hrt einen Ajax-Request aus, um die Fensterinhalte nachzuladen
		 *
		 * @params void
		 * @return void
		 */			
		getAjaxWindowContent: function() {
//alert(this.windowParams.contentURL);			
			this.windowContentInner.ajaxUpdate(
				this.windowParams.contentURL, {
					method: "post",
					evalScripts: true,
					onComplete: this._proceedAjaxRequest.bind(this)
				}
			)
			
		},
		
		_proceedAjaxRequest: function(transport) {

			this.windowContentInner.setStyle({visibility: 'hidden'});
			this.windowContentInner.update('<div style="display: inline">'+transport.responseText+'</div>');
			var imgInAjaxContent = this.windowContentInner.select('img');
			var objectInAjaxContent = this.windowContentInner.select('object', 'iframe');

			// Zuerst auf Flash-Objects pr�fen
			if (objectInAjaxContent.length) {
				var objWidth = 0;
				var objHeight = 0;
				
				for (i=0; i<objectInAjaxContent.length; i++) {
					var obj = objectInAjaxContent[i];
					
					if (typeof obj.width != 'undefined' && obj.width > objWidth) {
						objWidth = obj.width;
						objHeight = obj.height;
					}
				}
				
				// Inhalte anzeigen
				this.refreshWindowDimensions({
					width: objWidth,
					height: objHeight
				});				
			} 
			// Dann auf Bilder pr�fen
			else if (imgInAjaxContent.length) {
				imgInAjaxContent.each(
					function (img) {
						Event.observe($(img), 'load', this._proceedAjaxRequestImageLoad.bindAsEventListener(this));
					},
					this
				)
			} 
			// Keins von beiden: Sofort anzeigen
			else {
				this._displayWindowContent();
				this.refreshWindowDimensions({
					refElement: this.windowContentInner.down()
				});
			}
			
		},
		
		_proceedAjaxRequestImageLoad: function(ev) {
			
			var img = Event.element(ev);
			
			this._displayWindowContent();

			this.refreshWindowDimensions({
				refElement: img
			});
		},
		
		_checkClosingClick: function(ev) {
			if (Event.element(ev).id == 'cmtModalWinWrapper') {
				cmtUI.overlayHandler.hideOverlay(this);
			}
		},
		
		isVisible: function() {
			return this.windowIsVisible;
		}
	}

/* ------------------------------------------------
	Tooltips: Start
   ------------------------------------------------ */
	/**
	 * function initTooltips();
	 * Initialisert die tooltips auf einer Seite
	 *
	 * @param void
	 * @return void
	 */
	cmtUI.tooltips = Class.create();
	
	cmtUI.tooltips.prototype = {
		initialize: function(params){
		
			this.params = Object.extend({
			}, params)

			//Event.observe(document, 'dom:loaded', this.initTooltips.bindAsEventListener(this));
			this.initTooltips()
		},
		
		initTooltips: function(event) {

			$$('.tooltip').each( function(el) {
					
				var idParts = el.className.split('_');
				var tooltipID = idParts[1];
	
				var element = $('tooltipContainer_'+tooltipID).remove();
				$(document.body).insert(element);
				$('tooltipContainer_'+tooltipID).hide();
				
				$(el).observe('mouseover', function (event) {
					
					var el = Event.element(event);
					var idParts = el.className.split('_');
					var tooltipID = idParts[1];
					
					var layoutTooltip =  Element.getLayout($('tooltipContainer_'+tooltipID))
					var tooltipWidth = layoutTooltip.get('width');

					var layoutLink =  Element.getLayout($(el))
					var linkWidth = layoutLink.get('width');
					
					$('tooltipContainer_'+tooltipID).show();
					$('tooltipContainer_'+tooltipID).setStyle({
						'left':  Event.pointerX(event) - tooltipWidth - linkWidth +'px',
						'top': Event.pointerY(event)+'px',
					});

					
				})

				$(el).observe('mouseout', function (event) {
					var el = $(Event.element(event));
					var idParts = el.className.split('_');
					var tooltipID = idParts[1];
					
					$('tooltipContainer_'+tooltipID).hide();
				})

			},
			this)
		}
		
	}
	
	// Globale "modalWindow" erzeugen
	Event.observe(document, 'dom:loaded', function(ev) {
		modalWindow = new cmtUI.modalWindow();
		tooltips = new cmtUI.tooltips();
	});

	
