var Accordion = new Class({

	Extends: Fx.Elements,

	options: {/*
		onActive: $empty,
		onBackground: $empty,*/
		/*display: $empty,*/
		//show: $empty,
		height: true,
		width: false,
		opacity: true,
		fixedHeight: false,
		fixedWidth: false,
		wait: false,
		alwaysHide: false
	},

	initialize: function(){
		var params = Array.link(arguments, {'container': Element.type, 'options': Object.type, 'togglers': $defined, 'elements': $defined});
		this.parent(params.elements, params.options);
		this.togglers = $$(params.togglers);
		this.container = $(params.container);
		this.previous = -1;
		if (this.options.alwaysHide) this.options.wait = true;
		if ($chk(this.options.show)){
			this.options.display = false;
			this.previous = this.options.show;
		}
		if (this.options.start){
			this.options.display = false;
			this.options.show = false;
		}
		this.effects = {};
		if (this.options.opacity) this.effects.opacity = 'fullOpacity';
		if (this.options.width) this.effects.width = this.options.fixedWidth ? 'fullWidth' : 'offsetWidth';
		if (this.options.height) this.effects.height = this.options.fixedHeight ? 'fullHeight' : 'scrollHeight';
		for (var i = 0, l = this.togglers.length; i < l; i++) this.addSection(this.togglers[i], this.elements[i]);
		this.elements.each(function(el, i){
			if (this.options.show === i){
				this.fireEvent('active', [this.togglers[i], el]);
			} else {
				for (var fx in this.effects) el.setStyle(fx, 0);
			}
		}, this);
		if ($chk(this.options.display)) this.display(this.options.display);
	},

	addSection: function(toggler, element, pos){
		toggler = $(toggler);
		element = $(element);
		var test = this.togglers.contains(toggler);
		var len = this.togglers.length;
		this.togglers.include(toggler);
		this.elements.include(element);
		if (len && (!test || pos)){
			pos = $pick(pos, len - 1);
			toggler.inject(this.togglers[pos], 'before');
			element.inject(toggler, 'after');
		} else if (this.container && !test){
			toggler.inject(this.container);
			element.inject(this.container);
		}
		var idx = this.togglers.indexOf(toggler);
		toggler.addEvent('click', this.display.bind(this, idx));
		if (this.options.height) element.setStyles({'padding-top': 0, 'border-top': 'none', 'padding-bottom': 0, 'border-bottom': 'none'});
		if (this.options.width) element.setStyles({'padding-left': 0, 'border-left': 'none', 'padding-right': 0, 'border-right': 'none'});
		element.fullOpacity = 1;
		if (this.options.fixedWidth) element.fullWidth = this.options.fixedWidth;
		if (this.options.fixedHeight) element.fullHeight = this.options.fixedHeight;
		element.setStyle('overflow', 'hidden');
		if (!test){
			for (var fx in this.effects) element.setStyle(fx, 0);
		}
		return this;
	},

	display: function(index){
		index = ($type(index) == 'element') ? this.elements.indexOf(index) : index;
		if ((this.timer && this.options.wait) || (index === this.previous && !this.options.alwaysHide)) return this;
		this.previous = index;
		var obj = {};
		this.elements.each(function(el, i){
			obj[i] = {};
			var hide = (i != index) || (this.options.alwaysHide && (el.offsetHeight > 0));
			this.fireEvent(hide ? 'background' : 'active', [this.togglers[i], el]);
			for (var fx in this.effects) obj[i][fx] = hide ? 0 : el[this.effects[fx]];
		}, this);
		return this.start(obj);
	}

});

var myAccordion;

