var infoAktiv;

(function($){
  //-----laden/speichern/aktualisieren Animation
  jQuery.topInfo = function(options){
    var defaults = { hide: false, save: false, aktu: false }
    var settings = $.extend(defaults, options);

    tiText = (settings.aktu ? lang.aktualText : (settings.save ? lang.savingText : lang.loadingText));

    var hideTopInfo = function(){ $("#topinfo").slideUp("normal",function(){ $("#topinfo").remove(); }) }
    var showTopInfo = function(){
      if($("#topinfo")[0]){ $("#topinfo").remove(); }
      $("body").prepend('<div id="topinfo"><img src="images/loading.gif" alt="loading" /><br />'+tiText+'</div>');
      $("#topinfo").css("left",(($(window).width()-182)/2)+'px');

      $("#topinfo").show();
    }

    if(settings.hide){ hideTopInfo(); }else{ showTopInfo(); }
  }

  //-----Informationsleiste
  jQuery.infobox = function(options){
    var defaults = { hide: false, art: 'erfolg', text: '', sticky: false }
    var settings = $.extend(defaults, options);

    var showInfobox = function(){
      $("body").append('<div id="infobox"><div id="infotext"></div></div>');
      window.clearTimeout(infoAktiv);
      $("#infobox:visible").hide().removeClass();

      $("#infotext").html(settings.text);
      $("#infobox").addClass(settings.art).fadeIn();
      if(!settings.sticky){ infoAktiv = window.setTimeout("$.infobox({hide:true})",5000); }
    }
    var hideInfobox = function(){
      $("#infobox").fadeOut("normal",function(){
        $("#infobox").remove();
      });
    }
    if(settings.hide){ hideInfobox(); }else{ showInfobox(); }
  }
  
  //-----verbleibende Zeichen(Input) Overlay
  jQuery.fn.showChars = function(){
    return this.each(function(){
      $(this).focus(function(){
        if(!$("#vzeichen")[0]){
          pos = $(this).position();
          $(this).after('<div id="vzeichen">'+lang.vzeichen+' <span>'+($(this).attr("maxlength")-$(this).attr("value").length)+'</span></div>');
          $("#vzeichen").fadeTo("fast",0.7);
          $("#vzeichen").css({"top":pos.top+28,"left":pos.left+1,"width":$(this).width()});
        }
      });
      $(this).keyup(function(){
        $("#vzeichen span").text($(this).attr("maxlength")-$(this).attr("value").length);
      });
      $(this).blur(function(){
        $("#vzeichen").remove();
      });
    });
  }
  
  //-----Buttons erstellen
  jQuery.fn.makeButtons = function(options){
    var defaults = { icon: 'arrowthickstop-1-e' }
    var settings = $.extend(defaults, options);

    return this.each(function(){
      tButton = $(this);
      tButton.removeClass("doButton");
      hasText = tButton.hasClass("noText") ? false : true;
      icon = "ui-icon-"+( tButton.attr("title") != "" ? tButton.attr("title") : settings.icon );
      tButton.attr("title","");
      tButton.button({icons: {primary: ''+icon+''}, text:hasText});
    });
  }
})(jQuery);

//-----Datepicker deutsch
$.datepicker.regional['de'] = {clearText: 'l&ouml;schen', clearStatus: 'aktuelles Datum l&ouml;schen',
  closeText: 'schlie&szlig;en', closeStatus: 'ohne &Auml;nderungen schlie&szlig;en',
  prevText: '&laquo;', prevStatus: 'letzten Monat zeigen',
  nextText: '&raquo;', nextStatus: 'n&auml;chsten Monat zeigen',
  currentText: 'heute', currentStatus: '',
  monthNames: ['Januar','Februar','M&auml;rz','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'],
  monthNamesShort: ['Jan','Feb','M&auml;r','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez'],
  monthStatus: 'anderen Monat anzeigen', yearStatus: 'anderes Jahr anzeigen',
  weekHeader: 'Wo', weekStatus: 'Woche des Monats',
  dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
  dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
  dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
  dayStatus: 'Setze DD als ersten Wochentag', dateStatus: 'W&auml;hle D, M d',
  dateFormat: 'dd.mm.yy', firstDay: 1,
  initStatus: 'W&auml;hle ein Datum', isRTL: false};
$.datepicker.setDefaults($.datepicker.regional['de']);
