function ShowComments(art,pg)
{   $("div#comments_list").html("<b>Загрузка...</b>");
     $.ajax({
        type: "POST",
        url: "/includes/comments.php",
        data: "a="+art+"&p="+pg,
        success : function(comments){$("div#comments_list").html(comments);}

     });
}

function Recaptcha()
{
  var randomnum = Math.ceil(Math.random()*100000);
  $("img#captcha").attr("src","/includes/captcha.php?r="+randomnum);
}

$(document).ready(function(){

$("div.art-preview p.art-title").click(function(){
   //alert($(this).parent().attr("class"));
   $(this).parent().find("p.enabled").removeClass("enabled").addClass("disabled");
   $(this).removeClass("disabled").addClass("enabled");
   $(this).parent().find("div.article:visible").hide();
   $(this).next().show();

});
$("div.showhideform a#hider").click(function(){
  $("div.comments_form").toggle();
  if($("div.comments_form").is(":hidden")) {$("div.showhideform a#hider").html("Я хочу высказаться")}
  if($("div.comments_form").is(":visible")) {$("div.showhideform a#hider").html("Не хочу ничего говорить")}
});

$("dl dd input#cptch, dl dd textarea#opinion").keyup(function(){
var c = $("dl dd input#cptch").val();
var o = $("textarea#opinion").val();
if((o != "")&&(c.length ==5)){$("button#submitter").removeAttr("disabled");}
else{$("button#submitter").attr("disabled","disabled");}
});

$("img#captcha").click(Recaptcha);



$("button#submitter").click(function(){
var c = $("dl dd input#cptch").val();
var n = $("dl dd input#nick").val();
var a = $("input#artcl").val();
var o = $("textarea#opinion").val();
     $.ajax({
        type: "POST",
        url: "/includes/sendform.php",
        data: "c="+c+"&o="+o+"&n="+n+"&a="+a,
        success : function(msg){
          if(msg=="success")
          {
            ShowComments(a,0);
            Recaptcha();
            $("dl dd input#cptch").val("");
            $("dl dd input#nick").val("");
            $("textarea#opinion").text("");
            $("dl dd p.status").html('<span style="color:green">Спасибо за ваше мнение :)</span>');
          }
          if(msg=="error2")
          {
            Recaptcha();
            $("dl dd p.status").html('<span style="color:red">Не правлильно введены цифры с картинки :(</span>');
            $("dl dd input#cptch").val("");
          }
          if(msg=="error1")
          {
            Recaptcha();
            $("dl dd p.status").html('<span style="color:red">Что-то с сервером, мнение не учтено :(</span>');
            $("dl dd input#cptch").val("");
          }
        }

     });

});
$("div.sleepingcats ul.items li a").mouseenter(function(){$(this).parent().addClass("mouseover");}).mouseleave(function(){$(this).parent().removeClass("mouseover");});


})