window.addEvent('domready', function(){
	$$('.top-nav-box .top-navigation-content').each(function(el){
		if (el.hasClass('selected')){
			return;
		}
		el.set('morph',{
			duration:200
		});
		el.addEvents({
				mouseenter: function(){
					this.morph({
						'background-position': '0px 0px'
					});
				},
				mouseleave: function(){
					//alert(position);
					this.morph({
						'background-position': '0px 20px'
					});
				}
			});        
	});
	if (typeof index == 'undefined'){
		index = 0;
	}
	myAccordion = new Accordion($('accordion'), 'span.toggler', 'ul.content', {
		opacity: false,
		show: index || 0,
//        display: index,
		alwaysHide: true,
		onActive: function(toggler, element){
//            toggler.removeClass('active');
			toggler.setStyle('background-image', 'url(/media/public/sites/kvhh/css/img/minus_9x9.gif)');

		},
		onBackground: function(toggler, element){
//            toggler.addClass('active');
			toggler.setStyle('background-image', 'url(/media/public/sites/kvhh/css/img/plus_9x9.gif)');
		}
	});
	
//    $$('span.toggler').addEvent('mouseenter', function() { this.fireEvent('click'); });
	
	Galleries.start();    
	addCaps();
	fitColHeight();
	$$('input.search-field').each(function(element){
		new OverText(element);
	})

});
var ImageWindow = new Class({
	Implements:[Options],
	options:{
		'label':'&nbsp;'  
	},
	initialize: function(image, fromImage, options){
		this.image = $(image);
		this.fromImage = $(fromImage);
		this.boundDestroy = this.destroy.bind(this);
		this.boundDocClick = this.docClick.bind(this);
		this.buildWindow();
	},
	buildWindow: function() {
		this.window = new Element('div',{
			'styles':{
				'position':'absolute',
				'display':'none',
				'overflow':'hidden'
			},
			'class':'image-window'
		}).inject($(document.body));
		this.header = new Element('div',{
			'class':'image-window-header',
			'html':this.options.label,
			'events':{
				'click':this.boundDestroy  
			}
		}).inject(this.window);
		this.window.adopt(this.image);
	},
	show: function(){
		var from = this.fromImage.getCoordinates();
		this.window.setStyles({
			'left':from.left+'px',
			'top':from.top+'px',
			'width':from.width+'px',
			'height':from.height+'px',
			'display':'block',
			'opacity':0.1,
			'z-index':11000
		});
		this.image.setStyle('display','');
		var to = this.image.getDimensions();
		new Fx.Morph(this.window,{
			'onComplete':function() {
				document.addEvent('mousedown',this.boundDocClick);    
			}.bind(this)
		}).start({
			'width':[from.width,to.width+20],
			'height':[from.height,to.height+20],
			'left':[from.left, Math.max(20,from.left - Math.floor((to.width-from.width)/2))],
			'top':[from.top, Math.max(20,from.top - Math.floor((to.height-from.height)/2))],
			'opacity':[0.1,1]
		});
		
	},
	docClick: function() {
		this.header.fireEvent('click');
	},
	destroy: function() {
		//document.removeEvent('click',this.boundDocClick)
		this.window.set('tween',{
			'onComplete':(function() {
				this.image.setStyle('display','none').inject(document.body);
				this.window.destroy();
				
			}).bind(this)
		})
		this.window.fade('out');
	}
	
});
function showOrganigramm(){
	new ImageWindow('organigramm','organigramm-cont').show();
}
function showImage(target, source){
	//console.log(source, target);
	new ImageWindow(target,source).show();
}
function checkValue(item, command) {
	switch (command) {
		case 'focus':
			if (item.value == 'Passwort') {
				replaceInput(item,'password','',1);
			}
			break;
		case 'blur':
			if (item.value == '') {
				replaceInput(item,'text','Passwort',0);
			}
			break;
	}
}
function replaceInput(oldpass,type,value,focus){
	var newpass=document.createElement('input');
	newpass.setAttribute('type',type);
	newpass.setAttribute('name',oldpass.getAttribute('name'));
	newpass.setAttribute('id',oldpass.getAttribute('id'));
	switch(type){
		case 'password':
			newpass.setAttribute('style','color: #000;');
			break;
		case 'text':
			newpass.setAttribute('style','color: #666');
			break;
	}
	newpass.setAttribute('style',oldpass.getAttribute('style'));
	newpass.setAttribute('size',oldpass.getAttribute('size'));
	newpass.setAttribute('onfocus',oldpass.getAttribute('onfocus'));
	newpass.setAttribute('onblur',oldpass.getAttribute('onblur'));
	newpass.setAttribute('value',value);
	oldpass.parentNode.replaceChild(newpass,oldpass);
	if (focus == 1) {newpass.focus(); newpass.select();}
}
function fitColHeight() {
	var cols = $$('#col1','#col2','#col3');
	var height = 0;
	cols.each(function(col){
		var el = $(col);
		height = Math.max(height, el.clientHeight, el.offsetHeight);
	});
	if (!height){
		return;
	}
	cols.each(function(col){
		var h, id = col.get('id');
		if (id == 'col3') return;
		if (['col1','col2'].contains(id)){
			h = (height+15)+'px';
		}
		else {
			h = (height)+'px';
		}
		col.setStyle('height',h);
	});
};

