// usage: log('inside coolFunc',this,arguments);
// http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
	log.history = log.history || [];   // store logs to an array for reference
	log.history.push(arguments);
	if(this.console){
		console.log( arguments );
	}
};

$(function()
{
	/*
		Übersetzung
	*/
	var elems = $('#wrapper').find('span, a, p, h1, h2, h3, h4, h5, label, button, li, div.title');
	
	elems.each(function(index)
	{
		var check = $(this).text().indexOf('(EN)');

		if ( check > -1 )
		{
			$(this).attr('style', 'color:red !important');
		}
		
		if ( $(this).attr('title') )
		{
			var check2 = $(this).attr('title').indexOf('(EN)');

			if ( check2 > -1 )
			{
				$(this).attr('style', 'background:red !important; border:1px red solid !important;');
			}
		}
	});
	
	
	/*
		Feedback-Popup:
		- occurs once per user
		- otherwise the feedback button is shown directly
	*/
	function fh_feedback_popup() {
		
		function show_feedback_button(feedback_button) {
			// move the button from the overlay to the 'normal' DOM
			feedback_button.appendTo('body').addClass('s-fixed');
			
			return true;
		}

		// the information, that the overlay was shown is stored within local storage
		Modernizr.load(
		{
			test: Modernizr.localstorage,
			nope: 'javascripts/remy_sharp_storage_polyfill.js',
			complete: function ()
			{
				// nothing to do, if overlay was already shown to user
				var overlay_already_shown 	= ( sessionStorage.getItem('overlay_shown') === 'true'),
					overlay_elem 			= $('#fee'),
					overlay_test_modus		= overlay_elem.is('.s-test'),
					feedback_button			= overlay_elem.find('.fee-go-go-go');

				if ( overlay_already_shown && ! overlay_test_modus )
				{
					// overlay has already been shown, just show the feedback button
					show_feedback_button(feedback_button);
					
					return false;
				}
				
				// the feedback button shouldn't be functional, if the overlay is shown
				var feedback_button_href = feedback_button.attr('href');
				feedback_button.removeAttr('href');
				
				overlay_elem.overlay({

					top: 260,

					mask: {

						color: '#000',

						loadSpeed: 200,

						opacity: 0.5
					},

					// disable this for modal dialog-type of overlays
					closeOnClick: false,

					// load it immediately after the construction
					load: true,
					
					onLoad: function() {
						
						var overlay_api = this,
							overlay		= overlay_api.getOverlay();

						$('.fee-close').click(function()
						{
							// store the information within local storage
							if ( ! overlay_test_modus )
							{
								sessionStorage.setItem('overlay_shown', true);
							}
							else
							{
								sessionStorage.removeItem('overlay_shown');
							}
							
							// animate the feedback button
							var overlay_pos = overlay.position();
			
							// close the overlay
							overlay_api.close();
							
							// make the feedback button functional again
							feedback_button.attr('href', feedback_button_href);
							
							return show_feedback_button(feedback_button);
							
							// var navi_height	= $('#header_1').height() + $('#header_2').height() + 10,
							// 
							// 	// we need to push the button horizontal using:
							// 	// the left position plus the padding of the overlay
							// 	top_pos 	= (~~overlay_pos.top - navi_height);
							// 
							// 	// we need to push the button vertical using:
							// 	// the top position of the overlay minus the height ot the two headers
							// 	left_pos 	= (~~overlay_pos.left + 10);
							// 
							// console.log(navi_height);
							// console.log(top_pos);
							// console.log(left_pos);
							// 
							// feedback_button.animate({
							// 	left: '+=' + left_pos,
							// 	top: '-='+ top_pos,
							// },
							// 2000,
							// function()
							// {
							// 	// return false;
							// 	console.log($(this));
							// 	
							// 	// close the overlay
							// 	overlay_api.close();
							// 	
							// 	// show the feedback button
							// 	overlay.addClass('s-fixed');
							// 	// $(this).show();
							// 
							// });
							// 
							// return false;
						});

						// $('.fee-close').click();
					}
				});
			}
		});

	}
	// fh_feedback_popup();
	
	
	/*
		Footer-Navigation: highlight links with hash targets/uris
	*/
	if ( window.location.hash )
	{
		var sel = "#footer-nav a[href*="+window.location.hash+"]";

		$(sel).addClass('current');
	}
	
	
	/*
		Suche
	*/
	var search_keyword = $('body#search_results span.keyword').text();
	
	if ( search_keyword.length )
	{
		var targets = $('span.excerpt, span.title');
		
		if ( targets.length )
		{
			var pattern = new RegExp('(' + search_keyword + ')', 'ig');
			
			var replacement = '<span class="keyword">$1</span>';
			
			targets.each(function()
			{
				var content = $(this).html();
				
				if ( pattern.test(content) )
				{
					var new_content = content.replace(pattern, replacement);
					$(this).html(new_content);
				}
			});
		}
	}
	
	
	/*
		Overlays / Popups
	*/
	$('a.overlay').each(function()
	{
		$(this).attr('rel', '#overlay');
		
		$(this).overlay(
		{
			mask: '#000',

			onBeforeLoad: function() {

				// grab wrapper element inside content
				var wrap = this.getOverlay().find(".contentWrap");

				// load the page specified in the trigger
				wrap.html('<img src="'+this.getTrigger().attr("href")+'" alt=""/>');
			}
		});
		
	});
	
	
	/*
		room filter @ /meet
	*/
	var items_to_filter_wrapper = $('#roomList');
	var items_to_filter = items_to_filter_wrapper.find('> div.item');
	
	if ( items_to_filter.length > 1 )
	{
		function set_z_indexes()
		{
			var z_index = 100;
			items_to_filter.each(function()
			{
				$(this).css('z-index', z_index);
				z_index--;
				
				// $(this).toggleClass('full');
				// $(this).data()
			});
		}
		
		function set_max_capacities()
		{
			items_to_filter.each(function()
			{
				if ( $(this).data('max') )
				{
					return;
				}
				
				var capacities = $(this).attr('data-capacity');
				capacities = capacities.split('|');
				
				var max = 0;
				
				$.each(capacities, function(index, value)
				{
					value = ~~value;
					
					if ( value > max)
					{
						max = value;
					}
				});
				
				$(this).data('max', ~~max);

			});
			
			items_to_filter_wrapper.data('max_capacities_set', true);
		}
		
		function filter_rooms(filter_type)
		{
			var filter_trigger = $('#' + filter_type);

			filter_trigger.change(function()
			{
				shown_items = items_to_filter.filter(':hidden');
				
				var selected = $(this).val();
				
				var data_field = 'data-'+filter_type;

				var selector = '['+data_field+'*="'+selected+'"]';
				
				// valid rooms
				var hits = items_to_filter.filter(selector);
				
				// filtered out rooms
				var blanks = shown_items.not(selector);
				
				/*
					the capacity filter need some more magic:
					- 
				*/
				if ( filter_type == 'capacity' )
				{
					// cast int
					selected = ~~selected;
					
					if ( ! items_to_filter_wrapper.data('max_capacities_set') )
					{
						set_max_capacities();
					}
					
					// take each rooms max capacity and compare it to the selected capacity
					hits = items_to_filter.filter(function()
					{
						return ($(this).data('max') >= selected);
					});
					
					blanks = items_to_filter.filter(function()
					{
						too_small = ( $(this).data('max') < selected );
						
						return too_small;
					});
				}

				// hide the filtered out items
				blanks.each(function()
				{
					$(this).fadeOut();
				});

				// show the "good ones"
				hits.each(function()
				{
					$(this).fadeIn();
				});

				// bind the used filter to the room wrapper data field
				items_to_filter_wrapper.data('filter_type', filter_type);
			});
			
			filter_trigger.show();
		}
		
		var filter_types = Array(
			// 'seating',
			'capacity'
		);
		
		$.each(filter_types, function()
		{
			filter_rooms(this);
		});
		
		function set_heights()
		{
			var old_height = 116;
			var new_height = 0;
			
			items_to_filter.each(function()
			{
				h = $(this).find('.inner').height();
				h2 = $(this).find('h3').outerHeight(true);
				h3 = $(this).find('p.area').outerHeight(true);
				h4 = $(this).find('p.capacity').outerHeight(true);
				
				total_height = h2+h3+h4;
				
				if ( total_height > new_height)
				{
					new_height = total_height;
				}
			});
			
			if ( new_height > old_height)
			{
				items_to_filter.find('.inner').css('height', new_height);
			}
		}
		
		set_max_capacities();
		set_z_indexes();
		set_heights();
		
		// $('#capacity').change();
	}
	
	/*
		image galleries on the gallery detail page
	*/
	var _scrollable = $('#galleryBody > .scrollable');
	var images = $('#galleryBody > .scrollable > .image_container > div > img');
	
	if ( _scrollable.length && ( images.length > 1 ) )
	{
		_scrollable.scrollable(
		{
			mousewheel: 	false,
			next: 			'.next > a',
			prev: 			'.prev > a'
		})
		.navigator(
		{
			navi: "span.navigator",
			
			indexed: true,

			naviItem: 'span'
		});
		
		var api = _scrollable.data('scrollable');
		
		/*
			total images
		*/
		var navi = api.getNaviButtons().first();

		if ( navi.length )
		{
			var total_container = navi.siblings('.total');
			var last = navi.find('span').last();
			
			var total = last.text();
			total_container.find('span').text(total);
			
			navi.show();
		}
		
		/*
			navigation buttons
		*/
		var navigation_buttons = api.getNaviButtons().filter('a');
		
		navigation_buttons.parents('li').show();
		
		/*
			seek to active image, if given
		*/
		var active_image = images.filter('.current').first(),
			pos = images.index(active_image);
		
		if ( active_image.length )
		{
			api.seekTo(pos, 0);
		}
	}
	

	/*
		even the height of inline boxes with different heights
	*/
	var boxes = [
		$('#testimonials, #facts, #shortcuts')
		// ,$('#special, #contactInfo')
	];
	
	$.each(boxes, function(index, val)
	{
		if ( val.length )
		{
			even_box_heights(val);
		}
	});
	
	function even_box_heights(boxes)
	{
		var old_height = 0;
		var new_height = 0;
		
		boxes.each(function()
		{
			h = $(this).outerHeight(true);
			
			if ( h > new_height)
			{
				new_height = h;
			}
			// $(this).toggleClass('full');
			// $(this).data()
		});
		
		if ( new_height > old_height)
		{
			boxes.each(function(index)
			{
				diff = $(this).outerHeight() - $(this).height();

				if (diff > 0)
				{
					$(this).css('height', new_height-diff);
				}
				else
				{
					$(this).css('height', new_height);
				}
			});
		}
	}
	
	
	/*
		select #flowplanes and make it scrollable. use circular and navigator plugins
	*/	
	init_sliders();
	function init_sliders()
	{
		if ( $('.flowpanes').length )
		{
			$('.flowpanes').each(function(i)
			{
				var text_container = $(this).find('.text_container');

				var got_hidden_texts = ( $(this).find('> .items .text').length > 0 ) && ( text_container.length );
				
				var is_listslider = ( $(this).parents('.listslider_wrapper').length == 1 );
				
				/*
					if one of the boxes has too much content for the fixed heights,
					we need to detect the correct size and adapt the other boxes
				*/
				var content_boxes = $(this).find('.content');
				
				if ( content_boxes.length )
				{
					var min_height = content_boxes.height();
					
					$(this).parents('.listslider_wrapper').toggleClass('auto_height');
					
					var max_height = 0;
					
					content_boxes.each(function()
					{
						_h = $(this).outerHeight(true);
						
						max_height = ( _h > max_height ) ? _h : max_height;
					});
					
					if ( max_height > min_height )
					{
						var _css = max_height + 'px';
					
						content_boxes.css('height', _css);
					
						var targets = new Array(
							$(this).find('.item'),
							$(this),
							$(this).siblings('.flowtabs_wrapper'),
							$(this).parents('.listslider_wrapper')
						); 
					
						$.each(targets, function(index)
						{
							$(this).css('height', _css);
						});
					}
					
					$(this).parents('.listslider_wrapper').toggleClass('auto_height');
				}
				
				
				/*
					skip image sliders with only one image
				*/
				images = $(this).find('div.image');

				if ( (images.length && images.length < 2) )
				{
					return;
				}
				
				/*
					initialize the image sliders
				*/
				$(this).siblings('.next').show();
				
				var options = {
					
					// select #flowtabs to be used as navigator
					navi: ".flowtabs_bottom",
					
					// assign "current" class name for the active A tag inside navigator
					activeClass: 'current',

					// keyboard: 'true',
					
					naviItem: 'li',
					
					touch: false

					// make browser's back button work
					//history: true
				};
				
				if ( got_hidden_texts || is_listslider )
				{
					$.extend(options,
					{
						// select #flowtabs to be used as navigator
						navi: ".flowtabs",
						// select A tags inside the navigator to work as items (not direct children)
						naviItem: 'a'
					});
				}
				
				var scroll = $(this).scrollable(
				{
					circular: true,
					mousewheel: false
				})
				.navigator(options);
				
				/*
					the first slider on the frontpage slides automatically
				*/
				var is_frontpage = $('body#frontpage #hero > .themenslider_wrapper');
				
				if ( is_frontpage && i == 0 )
				{
					scroll.autoscroll(
					{
						interval: '5000'
					});
				}

				$(this).siblings('ul.flowtabs, .flowtabs_wrapper').find('li:first > a').addClass('current');
				
				var api = $(this).data('scrollable');
				
				/*
					two navigators, do some magic
				*/
				var second_navigator = $(this).siblings('.flowtabs_bottom');
				
				if ( second_navigator.length && ( got_hidden_texts || is_listslider) )
				{
					// generate <li>s
					var item_count = $(this).siblings('ul.flowtabs, .flowtabs_wrapper').find('li').length;
					
					var list_items = '';  
					
					for (i = 0; i < item_count; i++)
					{  
					    list_items += '<li></li>';  
					}
					
					second_navigator.html(list_items);
					
					second_navigator.find('> li:first').addClass('current');
				}
				
				function control_second_navigator(_api)
				{
					var i = _api.getIndex() + '';
						
				    second_navigator.find('li').removeClass("current");
					var sel = second_navigator.find('li:eq('+(i)+')');
					sel.addClass("current");
				}
				
				/*
					hidden texts inside hero-scroller are swapped when images are scrolled
				*/
				
				// fire text swapping initially
				if ( got_hidden_texts )
				{
					swap_text(api);
				}
				
				function swap_text(_api, fade, plus_one)
				{
					var current_item = _api.getItems().eq(_api.getIndex());
					if ( typeof(plus_one) != 'undefined' )
					{
						current_item = _api.getItems().eq(_api.getIndex()+1);
					}
					
					var text = current_item.find('> .text');
					
					if ( typeof(fade) != 'undefined' )
					{
						text_container.find('.fader').fadeOut('fast', function()
						{
							text_container.find('.fader').remove();
							text_container.append('<div class="fader">' + text.html() + '</div>');
						});
					}
					else
					{
						text_container.find('.fader').html(text.html());
					}
				}
				
				/*
					the api.onSeek function:
					- swap texts after images are scrolled
					- control second navigator, if given
				*/
				api.onSeek(function(event)
				{
					if ( got_hidden_texts )
					{
						swap_text(this, 1);
					}
					
					if ( second_navigator.length )
					{
						control_second_navigator(this);
					}
				});
			});
			
		}
		return true;
	}

	
	/*
		fill the customer alliance rating stars according to the value delivered by
		the customer alliance javascript
	*/
	customer_alliance_rating();
	function customer_alliance_rating() 
	{
		if ( $('#customer_alliance span.ca').length &&  $('#customer_alliance ul').length )
		{
			var s = $('#customer_alliance span.ca').text(),
				pattern = /\s([^\s^]+)\s\//;

			if ( pattern.test(s) )
			{
				var rating = pattern.exec(s);
				rating = rating[1];
				rating = rating | 0;

				$('#customer_alliance ul > li').each(function(i)
				{
					if ( i+1 > rating )
					{
						$(this).addClass('empty');
					}
					$(this).find('span').hide();
				});

			}
		}
	}
	
	
	/*
		'fancy' the booking form
	*/
	var form_booking = $('form#booking');
	
	if ( form_booking.length )
	{
		form_add_datepickers();
	}
	
	
	/*
		'fancy' the contact form
	*/
	var form_contact = $('form#kontaktformular');
	
	if ( form_contact.length )
	{
		form_validations(form_contact);
	}
	
	
	/*
		'fancy' the inquiry form
	*/
	var form = $('form#anfrage');
	
	if ( form.length )
	{
		show_hide_additional_accommodation_data();
		show_hide_company_name_n_fieldset();
		form_add_datepickers();
		// form_add_timepickers();
		form_validations(form);
		form_row_highlight();
	}
	
	
	/*
		
	*/
	function form_add_timepickers()
	{
		$("input.time").timePicker(
		{
			startTime: "10:00", // Using string. Can take string or Date object.
			endTime: new Date(0, 0, 0, 20, 0, 0), // Using Date object here.
			show24Hours: true,
			separator: ':',
			step: 15
		});
		
		// Store time used by duration.
		var oldTime = $.timePicker("#uhrzeit_von").getTime();

		// Keep the duration between the two inputs.
		$("#uhrzeit_von").change(function()
		{
			// if ($("#uhrzeit_bis").val())
			// { // Only update when second input has a value.
			// 	// Calculate duration.
			// 	var duration = ($.timePicker("#uhrzeit_bis").getTime() - oldTime);
			// 	// log(duration);
			// 	var time = $.timePicker("#uhrzeit_von").getTime();
			// 	// Calculate and update the time in the second input.
			// 	$.timePicker("#uhrzeit_bis").setTime(new Date(new Date(time.getTime() + duration)));
			// 	oldTime = time;
			// }
		});
		// Validate.
		$("#uhrzeit_bis").change(function()
		{
			if($.timePicker("#uhrzeit_von").getTime() > $.timePicker(this).getTime())
			{
				//$(this).parents('dl').addClass("error");
			}
			else
			{
				//$(this).parents('dl').removeClass("error");
			}
		});
	}
	
	
	/*
		datepickers using the jQuery TOOLS dateinput
	*/
	function form_add_datepickers()
	{
		if ( lang == 'de' )
		{
			// see https://github.com/clemens/i18n_demo_app/blob/master/config/locales/de.yml
			$.tools.dateinput.localize('de',
			{
			   months:      'Januar,Februar,März,April,Mai,Juni,Juli,August,September,Oktober,November,Dezember',
			   shortMonths: 'Jan,Feb,Mär,Apr,Mai,Jun,Jul,Aug,Sep,Okt,Nov,Dez',
			   days:        'Sonntag,Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag',
			   shortDays:   'So,Mo,Di,Mi,Do,Fr,Sa'
			});
		}
		
		var input_from 	= $("input.date_from, input#date_from");
		var input_to	= $("input.date_to, input#date_to");
		
		if ( ! (input_from.length || input_to.length) )
		{
			return false;
		}
		
		var date_now 		= new Date();
		var date_tomorrow	= new Date(date_now.getFullYear(), date_now.getMonth(), (date_now.getDate()+1));
		var date_plus2days	= new Date(date_now.getFullYear(), date_now.getMonth(), (date_now.getDate()+2));
		
		/*
			add datepicker with current date + 1 day
		*/
		var _options = {
			min: date_tomorrow
		};
		_add_datepicker(input_from, date_tomorrow, _options);
		
		input_from.data('dateinput').change(function()
		{
			var new_date = this.getValue();
			new_date	= new Date(new_date.getFullYear(), new_date.getMonth(), (new_date.getDate()+1));
			
			var api = input_to.data("dateinput");
			
			api.setMin(new_date, true);
			
			// api.setValue(new_date, true);
		});
		
		/*
			add datepicker with current date + 2 days
		*/
		_options = {
			min: date_plus2days
		};
		_add_datepicker(input_to, date_plus2days, _options);
		
		function _add_datepicker(elem, date, options)
		{
			if ( typeof(options) == 'undefined' )
			{
				options = {};
			}
			
			$.extend(options,
			{
				firstDay: 	1,
				format: 	(lang == 'de') ? 'dd.mm.yyyy' : 'yyyy/mm/dd',
				lang: 		lang,
				trigger: 	'.icon_calendar',
				value: 		date
			});
			
			/*
				dates in the fastbooking tool are saved in an english format within hidden fields
			*/
			if ( elem.parents('#booking_n_rating').length || lang == 'en' )
			{
				$.extend(options,
				{
					change: function(e)
					{
						var new_date = (lang == 'de') ? this.getValue('dd.mm.yyyy') : this.getValue('yyyy/mm/dd');

						var id = elem.attr('id');

						var target = $('[name='+id+']');

						target.val(new_date);
					}
				});
			}
			
			elem.dateinput(options);
			var api = elem.data('dateinput');
			api.setValue(date);
		}
		
		return true;
	}
	
	
	/*
		give definition lists containing text inputs a 'hovered' class on hover
	*/
	function form_row_highlight()
	{
		form.find('dl.text input').focusin(function()
		{
			$(this).parents('dl').addClass('hovered');
		});
		
		form.find('dl.text input').focusout(function()
		{
			$(this).parents('dl').removeClass('hovered');
		});
	}
	
	
	/*
		validation methods and dynamic functions of the application form
	*/
	function form_validations(form)
	{
		var submit_button = form.find(':submit');
		
		form.validate(
		{
			lang: 			lang,
			ignore: 		':hidden',
			errorElement: 	'span',
			errorClass: 	'feedback',
			rules: {
				email_confirmation: {
					equalTo: "#email"
				}
			},
			// rules: {
			// 	captcha: {
			// 		remote: {
			// 			url: form.attr('action'),
			// 			type: 'post',
			// 			data: form.serialize(),
			// 			success: function(data){
			// 		    	log(data);
			// 		  	}
			// 		}
			// 	}
			// 	,
			// 	uhrzeit_von: {
			// 		uhrzeit: true
			// 	},
			// 	uhrzeit_bis: {
			// 		uhrzeit: true
			// 	}
			// },
			success: function(label)
			{
				label.parents('dl').removeClass('error').addClass('valid');
				
				return false;
			},
			highlight: function(element, errorClass)
			{
				$(element).parents('dl').removeClass('valid').addClass('error');
			}

			// ,
			// debug: true,
			// submitHandler: function(form)
			// {
			// 	alert('form valid, would be submitted');
			// }
		});
		
		// jQuery.validator.addMethod("uhrzeit", function(value, element)
		// {
		// 	var von = '#uhrzeit_von';
		// 	var bis = '#uhrzeit_bis';
		// 	
		// 	var this = $(element);
		// 	var id = $(element).attr('id');
		// 	log(id);
		// 	
		// 	var to_validate = ( id == 'uhrzeit_von' ) ? $(bis) : $('uhrzeit_von');
		// 	log(to_validate);
		// 	
		// 	if ( to_validate.is(':filled') )
		// 	{
		// 		var check = true;
		// 		
		// 		var von = $.timePicker(von).getTime();
		// 		log(von);
		// 		var bis = $.timePicker(bis).getTime();
		// 		log(bis);
		// 		
		// 		if ( bis && von )
		// 		{
		// 			var check = bis.valueOf() > von.valueOf();
		// 		}
		// 		log(check);
		// 
		// 		return check;
		// 	}
		// 	
		// 	/*
		// 		validate the other time field (again)
		// 	*/
		// 	
		// 	
		// }, "Please specify the correct domain for your documents");
		
		// form.submit();
		
		return false;
		
		/*
			validate via ajax
		*/
		// form.submit(function()
		// {
		// 	data = form.serialize();
		// 	
		// 	$.ajax(
		// 	{
		// 		type: 'POST',
		// 		data: data,
		//  				url: form.attr('action'),
		// 		success: function(data){
		// 	    	log(data);
		// 	  	}
		// 	});
		// 
		// 	return false;
		// });
	}
	
	
	/*
		in case of a private event, the company name input will be hidden
	*/
	function show_hide_company_name_n_fieldset()
	{
		var radio_elems				= $('#veranstaltungs_art_firma, #veranstaltungs_art_privat');
		var company_name_n_fieldset	= $('#wrapper_firma > h3, dl.dl_firmenname');
		// var company_name			= $('#firmenname');
		
		if ( ! company_name_n_fieldset.length )
		{
			return false;
		}
		
		$('#veranstaltungs_art_firma').change(function(val)
		{
			company_name_n_fieldset.show();
		});
		
		$('#veranstaltungs_art_privat').change(function(val)
		{
			company_name_n_fieldset.hide();
		});
		
		// fire events for caching reasons
		var radio_elem_selected = radio_elems.filter(':checked');
		radio_elem_selected.change();
		
		return true;
	}
	
	
	/*
		show/hide the accomondation form fields,
		depending on wheter the customer needs rooms to stay overnight
	*/
	function show_hide_additional_accommodation_data()
	{
		var data_wrapper = $('#additional_accommodation_data');
		var radio_elems = $('#uebernachtung_ja, #uebernachtung_nein');
		
		$('#uebernachtung_ja').change(function(val)
		{
			data_wrapper.show();
		});
		
		$('#uebernachtung_nein').change(function(val)
		{
			data_wrapper.hide();
		});
		
		// fire events for caching reasons
		var radio_elem_selected = radio_elems.filter(':checked');
		radio_elem_selected.change();
	}
});
