
  //------------------- Рейтингование -----------------------
    $(document).ready(function()
      {
        $(".rating_change").click(function()
          { 
            if ($(this).attr("class") == "rating_change png" || $(this).attr("class") == "rating_change")
              {
                value = this.id;
                
                $("#rating_plus").after('<img class="ajaxPreloader" src="/img/ajax-loader.gif" style="position: absolute; margin-top: 0px;">');
                $.post("/rating/change/", {obj_id:$('#obj_id').val() , item_id:$('#item_id').val() , value:value }, function(data) 
                  { 
                    $(".ajaxPreloader").remove();
                
                    if (data)
                      { 
                        $.post("/rating/change/", {rating_type: 'topic', user_comment_id:$('#user_comment_id').val(), value:value }); 
                          
                        new_value = parseFloat(parseFloat($("#rating_value").html()) + parseFloat(data));
                        $("#rating_value").html(String(new_value)); 
                        $("#rating_plus").attr("src", "/img/ico/action_add_d.png");
                        $("#rating_plus").removeClass("rating_change");
                        $("#rating_minus").attr("src",  "/img/ico/action_remove_d.png");
                        $("#rating_minus").removeClass("rating_change");
                      }  
                  });
              }
          });
      });
     
    $(document).ready(function()
      {
        $(".comment_rating_change").click(function()
          { 
            if ($(this).hasClass("comment_rating_change"))
              { 
                
                item_id = this.id.slice(2);
              
                if ($(this).hasClass("rating_minus"))
                  {
                    value = "rating_minus";
                  }
                if ($(this).hasClass("rating_plus"))
                  {
                    value = "rating_plus";
                  } 
                                  
                $.post("/rating/change/", {obj_id:$('#comm_obj').val() , item_id:item_id , value:value }, function(data) 
                  {  
                    if (data)
                      { 
                      
                        $.post("/rating/change/", {rating_type: 'comment', user_comment_id:$('#user_comment_id_'+item_id).val(), value:value }, function(datar) 
                          {
                             //alert(datar); 
                          });                        
                       
                        new_value = parseInt(parseInt($("#comm_rating_value_"+item_id).html()) + parseInt(data));
                        $("#comm_rating_value_"+item_id).html(String(new_value));
                        
                        if (new_value == 0) $("#comm_rating_value_"+item_id).css("color","#666666");
                        if (new_value > 0)  
                          {
                            $("#comm_rating_value_"+item_id).css("color","#0a6c00");
                            $("#comm_rating_value_"+item_id).html("+"+$("#comm_rating_value_"+item_id).html());
                          }
                        if (new_value < 0)  $("#comm_rating_value_"+item_id).css("color","#c41111");
                         
                        $("#rp"+item_id).attr("src", "/img/ico/plus24_d.png");
                        $("#rp"+item_id).removeClass("rating_change");
                        $("#rm"+item_id).attr("src",  "/img/ico/minus24_d.png");
                        $("#rm"+item_id).removeClass("rating_change");
                        $("#sp"+item_id).remove();
                      }  
                  });
              }
          });
      });    
    
  //------------------- Коментарии -----------------------
      $(document).ready(function(){
          $("#add_comm_topic").click(function(){
             $("#add_comm_end").hide();
             $(".comment_form").remove();
             $("#comment_to").val('');
             $("#add_comm_end").before('<div class="comment_form">'+$('.comment_form_tpl').html()+'</div>');
          });
	  
          $(".comment:odd").css("background-color","#EEE6DE");	
          $(".answer").click(function(){
              $("#add_comm_end").show();
              $(".comment_form").remove();
              //$("#c"+this.id.slice(1)).append('<div class="comment_form">Добавить комментарий:<form action="" method="post"><textarea id="comment_text" name="comment_text"></textarea><br/><input type="hidden" name="comment_to" value="'+this.id.slice(1)+'"><input type="submit" id="comment_submit" value="Отправить"></form></div>');
              $("#c"+this.id.slice(1)).append('<div class="comment_form">'+$('.comment_form_tpl').html()+'</div>');
              $('#comment_to').val(this.id.slice(1)); 
              $('#comment_form_tpl').show();            
          });
      });
      
      function delclick()
        {
          $(".delete_comment").click(function(){
            level = (parseInt($('#c'+this.id.slice(1)).css("margin-left"))-10)/30;
            k = 1; 
            list_id = this.id.slice(1); 
            while (level < ((parseInt($('#c'+this.id.slice(1)).next("div").css("margin-left"))-10)/30)){
              list_id = list_id + "|" + $('#c'+this.id.slice(1)).next("div").attr("id").slice(1);
              $('#c'+this.id.slice(1)).next("div").remove();
              k++;
            }

            $('#c'+this.id.slice(1)).remove();
            
            $("#comment_count").html(parseInt($("#comment_count").html()) - k);
                
            $(this).after('<img style="position: absolute; margin-top: -2px;" class="ajaxPreloader" src="/img/ajax-loader.gif">');
            $.post("/comments/delete/", {comid:list_id, obj:$("#comm_obj").val()}, function(data){
                $(".ajaxPreloader").remove();        
              }); 	          
          });
        }
   
      $(document).ready(function(){
          $(".moderate_comment").click(function(){ 
            $(this).after('<img style="position: absolute; margin-top: -2px;" class="ajaxPreloader" src="/img/ajax-loader.gif">');
            $('#c'+this.id.slice(1)).html('<div style="height: 25px;"><img src="/data/users/avatar/comment_moder.png" style="float: left; margin-right: 10px;" /><div style="width: 100%; text-align: cwnter; font-size: 16px; padding-top: 3px;">Пришел добрый доктор Айболит и вылечил плохой коментарий <a href="javascript: void(0);" id="d'+this.id.slice(1)+'" class="delete_comment" style="text-decoration: underline; color: red">удалить</a></div></div>');  
            delclick();
            $.post("/comments/moderate/", {comid:this.id.slice(1), obj:$("#comm_obj").val()}, function(data){
                $(".ajaxPreloader").remove();        
              }); 	          
          });
      });   
      
      $(document).ready(function(){
        delclick();
      });        
   
  // ---------------------------- Букмарчим
  function getBrowserInfo() 
    {
      var t,v = undefined;
      if (window.opera) t = 'Opera';
      else if (document.all) 
        {
          t = 'IE';
          var nv = navigator.appVersion;
          var s = nv.indexOf('MSIE')+5;
          v = nv.substring(s,s+1);
        }
      else if (navigator.appName) t = 'Netscape';
      return {type:t,version:v};
    }

  function bookmark(a)
    {
      var url = window.document.location;
      var title = window.document.title;
      var b = getBrowserInfo();
      if (b.type == 'IE' && 7 > b.version && b.version >= 4)
        { 
          window.external.AddFavorite(url,title);
        }
      else if (b.type == 'Opera') 
        {
          a.href = url;
          a.rel = "sidebar";
          a.title = url+','+title;
          return true;
        }
      else if (b.type == "Netscape")
        { 
          window.sidebar.addPanel(title,url,"");
        }
      else
        {
          alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
        }
      return false;
    }

  function start()
    {
      var url = location.href;
      netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite");
      navigator.preference("browser.startup.homepage", url);
    }  