var Galleries = {
	start: function() {
		$$('.mooflow').each(function(gallery){
			Galleries.init(gallery)
		});   
	},
	init: function(container){

		var mf = new MooFlow($(container), {
			startIndex: 0,
			useSlider: true,
			useAutoPlay: true,
			useCaption: true,
			useResize: true,
			useMouseWheel: true,
			useKeyInput: true,
			useViewer:true,
			onClickView: function(obj){
				var img = new Element('img',{src:obj.src, title:obj.title, alt:obj.alt, styles:obj.coords}).setStyles({'position':'absolute','border':'none'});
				var title = (obj.title || '')+(obj.title && obj.alt ? ' - ' : '')+(obj.alt || '');
				var link = new Element('a',{'class':'remooz-element','href':obj.href,'title':title, styles:{'border':'none'}});
				$(document.body).adopt(link.adopt(img));
				var remooz = new ReMooz(link, {
					centered: true,
					resizeFactor: 0.8,
					origin: link.getElement('img'),
					onCloseEnd: function(){link.destroy()}
				});
				remooz.open();
			}
		});
		
	}
	
};
OverText.implement({
	'test': function() {
		var v = this.element.get('value').trim();
		this[v ? 'hide' : 'show']();
		return !v;
	}
}); 

window.addEvent('domready',function() {
	var checkOver = function(element){
		if (!Browser.Engine.trident4){
			return element.scrollWidth > element.clientWidth;    
		}
		else {
			return true;
		}
	}
	addCaps();
	if (Browser.Engine.trident){
		$$('.arztsuche-form-content select').each(function(select) {
			//alert(select.clientWidth+'-'+select.scrollWidth);
			var over = checkOver(select);
			if (!over){
				return;
			}
			var parent = select.getParent();  
			if (Browser.Engine.trident4){
				parent.setStyles({
				   'position':'relative',
				   'height':'21px',
				   'display':'inline-block',
				   'width': '266px',
				   'overflow':'hidden'
				   //'border-left':'2px solid #000'
				});
				var inStyle = {
					'position':'absolute',
					'width':'auto',
					'right':'0'
				}
				var outStyle= {
					'position':'',
					'width':'266px'
				}
				select.addEvents({
					'mouseenter':function(){select.setStyles(inStyle)},
					'mouseleave':function(event) {
						if (window.event.toElement) {
							select.setStyles(outStyle);
							return;
						}
					},
					'blur':function(){select.setStyles(outStyle)},
					'change':function(){select.setStyles(outStyle)}
				});
				/*
				select.addEvent('mouseenter',function(event) {
					select.setStyles({
						'position':'absolute',
						'width':'auto',
						'right':'0'
					});
				})
				select.addEvent('mouseout',function(event) {
					if (window.event.toElement) {
						select.setStyles(outStyle);
						return;
					}
				})
				select.addEvent('change',function(event) {
					select.setStyles(outStyle);
				})
				*/
			}
			else{
				parent.setStyles({
				   'position':'relative',
				   'height':'21px',
				   'display':'inline-block',
				   'width': '266px',
				   'overflow':'hidden'
				   //'border-left':'2px solid #000'
				});
				select.setStyles({
					//'position':'absolute',
					'right':'0',
					'width':'266px'
				});
				select.attachEvent('onfocusin',function() {
					select.setStyles({
						'position':'absolute',
						'width':'auto'
					});
					parent.setStyle('border-left','2px solid #000');
				})
				select.attachEvent('onfocusout',function() {
					select.setStyles({
						'position':'',
						'width':'266px'
					});
					parent.setStyle('border-left','');
				})
			}
			/*
			if (Browser.Engine.trident4){
				parent.setStyle('border','1px solid #000');
				select.setStyle('border','0 none');
			}
			*/
		});
		
	}
	return;
	var select = $('ffachgebiet');
	if (!select){
		return;
	}
	var str = '';
	var parent = select.getParent();
	
	parent.setStyles({
	   'position':'relative',
	   'height':'22px',
	   'border':'1px solid red',
	   'display':'inline-block',
	   'width': '263px',
	   'overflow':'hidden'
	});
	select.setStyles({
		'position':'absolute',
		'right':0,
		'width':'auto'
	});
	return;
	var width = select.getStyle('width');
	select.addEvents({
		'click':function(){
			select.setStyles({
				'position':'absolute',
				'left':select.offsetLeft,
				'width':'auto'
				//'left':(offset.x)+'px',
				//'top':offset.y+'px',
			});
			select.click();
		},
		'blur': function() {
			select.setStyles({
				'position':'static',
				'left':'auto',
				'width':width
				//'left':(offset.x)+'px',
				//'top':offset.y+'px',
			});
		}
	})
	//console.log(offset);
})

