$(document).ready(function(){
  //$('textarea').autogrow();
  
  if($("ul.sf-menu").length > 0)
    $("ul.sf-menu").supersubs({
        minWidth:    12,   // minimum width of sub-menus in em units
        maxWidth:    27,   // maximum width of sub-menus in em units
        extraWidth:  1     // extra width can ensure lines don't sometimes turn over
        // due to slight rounding differences and font-family
      }).superfish();  // call supersubs first, then superfish, so that subs are
      // not display:none when measuring. Call before initialising
      // containing tabs for same reason.


if($.cookie("hideWarning") != 1) {
$("<!--[if lte IE 6]><div id='browserWarning'>Sie benutzen einen veralteten Browser! Hierdurch kann die Funktion der Seite eingeschränkt sein! Bitte nutzen Sie einen der folgenden Browser: <a href='http://getfirefox.com'>FireFox</a>, <a href='http://www.opera.com/download/'>Opera</a>, <a href='http://www.apple.com/safari/'>Safari</a> oder <a href='http://www.microsoft.com/windows/downloads/ie/getitnow.mspx'>Internet Explorer</a>. Vielen Dank! [<a id='warningClose' href='#'>Meldung schließen</a>]</div><![endif]-->")
      .css({
  backgroundColor: '#fcfdde',
  'width': '100%',
  'border-top': 'solid 1px #000',
        'border-bottom': 'solid 1px #000',
  'text-align': 'center',
  padding:'5px 0px 5px 0px'
      })
  .prependTo("body");
  }


  $('#warningClose').click(function() {
    $('#browserWarning').fadeOut();
    $.cookie("hideWarning", "1", { expires: 2 });
  });

  // Merkzettel
  $("#visitor_bookmarks").load("/api/bookmark?option=count");


  $("#loading").bind("ajaxSend", function(){
    $(this).show().animate({opacity: 1.0}, 500);
  }).bind("ajaxComplete", function(){
      $(this).fadeOut();
  });

  autoFill($("#sb_input"), "Suchbegriff eingeben");

  $('.bookmark').click(function(){
    var aObj = $(this);
    $.ajax({
      type: "GET",
        url: "/api/bookmark?option=add",
        data: "id="+this.id,
        timeout: 1000,
        success: function(msg){

            if(msg == 1) {
              // Steht auf der Liste
              aObj.text("Vom Merkzettel streichen");
              $("#visitor_bookmarks").load("/api/bookmark?option=count");
            } else if(msg == 0) {
           //Wurde gelöscht
              aObj.text("Zum Merkzettel hinzufügen");
              $("#visitor_bookmarks").load("/api/bookmark?option=count");
            } else {
              //alert("Fehler!");
              $("#visitor_bookmarks").load("/api/bookmark?option=count");
            }
            aObj = null;
        }
    });
  });

});
function autoFill(id, v){
    $(id).css({ color: "#b2adad" }).attr({ value: v }).focus(function(){
      if($(this).val()==v){
        $(this).val("").css({ color: "#333" });
      }
    }).blur(function(){
      if($(this).val()==""){
        $(this).css({ color: "#b2adad" }).val(v);
      }
    });
  }

  jQuery.fn.fadeToggle = function(speed, easing, callback) {
      return this.animate({opacity: 'toggle'}, speed, easing, callback);
  };