window.addEvent('domready',function(){

	$$('.pers_image').setStyle('height','87px');

	// Hintergrundfarbe von Formularfeldern ändern
	$$('.ffield,.ftarea').each(function(el){
		el.addEvent('focus',function(){
			el.setStyle('backgroundColor', '#FFFBE5')
		});
		el.addEvent('blur',function(){
			el.setStyle('backgroundColor', '#FFF')
		});
	});

});



/*******************************************************************
	SLIDER
*******************************************************************/

// Slider abhängig vom Status anzeigen/ausblenden
function toggleSlider(objectId, heightTo)
{
	if ($(objectId).getStyle('display') == 'none') {
		// DIV öffnen
		animateSlider(objectId, 0, 1, heightTo);
	}
	else {
		// DIV schließen
		animateSlider(objectId, 1, 0, 0);
	}
}


// Status des Sliders verändern (animieren)
function animateSlider(objectId, opacityFrom, opacityTo, heightTo)
{
	var myEffects = new Fx.Styles(objectId , {duration: 500, transition: Fx.Transitions.linear});

	elFx = new Fx.Styles($('pers_image'), {duration: 500, transition: Fx.Transitions.linear});

	$(objectId).setStyle('display', 'block');

	// 'dyn': Höhe passt sich dem Inhalt an
	if (heightTo == 'dyn') {
		heightTo = $(objectId).scrollHeight;
	}
	// 'dyn+': Höhe passt sich dem Inhalt an + 20px
	if (heightTo == 'dyn+') {
		heightTo = $(objectId).scrollHeight;
		heightTo = heightTo + 20;
	}


	if (heightTo == '0') { // ausblenden
		myEffects.start({
			'opacity': [opacityFrom, opacityTo],
			'height': heightTo
		})
		.chain(function(){$(objectId).setStyle('display', 'none')})
		.addEvent('onComplete', function(){
			if ($(objectId + 'T')) {$(objectId + 'T').setHTML('<img src="/img/gfx/down.gif" />')}
		});


		elFx.start({
			'height':'87px'
		});

	}
	else { // einblenden
		myEffects.start({
			'opacity': [opacityFrom, opacityTo],
			'height': heightTo
		})
		.chain(function(){
			if ($(objectId + 'T')) {$(objectId + 'T').setHTML('<img src="/img/gfx/up.gif" />')}
		});


		elFx.start({
			'height':getNaturalHeight($('pers_image'))
		});

	}

}



//***** Originalgröße eines Bildes ermitteln *****//
function getNaturalHeight(img)
{
    if( img.naturalHeight ) {
        return img.naturalHeight;
    } else {
        lgi = new Image();
        lgi.src = img.src;
        return lgi.height;
    }
}