if (!String.prototype.padLeft){
	String.implement({
		padLeft: function(len, c){
			var val = this, len = len || 0, c = c || '0';
			if (val.length >= len){
				return val;
			}
			for (var i = 0, l = len - val.length; i<l; i++){
				val = c + val;
			}
			return val;
		}
	})
}
var ToolTickerbox = new Class({
	Implements: [Options],
	options:{
		
	},
	initialize: function(options) {
		this.setOptions(options);
		if (this.options.counter){
			this.setupCounter();
			this.attachCounter();
		}
		if (this.options.ticker){
			this.setupTicker();
			this.startTicker();
		}
	},
	setupCounter: function() {
		var endDate;
		if (matches = this.options.counter.end.match(/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/)) {
			//SQL Date
			endDate = new Date(
				matches[1].toInt(),
				matches[2].toInt()-1,
				matches[3].toInt(),
				matches[4].toInt(),
				matches[5].toInt(),
				matches[6].toInt()
			);
		}
		else {
			endDate = Date.parse(this.options.counter.end);
		}
		if (!endDate) {
			return;
		}
		this.endTime = (endDate.getTime() / 1000).toInt();
		this.counterElement = this.options.counter.element || $(this.options.box).getElement('.counter');
		this.msMinutes = 60;
		this.msHours = this.msMinutes * 60;
		this.msDays = this.msHours * 24;
	},
	attachCounter: function() {
		this.setCounter();
		this.counterTimer = this.setCounter.periodical(1000,this); 
	},
	detachCounter: function() {
		$clear(this.counterTimer);
	},
	setCounter: function() {
		var now = ($time() / 1000).toInt();
		if (this.endTime <= now){
			this.renderCounter(0,0,0,0);
			this.detachCounter();
			return;
		}
		var diff = this.endTime - now, remaining;
		var days = Math.floor(diff / this.msDays); remaining = diff - days * this.msDays;
		var hours = Math.floor(remaining / this.msHours); remaining = remaining - hours * this.msHours;
		var minutes = Math.floor(remaining / this.msMinutes); remaining = remaining - minutes * this.msMinutes;
		var seconds = Math.floor(remaining);
		this.renderCounter(days, hours, minutes, seconds);
	},
	renderCounter: function(days, hours, minutes, seconds){
		if (!this.counterElement){
			return;
		}
		var params = {
			'days': days || 0,
			'hours': ((hours || 0)+'').padLeft(2,'0'),
			'minutes': ((minutes || 0)+'').padLeft(2,'0'),
			'seconds': ((seconds || 0)+'').padLeft(2,'0')
		};
		var template = this.options.template || '{days} Tage {hours}:{minutes}:{seconds}';
		this.counterElement.set('html',template.substitute(params));
	},
	setupTicker: function(){
		this.tickerTextElement = this.options.tickerTextElement || $(this.options.box).getElement('.ticker-text');
		this.tickerContainerElement = this.options.tickerContainerElement || $(this.options.box).getElement('.ticker-container');
		this.tickerWidth = this.tickerTextElement.offsetWidth;
		this.tickerInitialLeft = this.tickerContainerElement.getStyle('width').toInt();
		this.tickerLeft = this.tickerInitialLeft;
		this.tickerStep = this.options.ticker.step || 1;
		this.tickerSpeed = this.options.ticker.speed || 50;
		if (Browser.Engine.trident && Browser.Engine.Version <= 4){
			var styles = this.tickerContainerElement.getStyles('border-left-width','border-right-width','padding-left','padding-right');
			var offset = 0, parentElement = this.tickerContainerElement.getParent();
			offset += (styles['border-left-width'] || 0).toInt();
			offset += (styles['border-right-width'] || 0).toInt();
			offset += (styles['padding-left'] || 0).toInt();
			offset += (styles['padding-right'] || 0).toInt();
			parentElement.setStyle('width',(parentElement.getStyle('width').toInt()-offset)+'px');
			alert((parentElement.getStyle('width').toInt()-offset)+'px')
		}
	},
	startTicker: function() {
		this.tickerTextElement.setStyle('left',this.tickerInitialLeft);
		this.tickerLeft = this.tickerInitialLeft;
		this.tickerTimer = this.setTicker.periodical(this.tickerSpeed,this);
	},
	stopTicker: function() {
		$clear(this.tickerTimer);
		this.tickerTextElement.setStyle('left',0);
	},
	setTicker: function(){
		this.tickerLeft -= this.tickerStep;
		if (this.tickerWidth + this.tickerLeft <=0){
			this.tickerLeft = this.tickerInitialLeft;
		}
		this.tickerTextElement.setStyle('left',this.tickerLeft);
	}
});

