var timer;

$(window).load(function () {

  $('a[rel=lightbox]').lightBox({fixedNavigation:true});

  $("a[rel^='prettyPhoto']").prettyPhoto();

  if($("#loginform").is(":hidden")) {

    $('#mylb').mouseenter(function() {
      $("#mylb").addClass("is_active");
      $(this).show();
      $("#loginform").animate({'height':'136px', 'top':'0px'}, 500, function() {
        clearTimeout(timer);
        timer = window.setTimeout('slideOut()', 3000); //vorsichtshalber timer aktivieren, falls user doch nicht will
      });
    });

    $("#loginform").mouseenter(function() {  //wenn maus im feld, dann timer deaktivieren
      clearTimeout(timer);
    }).mouseleave(function () {  //wenn maus nicht in loginbox timer wieder aktivieren
      clearTimeout(timer);
      timer = window.setTimeout('slideOut()', 3000);
    });

    $("#loginform input").focus(function() {  //wenn in input geklickt, dann timer deaktivieren
      clearTimeout(timer);
      $('#mylb').unbind();
      $("#loginform, #loginform > *").unbind();
    });

  }

});

function slideOut() {

  if($("#loginform").is(":visible")) {
    clearTimeout(timer);
    $("#mylb").removeClass("is_active");
    $("#loginform").animate({'height':'0px', 'top':'143px'}, 500, function() {
      $(this).hide();
    });
  }

}
