jQuery(document).ready(function(){

   //Zeitgeverbundener Datepicker
   $(function()
{

	$('.date-pick').datePicker()
	$('#start-date').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#end-date').dpSetStartDate(d.addDays(1).asString());
			}
		}
	);
	$('#end-date').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#start-date').dpSetEndDate(d.addDays(-1).asString());
			}
		}
	);
});



  //versteckt alle uebersichte beim erstaufruf
  $(".uebersicht").hide();
  //toggle monate
  $(".monate").click(function()
  {
    $(this).next(".uebersicht").slideToggle(600);
    $(this).toggleClass("on");
  });

 $(".monate:first").addClass("on");
 $(".monate:first").next(".uebersicht").show();



  $(".tourfinder").hide();
  // ###   Klick auf Submit ###
  $(".button_tourfinder").click(function(){
    $(".tourfinder").click();
  });


	//Verbundene Selects fuer die Reiseanfrage
	function makeSublist(parent,child,childVal)
	{
		$("#"+child+" option").each(
		function() {
			var buildChildData= $(this).attr('value').split("_");
			$(this).addClass("sub_"+buildChildData[1]);
		 });

		$("body").append("<select style='display:none' id='"+parent+child+"'></select>");
		$('#'+parent+child).html($("#"+child+" option"));

			var parentValue = $('#'+parent).attr('value');
			$('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());

		childVal = (typeof childVal == "undefined")? "" : childVal ;
		$("#"+child+' option[@value="'+ childVal +'"]').attr('selected','selected');

       //falls es mehr als eine reise gibt, dann kommt die waehloption
        if ($("#"+child+" option").length>1){
            //
            //            if($("#"+child+" option").attr("value")!='')
            //                $('#'+child).prepend("<option value=''> -- Bitte w&auml;hlen -- </option>");
            //                else
                    $('#'+child).addOption("", " -- Bitte wählen -- ");
//                    $('#'+child+' option:first').attr("selected","selected");
        }

		$('#'+parent).change(
			function()
			{
				var parentValue = $('#'+parent).attr('value');
				$('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());
				if($("#"+child+" option").length>1) $('#'+child).addOption("", " -- Bitte wählen -- ");
				$('#'+child).trigger("change");
							$('#'+child).focus();
			}
		);
	}



		makeSublist('Reisename','Wunschtermin');




});