
var labelCntToggle;

// JQUERY
$(function(){		
	
	/******** Seitenübergreifende Funktionen ********/
	/* Content Toggle Funktion */
	$("a#cnt-toggle").click().toggle(function() {
		
		closeContent();
	}, function() {
		$("a#cnt-toggle").removeClass("cnt-open");
		
    $('#wrapper').animate({
        width: 'show',
        opacity: 'show'
    }, 'slow', function () {
    	$("a#cnt-toggle").html(labelCntToggle);
    });
	});

	/******** Seehof ********/
	/* Navigation - Reservationtool */
	// Set Datepicker in Nav
	var now = new Date();
	var year = now.getYear();
	if (year < 999)
  	year += 1900;
	var today = now.getDate() + "." + (now.getMonth() + 1) + "." + year;
	
	$('#res-form-date').DatePicker({
		format:'d.m.Y',
		flat: true,
		date: [today],
		current: today,
		calendars: 1,
		mode: 'range',
		starts: 1,
		onChange: function(formated, dates){
			var toFormat = "" + formated;
			var splitedDates = toFormat.split(",");
			$('#date_arrive_nav').val(splitedDates[0]);
			$('#date_depart_nav').val(splitedDates[1]);
		}
	});
	
	/* OpenToDo M32 Nav Animation 
	$('#m32 #nav ul li ul').each( function () {
		if (!$(this).parent().children('a').hasClass('current_page_item')) {
			$(this).hide();
		}
	});
	$('#m32 #nav ul li a').each( function () {
		//alert("mama");
	});*/
		
	/* Navigation Auto hide */
	$('#sh #nav ul .wrapper-nav').each(function () {
		
		// alle ausser dem aktuellen Subtree verbergen
		if ( !$(this).parent().hasClass('current_page_parent')) {
			$(this).hide();
		}
	});
	$('#sh #nav ul .mnav').each(function () {
		$(this).removeAttr('href');
		$(this).click(function () {
			if ($(this).parent().children(".wrapper-nav").is(":visible") == false) {
				$('#sh #nav ul .wrapper-nav').each(function () {
					$(this).animate({
				      height: 'hide',
				      opacity: 'hide'
					});
					$('#reservation-form').animate({
				      height: 'hide',
				      opacity: 'hide'
				  }, 'slow');
				  res_form_nav = 0;
				});
				$(this).parent().children(".wrapper-nav").animate({
		      height: 'show',
		      opacity: 'show'
				});
			};
		});
		
	});
	
	
	// Show/Hide - Reservation
	//  && typeof $.browser.msie == "undefined"
	$('#reservation-form').hide();
	var res_form_nav = 0; // 0 = close, 1 open
	if (res_form_date2 != 1) {
		if ($.browser.version != "6.0") {
			$('#nav-reserv').removeAttr('href');
			$('#nav-reserv').click(function () {
				//alert("klicked " + res_form_nav);
				if (res_form_nav == 1) {
					res_form_nav = 0;
				  $('#reservation-form').animate({
			      height: 'hide',
			      opacity: 'hide'
				  }, 'slow');
				  
				 	$('.current_page_parent .wrapper-nav').animate({
			      height: 'show',
			      opacity: 'show'
				  }, 'slow');
				  
				} else {
					//alert("Open");
					if (typeof $.browser.msie == "undefined") {
						$('#nav ul .wrapper-nav').each(function () {
							$(this).animate({
					      height: 'hide',
					      opacity: 'hide'
					  	}, 'slow');
					  });
							
					  $('#reservation-form').animate({
					      height: 'show',
					      opacity: 'show'
					  }, 'slow');
					} else {
						$('.current_page_parent .wrapper-nav').hide();
						$('#reservation-form').show();
					}
					res_form_nav = 1;
				}
			});
		}
	} else {
		reservation_form_prepare();
	}
	
	/* Search - onClick delete label */
	$("#search-text").click(function () {
		$("#search-text").val("");
	});
	/******** Seehof End *********/
	
	/******** Seitenübergreifende Funktionen ********/
	/* Newsticker - Home */
	$("#newsticker h2 a").each(function() {
		$(this).removeAttr('href');
	});
	$("#newsticker h2 a").each(function() {
		$(this).parent().parent().children(".nt-element").hide();
	});
	$("#newsticker h2 a").toggle(function() {
		  $(this).parent().parent().children(".nt-element").animate({
		      height: 'show',
		      opacity: 'show'
		  });
		}, function() {
		  $(this).parent().parent().children(".nt-element").animate({
		      height: 'hide',

		      opacity: 'hide'
		  });
	});

	/* IE6 - Hintergrundbild höhe */
	if ($.browser.version == "6.0" && typeof $.browser.msie != "undefined") {
		$('#bgimage').height($('html').height());	
	}
		
	/* Gallerie - Hover */

	// Auto scroll Down Gallerie
	var scrollingDownTimer = 5000; // millisec
	//var galHeight = $('#gallerie-bg').height();
	var galHeight = 82;
	var galBottom = 0;
	var offset = galHeight - 28;
	var galOpen = 1;
  $(this).oneTime(scrollingDownTimer, function() {
  	

    $('#gallerie').animate({
        height: galHeight-offset
    }, 'slow');
    if (autoCloseContent == 1) {
			 // closeContent();   
    }
  });
  
	$("#gallerie").hover(
		function(e){
			$(this).stopTime();
	    $('#gallerie').animate({
	        height: galHeight
	    }, 'slow');
		},
		function() {
			$(this).oneTime(scrollingDownTimer, function() {
						    
		    $('#gallerie').animate({
		        height: galHeight-offset
		    }, 'slow');
		  });
  	}
	);		
/*
  $('.galleriethumb').lightBox({
  	imageBtnClose: imageBtnClose,
  	imageBtnPrev: imageBtnPrev,
  	imageBtnNext: imageBtnNext,
  	imageLoading: imageLoading,
  	overlayBgColor: overlayBgColor,
  	overlayOpacity: overlayOpacity
	});*/
	$('.galleriethumb').lightbox(
		$.Lightbox.construct({
			files: {
				images: {
					prev:		imageBtnPrev,
					next:		imageBtnNext,
					loading:	imageLoading
				}
			},
			text: {
				image:		'Foto',
				of:			'von',
				close:		'Schlie&szlig;en',
				closeInfo:	'You can also click anywhere outside the image to close.',
				help: {
					close:		'Klicken um zu schlie&szlig;en',
					interact:	'' //Hover to interact
				}
			},				
			show_linkback:	false,
			show_info:		true,
			download_link: false,
			padding: 13,
			opacity: overlayOpacity
		})
	);
		
		/*
			files: {
				css: {
					lightbox:'styles/jquery.lightbox.css'
				},
				images: {
					prev:		imageBtnPrev,
					next:		imageBtnNext,
					loading:	imageLoading
				}
			},
			text: {
				image:		'Foto',
				of:			'von',
				close:		'Schlie&szlig;en',
				closeInfo:	'You can also click anywhere outside the image to close.',
				help: {
					close:		'Klicken um zu schlie&szlig;en',
					interact:	'' //Hover to interact
				}
			}
		}
	);
	
/*
    $(function(){
			$.Lightbox.construct({
				show_linkback:	'false',
				opacity:			0.8
			});
		});
				show_info:		true,
				download_link: false,
				files: {
					css: {
						lightbox:'styles/jquery.lightbox.css'
					},
					images: {
						prev:		imageBtnPrev,
						next:		imageBtnNext,
						loading:	imageLoading
					}
				},
				text: {
					image:		'Foto',
					of:			'von',
					close:		'Schlie&szlig;en',
					closeInfo:	'You can also click anywhere outside the image to close.',
					help: {
						close:		'Klicken um zu schlie&szlig;en',
						interact:	'' //Hover to interact
					}
				},*/

	$(".galleriethumb").hover(
		function(e){
			var infoTitle = $(this).children("span").eq(0).text();
			//create box
			$("#gallerie-popup-box .title").text(infoTitle);		
			/*
			$("#infobox .text").text(infoText);		
			$("#infobox .time").text(infoTime);		
			$("#infobox .hiddenid").text(infoHiddenId);		
			*/
				
			var posY = e.pageY - 30;
			var posX = e.pageX + 10; 
			
 			$("#gallerie-popup-box").css("top", posY);	
			$("#gallerie-popup-box").css("left", posX);
			$("#gallerie-popup-box").show();			
		},
		function(){
			$("#gallerie-popup-box").hide();				
		}
	);		

	/******** Angertal ********/
	
	$("#at #nav a").each( function() {
		if ($(this).parent().attr("class") != "current_page_item") {
			$(this).hover( function() {
				$(this).parent().addClass("current_page_item_hover");
			}, function() {
				$(this).parent().removeClass("current_page_item_hover");
			});
		}
	});
	
	$("#at #nav").hover( function() {
		$("#at #nav_highlight").show();
		$("#at #nav").mousemove( function(e) {
			// get new position
			var cur_pos = e.pageY - 120;
			cur_pos = cur_pos + ( 5 - (cur_pos % 6));
			//if (cur_pos % 6 != 0)
			 
			$("#at #nav_highlight").css("top",cur_pos);
		});
	}, function() {
		$("#at #nav_highlight").hide();
		
	});
	
});


