    //$(document).ready(function(){ $(document).pngFix(); });
   
  //------------------------------------- Подсчет введенных символов ---------------------

    $(document).ready(function()
      {
        $(".char_counter").keypress(function(e)
          { 
            k=1;       
            if (e.which == 8) k = -1;
            if (e.which == 0) k = 0;
            if ($(this).val().length = "") k = 0;
            
            maxlength = $(this).attr("maxlength");
            length = $(this).val().length +k;

            char_count = $("#"+$(this).attr("name")+"_char_count"); 
            
            
            count = maxlength-length;
            
            if (maxlength-length > maxlength) count = maxlength;
            if (maxlength-length < 0) count = 0;
            
            char_count.html(String(count));
          });        
      });

  //------------------- Рейтингование -----------------------
    $(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();
                      }  
                  });
              }
          });
      });    
    
    
    
    
    function setCookie (name, value, expires, path, domain, secure) 
      {
        document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
      }

    
    function cookieSwitch(id)
      {
        var cook = getCookie(id);
        if (cook == 'maximized')
          {
            setCookie(id, 'minimized', "Mon, 01-Jan-2015 00:00:00 GMT", "/");
          }
        else
          {
            setCookie(id, 'maximized', "Mon, 01-Jan-2015 00:00:00 GMT", "/");
          }
      }
      
    function getCookie(name) 
      {
	    var cookie = " " + document.cookie;
	    var search = " " + name + "=";
	    var setStr = null;
	    var offset = 0;
	    var end = 0;
	    if (cookie.length > 0) 
	      {
	        offset = cookie.indexOf(search);
		    if (offset != -1) 
		      {
		        offset += search.length;
			    end = cookie.indexOf(";", offset)
			    if (end == -1) 
			      {
			        end = cookie.length;
			      }
			    setStr = unescape(cookie.substring(offset, end));
		      }
	      }
	    return(setStr);
      } 
    
    // Свертывание развертывание правых панелей
    $(document).ready(function()
      {      
        // Функция свертывания развертывания правых панелей
        $(".switch_panel").click(function()
          {
            $(this).parent().parent().next().toggle();
            if ($(this).children('img').attr('src') == '/img/ico/maximized.png')
              {
                $(this).children('img').attr('src', '/img/ico/minimized.png');
              }
            else
              {
                $(this).children('img').attr('src', '/img/ico/maximized.png');
              }       
          });
          
        // свертывание развертывание блоков в контент-области (напр. для категорий)
        $(".switch_content_item").click(function()
          {
            $(this).next("div").toggle();
            if ($(this).children().children('img').attr('src') == '/img/ico/maximized.png')
              {
                $(this).children().children('img').attr('src', '/img/ico/minimized.png');
              }
            else
              {
                $(this).children().children('img').attr('src', '/img/ico/maximized.png');
              }       
          });
      });
    
  //------------------- Коментарии -----------------------
      $(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","#f4ffde");	
          $(".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();
      });        
   
  // ------------------ Иконки ссылок --------------------
    $(document).ready(function()
      {
        $("a[@href$=pdf]").addClass("pdf");
        $("a[@href$=doc]").addClass("doc");
        $("a[@href$=rtf]").addClass("rtf");
        $("a[@href$=zip]").addClass("zip");
        $("a[@href$=rar]").addClass("rar");
        $("a[@href$=xls]").addClass("xls");
        $("a[@href$=ppt]").addClass("ppt");
        $("a[@href$=jpg]").addClass("pic");
        $("a[@href$=gif]").addClass("pic");
        $("a[@href$=png]").addClass("pic");
        $("a[@href$=JPG]").addClass("pic");
        $("a[@href$=ppt]").addClass("ppt");
        $("a[@href$=pps]").addClass("ppt");
        $("a[@href$=mp3]").addClass("mus");
        $("a[@href$=wma]").addClass("mus");
        $("a[@href$=cdr]").addClass("cdr");
        $("a[@href$=ai]").addClass("cdr");
        $("a[@href*=/help/users/?info]").addClass("userico");
      });


  // ---------------------------- Букмарчим
  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);
    }

  // ---------------------------- Select для поиска
  $(document).ready(function(){
    var e = window.event; 
    $(document.body).click(function (e) {
      if (e.target.className == "select_button" || e.target.className == "select_button_sub"){
        if ($(".select_show:first").is(":hidden")) {
          $(".select_show").fadeIn("slow");
        } else {
          $(".select_show").hide();
        }
	  }else{
	   $(".select_show").hide(); 
	  }
    });
	
    $(".select").click(function () {
      $(".select_button").html($(this).html());
	  $(".select").css({"background-color":"#ffffff"})
	  $(this).css({"background-color":"#e3e6f9"})	  
	  $("#place").val($(this).attr("id"));
    });	
	
    $(".select").hover(
      function () {
        $(this).css({"background-color":"#e3e6f9"});
      },
      function () {
        $(this).css({"background-color":"#ffffff"});
      }       
	);
  });

  // ---------------------------- Показываем форму логина
  $(document).ready(function()
    {
      $(".login_show").click(function()
        {
          var divHeight = $("table:first").height();
          var loginWidth = $("table:first").width();
          var background = $('<div id="overlayBackground"></div>');
          $(background).css({'width:' : '100%', 'height': divHeight, 'opacity' : '0.1'});
          $("#login_form").width(Math.round(loginWidth*0.3));                                
          $(background).animate({'opacity' : '.6'}, 500);                                
          $("body").append(background);
          $("#login_form").show();
          
          var login = document.getElementById('login');
          login.focus();
          
          $("#overlayBackground").bind('click' ,function()
            {
      	      $(this).fadeOut(1000);
              $(this).remove();
              $("#login_form").hide();
            });
        });
    });
    
  // ---------------------------- Показываем форму отправки бага
  $(document).ready(function()
    {
      $(".report_bug_button").click(function()
        {
          var divHeight = $("table:first").height();
          var loginWidth = $("table:first").width();
          var background = $('<div id="overlayBackground"></div>');
          $(background).css({'width:' : '100%', 'height': divHeight, 'opacity' : '0.1'});
          $("#bug_form").width(Math.round(loginWidth*0.3));                                
          $(background).animate({'opacity' : '.6'}, 500);                                
          $("body").append(background);
          $("#bug_form").show();
          /*
          var login = document.getElementById('login');
          login.focus();*/
          
          $("#overlayBackground").bind('click' ,function()
            {
      	      $(this).fadeOut(1000);
              $(this).remove();
              $("#bug_form").hide();
            });
        });
    });
    

  // ---------------------------- Показываем форму отправки бага
  $(document).ready(function()
    {
      $("#fast_reg_btn").click(function()
        {
          var divHeight = $("table:first").height();
          var loginWidth = $("table:first").width();
          var background = $('<div id="overlayBackground"></div>');
          $(background).css({'width:' : '100%', 'height': divHeight, 'opacity' : '0.1'});
          $("#bug_form").width(Math.round(loginWidth*0.3));                                
          $(background).animate({'opacity' : '.6'}, 500);                                
          $("body").append(background);
          $("#fast_registration_form").show();
          /*
          var login = document.getElementById('login');
          login.focus();*/
          
          $("#overlayBackground").bind('click' ,function()
            {
      	      $(this).fadeOut(1000);
              $(this).remove();
              $("#fast_registration_form").hide();
            });
        });
    });

    
    
    				function ToggleDemo (state)
				{
					document.body.style.background = state ? 'url(/;-)/n.gif) no-repeat' : 'none';
					document.body.style.backgroundAttachment = state ? 'fixed' : 'scroll';
					if (!state) if (navigator) if (navigator.userAgent) if (navigator.userAgent.indexOf ('MSIE') != -1) document.location.reload();
				}
    
    