debug = function (log_txt) {
    if (window.console != undefined) {
        console.log(log_txt);
    }
};


/*Emptytext - Standardwerte für Textfelder*/

(function($)
{
    $.fn.emptyText = function(txt)
    {
        var defClass = arguments[1];
        if (defClass) $(this).addClass(defClass);

        $(this).val(txt);

        $(this).focus(function()
        {
            if ($(this).val() == txt)
            {
                if (defClass) $(this).removeClass(defClass);
                $(this).val("");
            }
        });
        $(this).blur(function()
        {
            if ($(this).val().trim() == "")
            {
                if (defClass) $(this).addClass(defClass);
                $(this).val(txt);
            }
        });
    };
})(jQuery);  




$(function(){

    // --->

    /* Datepicker */


$("#searchBox .text").emptyText(txtSearch, "eigentlichLeer");


if($('.datePickerGroup')[0]) {
        //There is at least one item that matches the selector

        //Creating the default dates: von = now, bis = now + 7 days!
        var d = new Date();
        var curDate = d.getDate();
        var curMonth = d.getMonth() + 1;
        var curYear = d.getFullYear();
        if(curDate < 10) { curDate = '0' + curDate }
        if(curMonth < 10) { curMonth = '0' + curMonth }

        var d2 = new Date();
        d2.setDate(d2.getDate()+7);
        var curDate2 = d2.getDate();
        var curMonth2 = d2.getMonth() + 1;
        var curYear2 = d2.getFullYear();
        if(curDate2 < 10) { curDate2 = '0' + curDate2 }
        if(curMonth2 < 10) { curMonth2 = '0' + curMonth2 }

        /*
           Compatible with more than one datepicker on the website.
           thisNode = The from-input field
           siblingNode = The respective to-input field

           Note: The correct assignment only works, when both input fields
           have a mutual parent element with the the class datePickerGroup.
           'cal_von' and 'cal_bis' must exist only once within the group!
        */

        $('.datePickerGroup input.cal_von').each(function() {
                thisNode = $(this);
                siblingNode = $(this).parents('.datePickerGroup').find('input.cal_bis');



                //If the input field already has a value set, use it. Otherwise set the defaults
                if(thisNode.val() == '') {
                        thisNode.val(curDate + '.' + curMonth + '.' + curYear);
                }
                if(siblingNode.val() == '') {
                        siblingNode.val(curDate2 + '.' + curMonth2 + '.' + curYear2);
                }

                //Feel free to add routines and listen to events
                thisNode.datepicker({   

				showButtonPanel: true,
				showOn: 'focus',
										
										
									
									minDate: d,
                                        onClose: function(dateText, inst) {
                                                var mDate = thisNode.datepicker("getDate");
                                                var sibDate = siblingNode.datepicker("getDate");

                                                siblingNode.datepicker("option", "minDate", mDate);
                                                if(sibDate < mDate) {
                                                        siblingNode.datepicker("setDate", mDate);
                                                }
                                        }
                                });

                siblingNode.datepicker({ minDate: thisNode.datepicker("getDate"),    showButtonPanel: true,
            showOn: 'focus' });

        });

};

// Schieberegler für Anfrageformular

$("select.rangeinput").each(function () {
									  

var minVal = $(this).find("option:first").attr("value");
var maxVal = $(this).find("option:last").attr("value");
var inputName = $(this).attr("name");
	$(this).replaceWith('<input type="range" class="range" name="' +inputName + '" min="' + minVal + '" max="'+ maxVal +'" value="0.1" step="1" />');
});
$(".range").rangeinput();


// Kinder Alter
function changeChildCount() {
    numberOfChildFields = $('input[name="countChildren"]').val();
	debug(numberOfChildFields);
    for(i=1;i<=10;i++) {
	if(i <= numberOfChildFields) {
	    $('input[name="ageChild_'+i+'"]').parent().show();
	} else {
	    $('input[name="ageChild_'+i+'"]').parent().hide();
	}
    }
}

    if($('input[name="countChildren"]')[0]) {
	changeChildCount();
	$('input[name="countChildren"]').change(function(e){
	    changeChildCount();
	});
    }


/***************************************************************************/
/*							Zeit-Themen-Navigation							*/
/***************************************************************************/
	var startdate = new Date();
	var startMonth = startdate.getMonth();
	
	/*		Zeit Themen Slider		*/
	
	/*$("#ztnWrapper div#ztn").append('<a class="prev browse"><-</a><a class="next browse">-></a>');
	$("#ztnSlider").scrollable({ circular: true, mousewheel: true, items:"ul.level_1" });
	var api = $("#ztnSlider").data("scrollable");
	api.move(startMonth, 0);*/


		
	/*		Images			*/
	
/*	$('.image_container').hover(function () {
							$(this).find(".magnify").animate({'top':'0'});  
												  
	}, function(){
		$(this).find(".magnify").stop(true, false).animate({'top':'-30px'});  
		
		});*/
	


	
if( $('a[rel]')[0] || $('.image_container a[rel]')[0] ){
//LIGHTBOX AUFRUFE HIER HINTERLEGEN 

$('a[rel], .image_container a').filter(function(index) {
//do NOT register the colorbox if the element has a parent with the class 'no_colorbox or is a PDF'
if($(this).parents('.no_colorbox')[0] || $(this).parents('.pdf_link')[0] || $(this).parents('.nivo-controlNav')[0]) {
return 0;
} else
return 1;
}).colorbox({transition:"elastic",  maxHeight:"80%", current:""});
};

	



//----------------------------------------------->
});


$('p.error').click(function() {
  $(this).hide();
});






/* Nivoslider */

         //Wieviele Bilder wurden zugeteilt
         var i = $('#header article section img').length;
         
         if(i >= 2){ 
              // fuer die richtige Darstellung             
              $('#header article').wrap('<div class="sliderPos">'); //ist der momentane #slider wo die Position festgelegt wird
              $('#header article img').unwrap().unwrap().unwrap(); 
              $('.sliderPos img').wrapAll('<div id="slider" class="nivoSlider">');
              $('.sliderPos').prepend('<div class="ribbon">');
              $('.sliderPos').wrapInner('<div class="slider-wrapper theme-default">');
			             
              // Aufruf des Sliders
              $('#slider').nivoSlider();
			  		  		                       
              /* Positionierung der Punkte */   
              var anzahl = $('#slider img').length; 
              var y = -13;
              var z = anzahl * y;
              $('div.nivo-controlNav').css('margin-left', z);
          
          } else if (i == 1) {
			
              $('#header article').wrap('<div class="sliderPos">'); //ist der momentane #slider wo die Position festgelegt wird
              $('#header article img').unwrap().unwrap().unwrap();
              
          } else {
              $('#header .inside').append('<div class="sliderPos">');
              $('.sliderPos').html('<img src="/tl_files/layout/default.jpg" alt="">');    
          } 
          
          
          
          
/* Zoom Icons zum vergrößern der Bilder */

$('.ce_text .image_container').hover(function() {
      	$('.ce_text .image_container span').stop().animate({ backgroundPosition : '-15px 0px' }, 300)	
}, function() {
      	$('.ce_text .image_container span').stop().animate({ backgroundPosition : '0px 0px' }, 300)
});