function reservation_form_prepare() {
	
	/* Kontaktformular - Error Highlighting */
	$(".wpcf7-validates-as-required").each(function () {
		if ($(this).parents().children("span").children("span").html() != null) {
			$(this).css("border-color", "red");
		}
	});
	$(".wpcf7-mail-sent-ok").each(function () {
		$("#form_show").hide();	
	});
	
	// get the current URL
	var url = window.location.toString();
	//get the parameters
	url.match(/\?(.+)$/);
	var params = RegExp.$1;
	// split up the query string and store in an
	// associative array
	var params = params.split("&");
	var queryStringList = {};
	
	for(var i=0;i<params.length;i++)
	{
		var tmp = params[i].split("=");
		queryStringList[tmp[0]] = unescape(tmp[1]);
	}
	
	// Set Datepicker in Content
	var now = new Date();
	var year = now.getYear();
	if (year < 999)
  	year += 1900;
	var today = now.getDate() + "." + (now.getMonth() + 1) + "." + year;
	var date_arrive = today;
	var date_depart = today;
	
	// Wenn Querystrings vorhanden sind, Formularfelder setze
	if (queryStringList['parents'] != null) {
		$('select#parents').val(queryStringList['parents']);
		$('select#children').val(queryStringList['children']);
		$('#date_arrive').val(queryStringList['date_arrive']);
		$('#date_depart').val(queryStringList['date_depart']);
		date_arrive = queryStringList['date_arrive'];
		date_depart = queryStringList['date_depart'];
	}

	$('#res-form-date2').DatePicker({	
		format:'d.m.Y',
		flat: true,
		date: [date_arrive, date_depart],
		current: today,
		calendars: 1,
		mode: 'range',
		starts: 1,
		onChange: function(formated, dates){
			var toFormat = "" + formated;
			var splitedDates = toFormat.split(",");
			$('#date_arrive').val(splitedDates[0]);
			$('#date_depart').val(splitedDates[1]);
		}
	});
}

function closeContent() {
	labelCntToggle = $("a#cnt-toggle").html();
	$("a#cnt-toggle").html("");
	$("a#cnt-toggle").addClass("cnt-open");
	
  $('#wrapper').animate({
      width: 'hide',
      opacity: 'hide'
  }, 'slow');
}