function addCaption( oImgElem, bUseCaptionMarker )
{
  // Check that image element not already have a div.imgblock as parent.
  if( oImgElem.parentNode && oImgElem.parentNode.className=="imgblock")
	return;
	
  // Create the div.imgblock element      
  var oImgBlockElem = document.createElement("div");
  oImgBlockElem.className = "imgblock";
  if( Browser.Engine.trident )
  {
	oImgBlockElem.style.styleFloat = oImgElem.align;
  }
  else
  {
	oImgBlockElem.style.cssFloat = oImgElem.align;
  }

  oImgElem.removeAttribute('align');
  
  if ( oImgElem.style.marginTop != null )
  {
	oImgBlockElem.style.marginTop = oImgElem.style.marginTop;
	oImgElem.style.marginTop = null;
  }
  
  if ( oImgElem.style.marginRight != null )
  {
	oImgBlockElem.style.marginRight = oImgElem.style.marginRight;
	oImgElem.style.marginRight = null;
  }

  if ( oImgElem.style.marginBottom != null )
  {
	oImgBlockElem.style.marginBottom = oImgElem.style.marginBottom;
	oImgElem.style.marginBottom = null;
  }

  if ( oImgElem.style.marginLeft != null )
  {
	oImgBlockElem.style.marginLeft = oImgElem.style.marginLeft;
	oImgElem.style.marginLeft = null;
  }
  
  
  
//  oImgElem.style.styleFloat = "none";

  if( oImgElem.className.search("leftjust") >= 0 )
  {
	oImgBlockElem.className = oImgBlockElem.className + " leftjust";
	oImgElem.className = oImgElem.className.replace("leftjust","");
  }
  if( oImgElem.className.search("rightjust") >= 0 )
  {
	oImgBlockElem.className = oImgBlockElem.className + " rightjust"; 
	oImgElem.className = oImgElem.className.replace("rightjust","");
  }


  var oHandle = oImgElem;  // oHandle is element that should be moved into our div.imgblock element

  // If the current image has a parent A (anchor/hyperlink) element then
  // we would also like that to go into our div.imgblock, therefore the oHandle
  // is adjusted to point to the A element.
  if( oImgElem.parentNode.tagName == "A" )
  {
	oHandle = oImgElem.parentNode;
  }

  //  alert("Before for '" + oImgElem.alt + "'");
  // Replace the oHandle node (the img or a) with our new div.imgblock element.
  var oOldHandle = oHandle.parentNode.replaceChild(oImgBlockElem,oHandle);  // This line sometimes crash in IE with error R6025!
  
  if( false ) //bUsePhotoShadow )
  {
	var oPhotoShadowElem = document.createElement("div");
	oPhotoShadowElem.className = "photoshadow";
  
	oImgBlockElem.appendChild(oPhotoShadowElem);
	oPhotoShadowElem.appendChild(oOldHandle);
  }
  else
  {
	oImgBlockElem.appendChild(oOldHandle);
  }
  //oImgBlockElem.appendChild(oOldHandle);
  oHandle=null;
  //  alert("After for '" + oImgElem.alt + "'");


  // Create div.caption element
  var oCaptionElem = document.createElement("div");
  oCaptionElem.className = "caption";
  oCaptionElem.style.marginLeft = oImgElem.style.marginLeft;

  if( bUseCaptionMarker)
  {
	// Create div.caption-marker element
	var oCaptionMarkerElem = document.createElement("div");
	oCaptionMarkerElem.className = "caption-marker";
	var oCaptionMarkerTextElem = document.createTextNode("\u00bb");
	oCaptionMarkerElem.appendChild(oCaptionMarkerTextElem);
	oCaptionElem.appendChild(oCaptionMarkerElem );
  }

  // Create div.caption-text element with appropriate alt text
  var oCaptionTextElem = document.createElement("div");
  oCaptionTextElem.className = "caption-text";
//  var oCaptionText = document.createTextNode( oImgElem.alt );
  var oCaptionText = document.createTextNode( oImgElem.title );
  oCaptionTextElem.appendChild(oCaptionText );
  oCaptionElem.appendChild(oCaptionTextElem);

  // Check whether copyright element should be handled...
  if( oImgElem.getAttribute("alt") != "" )
  {
	// Create div.copyright element with appropriate bolded text according to | delimiter (if any)...
	var oCopyrightElem = document.createElement("div");
	oCopyrightElem.className = "copyright";
	//var oCopyrightText = document.createTextNode( oImgElem.getAttribute("copyright") );
	var oCopyrightText = document.createElement("span");
	// Convert all texts before a possible '|' character into a bold-face...
//    ostr = oImgElem.getAttribute("copyright").replace(new RegExp("[^|]* |"),"<b>$&</b>");
//    ostr = oImgElem.getAttribute("alt").replace(new RegExp("[^|]* |"),"<b>$&</b>");
	ostr = "&copy; " + oImgElem.getAttribute("alt");
	oCopyrightText.innerHTML = ostr;
	oCopyrightElem.appendChild(oCopyrightText);
	oCaptionElem.appendChild(oCopyrightElem );
  }

  if( oImgElem.getAttribute("camera") != null )
  {
	// Adds extra <div class="exif"><span>...</span></div> with ... replaced with camera, lens and settings attribute texts.
	var oExifElem = document.createElement("div");
	oExifElem.className = "exif";
	var oExifText = document.createElement("span");
	oExifText.innerHTML = oImgElem.getAttribute("camera") + ", " + oImgElem.getAttribute("lens") + "<br/>" + oImgElem.getAttribute("settings");
	
	oExifElem.appendChild(oExifText);
	oCaptionElem.appendChild(oExifElem);
	
	/* Adds extra <div class="exif2"><span>...</span></div>
	if( oImgElem.getAttribute("settings") != null )
	{
	  var oExifSettingsElem = document.createElement("div");
	  oExifSettingsElem.className = "exif2";
	  var oExifSettingsText = document.createElement("span");
	  oExifSettingsText.innerHTML = oImgElem.getAttribute("settings");
	  oExifSettingsElem.appendChild(oExifSettingsText);
	  oCaptionElem.appendChild(oExifSettingsElem);
	}
	*/
  }
  
  //if( oImgElem.getAttribute("exif") != null )
  if( oImgElem.className.search("addexifcap") >= 0 )
  {
	// Adds extra <div class="exif"><span>...</span></div> with ... replaced with camera, lens and settings attribute texts.
	var oExifElem = document.createElement("div");
	oExifElem.className = "exif";
	var oExifText = document.createElement("span");
	oExifText.innerHTML = EXIF.getTag(oImgElem, "Model") + ", " +  
	  EXIF.getTag(oImgElem, "FocalLength") + "mm, f/" + 
	  EXIF.getTag(oImgElem, "FNumber") + ", 1/" + 
	  1/EXIF.getTag(oImgElem, "ExposureTime") + "s, " + 
	  "ISO " + EXIF.getTag(oImgElem, "ISOSpeedRatings");
	
	
	oExifElem.appendChild(oExifText);
	oCaptionElem.appendChild(oExifElem);
  }

  oImgBlockElem.appendChild(oCaptionElem);

  //return true;
	
  with(oImgElem.style)
  {
	oCaptionElem.style.width = (oImgElem.scrollWidth)+"px";
  }
  oImgBlockElem.style.width = (oImgElem.scrollWidth)+"px";

  return true; 
}


