$(init);

function init() {
  $(".vote_button").hover(function(){
    $(this).addClass("vote_hover");
  },function(){
    $(this).removeClass("vote_hover");
  });
  $(".vote_button").click(function(){
    var but = $(this);
    var id = but.attr("article");
    but.unbind(); 
    but.fadeTo("slow",0.3,function(){
      $.post('/index.php?do=vote',{id:id},function(reply){  
        but.html(reply).fadeTo("slow",1);
      });
    });     
  });
  $("#but_login").click(function(){
    var pass = $("#loginbox input").val();
    $.post('/index.php?do=login',{pass: pass},function(reply){
      if (reply == 'OK')
        location.reload();
    });
  });
  
}

function show_loginbox() {
  var w = $(window).width() /2 - 100;
  var h = $(window).height() /2 - 50;
  $('#loginbox').css('top',h+'px').css('left',w+'px').fadeIn('slow');
}

function logout() {
  $.get('/index.php?do=logout',function(){
    location.reload();
  });
}