confirmation box increments on each page refresh.

confirmation box increments on each page refresh.

Hey guys,

   I must have something wrong in my code or something.. for some reason when I try to delete a post before
the page refreshes than all is good, but after the page refreshes the confirmation logs it twice. here is my code.

  1.  var refreshSpeed = 8000;
     var intValID = 0;
     var KEYCODE_ENTER = 13;
     var KEYCODE_ESC   = 27;

     var c_hashid  = new Array (),
         r_hashid   = new Array ();
     
     function loadComments ()
     {     
        $.ajax ({
             url:  "postComments.php",
             type: "post",
             cache: false,
             dataType: "json",
             data: {type: "getComments"},
             success: function (d) {
                var c = [];
                var r = [];
               
                //Check for new post, update page.
                $(d.results.com).each (function (k, v) {
                    if ($("#showComments").find ("div#"+$(v).attr ("id")).length == 0) {
                        $("#showComments").prepend (v).fadeIn ("slow");
                    }
                    c.push ($(v).attr ("id"));
                   
                    if ($.inArray ($(v).attr ("id"), c_hashid) == -1) {
                        c_hashid.push ($(v).attr ("id"));
                    }
                });
               
                //check for new replies, update page.
                $(d.results.rep).each (function (e, k) {
                    var rid = $(k).attr ("id").split ('_r')[0];
                     if ($("#showComments").find ("div#"+rid).attr ("id").length > 0) {
                            if ($("#showComments").find ("div#"+$(k).attr ("id")).length == 0) {
                            var n = rid.replace ("postinfo_", "comments_");
                            $(k).appendTo ($("div#"+n)).fadeIn;
                        }
                       
                        r.push ($(k).attr ("id"));
                   
                        if ($.inArray ($(k).attr ("id"), r_hashid) == -1) {
                            r_hashid.push ($(k).attr ("id"));
                        }
                     }
                });
               
                remove_deleted (c_hashid, c); //remove post
                remove_deleted (r_hashid, r); //remove replies
                //start_timer ();
                optionBttn ();
                return false;
             }
             
        });     
     }
     
     function remove_deleted (ids, r)
     {
          stop_timer ();
         
          $.each (ids, function (k, v){
              if ($.inArray (v, r) == -1) {
                  $("#showComments").find ("div#"+v).slideUp ("slow");
              }
          });
     }
       
     function play_video ()
     {
        $(".ytpreview").live ("click",function () {
            var yt_ar = $(this).children ('img').attr ('src').split ("/");
            var yt_id = yt_ar.length - 2;
            $(this).html ("<iframe width='400' height='250' src='http://www.youtube.com/embed/" + yt_ar [yt_id] + "?t &autoplay=1' frameborder='0' allowfullscreen></iframe>");
        });
       
        submitPost ();
     }
     
     function submitPost ()
     {
         $("#cbutton").click (function (e)
        {
            stop_timer ();
       
            $.ajax ({
              url:  "postComments.php",
              type: "post",
              cache: false,
              dataType: "json",
              data: {type: "postComment", cbox:  $("#cbox").val()},
              success: function (d) {
                  $.growlUI ('Your Message has been Posted', 'Updating, please wait..');
                  $("#cbox").val('');
                  $("#countdown").html ('255');
                  $("#cbutton").attr("disabled", "disabled");
                  start_timer ();
              }
            });   
           
            return false;
        });
     }
     
     function deletePost ()
     {
            $("[class^=delete_]").each (function () {
                $(this).on("click", function (e) {
                    stop_timer ();
                   
                     if (confirm ("Are you sure you want to delete this post?")) {
                        console.log ($(this).attr ("class"));
                        e.preventDefault ();
                        start_timer ();
                    }
                   
                    $(this).unbind ("click");
                    $(this).die ();
                });
            });
            /*
            $("[class^=delete]").on ("click",function () {
                $('.c_button').attr ("id");
                if (confirm ("Are you sure you want to delete this post?")) {
                    var ph = $(this).attr ("class").split ("_");
                    console.log ($('[id^=c_button]').attr ("class"));
                    /*
                    $.ajax ({
                        type: "post",
                        url:  "postComments.php",
                        cache: false,
                        dataType: "json",
                        data:  {type: "deletePost", phash: ph[1]},
                        success: function () {
                            $("#postinfo_"+ph[1]).empty ().remove ();
                           
                            loadComments ();
                        }
                    }); 
                   
                    $(this).die ("click");
                }else{
                    $(this).die ("click");
                    return false;
                }
            }); */
     }
     
     function optionBttn ()
     {
         $("[class^=reply_]").each (function () {
            $(this).on ("click", function () {
                var boxid = $(this).attr ("class").split ("_")[1];
               
                if ($(".replybox_"+boxid).is (":hidden")) {
                    $('.replybox_'+boxid).show ();
                }
               
                $("div[class^=replybox_]").each (function ()
                {
                    if ($(this).attr ("class") != "replybox_"+boxid)
                    {    console.log ($(this).attr ("id"));
                        $(this).slideUp ("fast");
                    }
                });

            });
         });
         deletePost ();
         start_timer ();
     }
     
     function textAreaAnim ()
     {       
        $("#cbox").focus (function ()
        {   
            $("div[id^=rcommentBox]").slideUp ("slow");
           
            $(this).animate ({height: 100}, 100, "linear");   
           
            //textAreaListen ($(this));
           
            $(this).keyup (function ()
            {
                var left = 255 - $(this).val ().length;
                       
                if ($(this).val ().length >= 5) {
                    $("#cbutton").removeAttr("disabled");
                }
               
                if (left < 10) {
                    $("#countdown").css ("color", "red");
                  
                }else{
               
                    $("#countdown").css ("color", "gray");
                }
               
                $("#countdown").html(left);
            });
        });

        $("#cbox").blur (function () {
            $(this).animate ({"height": 20}, 60, "swing");
        });
     }
     
     function textAreaListen ($obj)
     {     
         $obj.keydown (function (e)
         {
            if (e.keyCode == 32 || e.charCode == 32) {
                var t_content = $obj.val ();
                var t_urls = t_content.match (/https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?/);
               
                $('#ajax_flag').val (0);
       
                console.log (t_urls ['input']);
                if (t_urls != null) {
                    if (t_urls.length > 0 &&  $('#ajax_flag').val () == 0) {
                        $('#showthumb').html ('<img src='+t_urls['input']+'>');
                    }
                }
            }
         });
     }
     
     function start_timer () {
         intValID = setTimeout (function () {
                        loadComments();
         }, refreshSpeed);
     }
     
     function stop_timer () {
        clearTimeout (intValID);
     }
     
     $(document).ready (function ()
     {
         $("#cbutton").attr("disabled", "disabled");
         
         $(document).mouseup (function (e)
         {
             if ($("#layerOne").has (e.target).length === 0)
             {
                $("div[id^=replybox]").fadeOut ("fast");
             }
         });
         
         loadComments ();
         textAreaAnim ();
         play_video ();
     });
































































































































































































































































 you can see what I am talking about at... http://xlordt.linuxsecured.net/mfwall/ now I am still fairly new to jquery, been reading and updating my self on this everyday each day hour after hour. also any changes to make this code better viewable would be a +. thanx.