function addCaps()
{
  var i=0;
  var oImages = document.images; //document.getElementsByTagName("img"); // document.images
  var oImg;
//  alert("inside addCaps() - " + oImages.length );
  for( i=0; i<oImages.length; i++ )
  {
	oImg = document.images[i];
//    alert("oImg.className = " + oImg.className);
	if( oImg.src.indexOf('wysiwygPro') == -1 && oImg.title != "" || oImg.src.indexOf('wysiwygPro') == -1 && oImg.alt != "")
	{
		if( oImg.className.search("addCaps") >= 0 )
		{
		  addCaption(oImg,false);
		}
	}else{
		oImg.className = "";
	}
  }

  return true;
}
function fitColumnHeight() {
	var tallestcolumn = 0, columns = jQuery('div.fap-row.has-equal-columns > div.fap-col');
	columns.height('');	
	columns.each(
		function() {
			currentHeight = jQuery(this).height();
			if (currentHeight > tallestcolumn) {
				tallestcolumn = currentHeight;
			}
		}
	);
	columns.height(tallestcolumn);
}
jQuery(function() {
	fitColumnHeight();
});
jQuery.tools.overlay.addEffect("load",
	function(position, done) {
		var trigger = this.getTrigger(),wrap = this.getOverlay().find('.overlay-content'), conf = this.getConf(), overlay = this.getOverlay(),
			self = this, href = trigger.attr('data-href'), url = trigger.attr('data-url') || window.location.href, lang = trigger.attr('data-lang');
		function bindClose() {
			wrap.find('.close').click(function() {
				self.close();
			})
		}
		var style = trigger.attr('data-style');
		if (style){
			wrap.attr('style',style);
		}
		wrap.load(href+'?lang='+lang+'&url='+escape(url), function() {
			position.top = jQuery(window).scrollTop()+50;
			overlay.css(position).fadeIn(conf.speed, done)
			bindClose();
			var form = wrap.find('form');
			form.validator({
				lang: lang
			});
			wrap.find('.submit').click(function(event) {
				if (form.data('validator').checkValidity()) {
					jQuery('<input type="hidden" name="url" value="'+document.location.href+'" />').appendTo(form);
					jQuery.ajax({
						type: 'POST',
						url: href,
						data:form.serialize(),
						success: function(content){
							wrap.html(content);
							bindClose();
						}
					})
				}
			});
		});
},
	function(done){
		this.getOverlay().fadeOut(this.getConf().closeSpeed, done);
	}
);
jQuery.tools.validator.localize('de',{
	':email'          : 'keine g&uuml;ltige E-Mail',
	':number'         : 'keine g&uuml;ltige Zahl',
	'[max]'             : 'maximal $1',
	'[min]'             : 'mindestens $1',
	'[required]'     : 'erforderlich'
});
jQuery(function($){
	$('.overlay-load-trigger').overlay({
		effect: 'load',
		mask: {
			color: '#000',
			opacity: 0.7
		},
		fixed: true,
		onClose: function() {
			$('.error').remove();
		}
	})
});
