$(function(){
    $("#navi>ul>li").each(function () {
        $(this).hoverIntent({
            over: function () {
                $(this).addClass("hover");
            },
            timeout: 100,
            out: function () {
                $(this).removeClass("hover");
            }
        });
    });

    function mycarousel_initCallback(carousel)
      {
        // Disable autoscrolling if the user clicks the prev or next button.
        carousel.buttonNext.bind('click', function() {
          carousel.startAuto(0);
        });
        carousel.buttonPrev.bind('click', function() {
          carousel.startAuto(0);
        });
        // Pause autoscrolling if the user moves with the cursor over the clip.
        carousel.clip.hover(function() {
          carousel.stopAuto();
        }, function() {
          carousel.startAuto();
        });
      };


    // setup ul.tabs to work as tabs for each div directly under div.panes
    $("ul.tabs").tabs("div.panes > div");


    // Datepicker im calendar teaser
    $(".datepicker").datepicker();

    // Datepicker-Teaser mit Kalenderlink, Aufruf des Links mit Datum bei DP-Auswahl
    $("div.datepicker.eventSearchLink").datepicker('option', {onSelect: function (dateText, inst) {
        var dateArray;
        dateArray = dateText.split('.');
        window.location = $(this).next('a').attr('href') + '?' + 'dStart[2]=' + dateArray[0]
             + '&' + 'dStart[1]=' + dateArray[1] + '&' + 'dStart[0]=' + dateArray[2]
             + '&' + 'dEnd[2]=' + dateArray[0] + '&' + 'dEnd[1]=' + dateArray[1]
             + '&' + 'dEnd[0]=' + dateArray[2];
    }});

    // Datepicker in QuickFinder und Veranstaltungskalender
    // Leider etwas schwieriger mit select form fields
    // $("a.date_picker").datepicker();
    dpOpts = {};
    // Bei Datumsauswahl Textdatum auf Selects verteilen
    dpOpts.onSelect = function (dateText, inst) {
        var dateArray,
            $this;
        dateArray = dateText.split('.');
        $this = $(this);
        $this.siblings('select:eq(0)').val(Number(dateArray[0]));
        $this.siblings('select:eq(1)').val(Number(dateArray[1]));
        $this.siblings('select:eq(2)').val(Number(dateArray[2]));
    }
    // Brücken-Input erstellen und mit Datepicker versehen (und korrektes Datum setzen)
    $('<input style="width:1px;visibility:hidden">').insertBefore('a.date_picker').each(function () {
        var d,
            m,
            y,
            $this;
        $this = $(this);
        $this.datepicker(dpOpts);
        d = $this.siblings('select:eq(0)').val();
        m = $this.siblings('select:eq(1)').val();
        y = $this.siblings('select:eq(2)').val();
        if (d && m && y) {
            $this.datepicker('setDate', new Date(y, m - 1, d));
        }
    });
    // Link mit Datepicker-Input verbinden
    $('a.date_picker').click(function () {
        $(this).prev().focus();
        return false;
    });
    // Ende Datepicker

// timepicker config
/*
$.timepicker.regional['de'] = {
  timeOnlyTitle: 'Uhrzeit auswählen',
  timeText: 'Zeit',
  hourText: 'Stunde',
  minuteText: 'Minute',
  secondText: 'Sekunde',
  currentText: 'Jetzt',
  closeText: 'Auswählen',
  ampm: false
};
$.timepicker.setDefaults($.timepicker.regional['de']);
*/
// timepicer config ende

    // bilder abdunkeln
    /*$("div.tab_content").mouseover(function(){
        $(this).fadeTo('slow', 0.5, function() {
          // Animation complete
        });
    });
    $("div.tab_content").mouseout(function(){
        $(this).fadeTo('fast', 1, function() {
          // Animation complete
        });
    });*/
    $("a.map").nyroModal( {minWidth: 440, minHeight:800} );
    $("a.linkRouting").nyroModal( {minWidth: 440, minHeight:600} );
    $("a.anfrageFenster").nyroModal( {minWidth: 778, minHeight:610, forceType: 'iframe'} );
    $('#mycarousel').jcarousel({animation: 1000, scroll: 1, auto: 8, wrap: 'last', initCallback: mycarousel_initCallback});
    $('a.galleryStartLink').click(function (e) {
        e.preventDefault();
        $(this).parent().next('.detail a:first').click();
    });
});

function saferString(string){
    string = string.split('<').join('&lt;');
    string = string.split('>').join('&gt;');
    return string
}

function str_replace(search, replace, string){
    return string.split(search).join(replace);
}
