$(window).addEvent('domready', function() {
	if($('form-suche')) {
		$('form-suche').getElement('input').addEvents({
			'focus': function() {
				if(!this.retrieve('value')) {
					this.store('value', this.get('value'));
				}
				if(this.get('value') == this.retrieve('value')) {
					this.set('value', '');
				}
			},
			'blur': function() {
				if(this.get('value') == '') {
					this.set('value', this.retrieve('value'));
				}
			}
		});
	}
	if($$('#content .hotel_detail .left .more_images a') && $$('#content .hotel_detail .left .more_images a').length > 0) {
		$$('#content .hotel_detail .left .more_images a').addEvent('click', function(event) {
			event.stop();
			showLargeImage(this, $$('.main_image_container').getLast());
		});
	}
	
	if($$('.mod_weather_info .ce_weather') && $$('.mod_weather_info .ce_weather').length > 0) {
		ce_slideshow($$('.mod_weather_info').getLast(), 'div', 4000);
	}
});

function showLargeImage(el, container) {
	var new_el_wrapper = new Element('a', {
		'href': el.getElement('img').get('alt'),
		'rel': 'lightbox'
	});
	var new_el = new Asset.image(el.get('href'), {
		onload: function() {
			this.fade(1);
			container.getElement('img').fade(0);
			(function(cimg){cimg.destroy();}).delay(1000, this, container.getElement('a'));
		}
	});
	new_el.fade('hide');
	new_el.inject(new_el_wrapper);
	new_el_wrapper.inject(container, 'bottom');
	new_el_wrapper.slimbox({}, null, true);

}

function ce_slideshow(container, type, length) {
	var length = length ? length : 4000 ;
	var elements = container.getElements(type);
	var elementcount = elements.length - 1;
	var visible = 0;
	elements.fade('hide');
	elements[visible].fade('show');
	
	var fader = (function(){
		var oldvisible = visible;
		if(visible == elementcount) {
			visible = 0;
		} else {
			visible = visible + 1;
		}
		elements[oldvisible].fade(0);
		elements[visible].fade(1);
	}).periodical(length);
}
