$(document).ready(function(){

	// // Set min-height for content, so page isn't scaled by accordeon
	// var maxNavHeight = $('.page-item-' + fixedPostID).height() + 41*6; // FINAL -----> ADJUST PAGE ID !!!
	// var contentHeight = $('#content').height();
	// 
	// if(contentHeight<maxNavHeight){
	// 	$('#content-wrapper').height(maxNavHeight+8); // +8 --> firefox height-bug (in footer)
	// }
	
	
	// add "target=_blank" to external links
	$('a[href^="http://"]:not([href^="http://www.hotel-bayern-vital.de/"])').not("[href^=#]")
		.attr("target", "_blank");

	// link to pdf: add class 'pdf' & open in new window
	$('a').each(function(){
		var linkEnding = $(this).attr('href').substr($(this).attr('href').length-3, 3); // get last 3 chars of href
		if(linkEnding == 'pdf'){
			$(this).addClass('pdf');
			$(this).attr('target', '_new');
		}
	});

	
	/*
// initialise accordion
	$('#navigation').hoverAccordion({
		keepheight: 'false',
		activateitem: fixedPostID
	});	
*/

/*
	// initialise UI accordion, if actual site is not startseite
	if(fixedPostID != 89){
		$("#navigation").accordion({
			autoHeight: false,
			active: fixedPostID-1
		});
	}
*/
	
	// show all header images when page is loaded
	$('ul#header li').each(function(){
		$(this).css('display', 'block');
	});
	
	// initialise header slide show
	$('ul#header').innerfade({
		speed: 2000,
		timeout: 7000,
		type: 'sequence',
		containerheight: '255px'
	});
	
	// show all header images when page is loaded STARTSEITE
	$('ul#header-stsart li').each(function(){
		$(this).css('display', 'block');
	});
	
	// initialise header slide show STARTSEITE
	$('ul#header-start').innerfade({
		speed: 2000,
		timeout: 7000,
		type: 'sequence',
		containerheight: '457px'
	});
	
	// INITIALISE HYPHENATOR
	Hyphenator.run();
	
	// CONTACT FORM
	$('form#contact_form').submit(function(){
		// remove error messages p & fade out #errors
		$('#errors p').remove();
		$('#errors').fadeTo(0, 0);
		$('.err').removeClass('err');
		var hasError = false;
		var focusOn = false;
		$('.requiredField').each(function(){
			if(jQuery.trim($(this).val()) == ''){
				var labelText = $(this).prev('label').text();
				$('#errors').append('<p>Bitte f&uuml;llen Sie das Feld '+labelText+' aus.</p>');
				$('#errors').fadeTo(200, 1);
				$(this).addClass('err');
				hasError = true;
				// focus element if is first error
				if(!focusOn){
					$(this).focus();
					focusOn = true;
				}
			} else if($(this).hasClass('email')){
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				if(!emailReg.test(jQuery.trim($(this).val()))) {
					var labelText = $(this).prev('label').text();
					$('#errors').append('<p>Bitte geben Sie eine g&uuml;ltige '+labelText+'-Adresse an.</p>');
					$('#errors').fadeTo(200, 1);
					$(this).addClass('err');
					hasError = true;
					// focus element if is first error
					if(!focusOn){
						$(this).focus();
						focusOn = true;
					}
				}
			}
		});
		if(!hasError){
			$('#errors').fadeTo(200, 0);
			$('form#contact_form input.button').fadeOut('normal', function() {
				$(this).parent().append('<img src="http://localhost/hotel-bayern-vital/wp-content/themes/hbv/css/loading.gif" alt="Loading&hellip;" height="24" width="24" />');
			});
			var formInput = $(this).serialize();
			$.post($(this).attr('action'),formInput, function(data){
				$('form#contact_form').slideUp("fast", function() {				   
					$(this).after('<p class="thx">Vielen Dank!<br />Ihre Anfrage wurde erfolgreich versendet.</p>');
				});
			});
		}
		return false;	
	});

});


// Popup Reservierung
function reservierung(){
	newWindow = window.open('http://194.177.128.243/gastrobin/gastrores.exe?betrieb=2219&action=10000', 'Kontakt', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=550,height=450');
	newWindow.focus();
}

// Mail address decoding
function UnCryptMailto(s){
	var n = 0;
	var r = "";
	for(var i=0; i<s.length; i++){
		n = s.charCodeAt( i );
		if(n >= 8364){
			n = 128;
		}
        r += String.fromCharCode(n-1);
	}
	return r;
}
function linkTo_UnCryptMailto(s){
	location.href=UnCryptMailto(s);
}
