// JavaScript Document
window.addEvent('domready', function(){

	$$('.reiseBlockContent').setStyle('display', 'block');
	$$('.echoArea').setStyle('display', 'block');
	$$('.echoEntry').setStyle('display', 'block');

//REIESE INHALT SLIDER//

	function hideDetail(div){
		div.set('text','Mehr Informationen');
		div.removeClass('opened');
		div.reiseEntry.removeClass('reiseEntryBg');
		if(div.hasClass('noEcho')) {
			div.removeClass('noEcho');
		}
	}
	function showDetail(div, emptyEcho){
		div.echo.setStyle('display', 'block');
		div.set('text','Weniger Informationen');
		div.addClass('opened');
		div.reiseEntry.addClass('reiseEntryBg');
		if(emptyEcho == true) {
			div.reiseEntry.setStyles({
				'background-image': 'url("/gbt_img/bg_reiseBlock.gif")',
				'background-repeat': 'repeat-y'
			});
			div.addClass('noEcho');
		}		
	}

	var nGroups = $$('div.mehrInfoLink');

	nGroups.each(function(div){
		var block = div.getPrevious().getElement('.reiseBlockContent');
		var imgBlock = div.getPrevious().getElement('.echoArea');
		var reiseEntry = div.getPrevious();
		//alert(imgBlock.getProperty('class'));
		div.reiseEntry = reiseEntry;
		div.echo = imgBlock;

		//check ob Echo Element gibt
		var emptyEcho = false;
		if(imgBlock.hasClass('emptyEcho') == true) {
			emptyEcho = true;
		}

		var fx = new Fx.Slide(block);
		var fxImg = new Fx.Slide(imgBlock);
	
		
		fx.hide();
		fxImg.hide();
		hideDetail(div);
		

		div.addEvent('click', function(){
			fx.toggle();
			fxImg.toggle();
			if((this.get('text')).indexOf('Weniger') > -1) {
				hideDetail(this);
			} else {
				showDetail(this, emptyEcho);
			}
		});
	});
	
//ECHO SLIDER//

	
	var reiseEntry = $$('div.reiseEntry');
	var echos = $$('div.echoEntry');
		
	echos.each(function(div){
		var textFull = div.get('text');
		var textLength = textFull.length;
		if(textLength > 85) {
			
			div.introText = textFull.substr(0, 80) + ' ...<span class="spacer"></span>';
			//div.Lead = textFull.substr(0, 85);
			
			div.set('html', '<div class="echoShort openEcho">'+div.introText + '</div>', '<div class="echoLong">'+ textFull+'<span class="spacer"></span></div>');
			var fxEchoLong = new Fx.Slide(div.getElement('.echoLong'));
			fxEchoLong.hide();
			div.fxLong = fxEchoLong;
			
		}
		div.addEvent('click', function(){
			var echoBlock = div.getParent();
			var echoBlockFx = new Fx.Slide(echoBlock);
			
			if(div.getElement('.echoShort')) {	
				echos.each(function(div2){
									
					if(div2.hasClass('openedEcho')==1 && div2 != div) {
						if(div2.getParent() == div.getParent()) {
							div2.fxLong.slideOut().hide();
							div2.getElement('.echoShort').setStyle('display', 'block');
							div2.removeClass('openedEcho');
						} 
					}
				});
				if(div.fxLong.open == false) {	
					div.fxLong.slideIn();
					//div.getElement('.echoShort').set('text', div.Lead);
					div.getElement('.echoShort').setStyle('display', 'none');
					div.getElement('.echoShort').removeClass('openEcho');
					div.addClass('openedEcho');
				} else {
					div.fxLong.slideOut().hide();
					//div.getElement('.echoShort').set('text', div.introText);
					div.getElement('.echoShort').setStyle('display', 'block');
					div.getElement('.echoShort').addClass('openEcho');
					div.removeClass('openedEcho');
				}
				echoBlockFx.slideIn(); //to adjust the height of Echo
			}
		});
	});
});