1 var dialogFirst=true;
 2 
 3 function dialog(title,content,width,height,cssName){
 4     if(dialogFirst==true){
 5         var temp_float=new String;
 6         temp_float = "<div id=\"floatBoxBg\" style=\"height:"+$(document).height()+"px;filter:alpha(opacity=0.5);-moz-opacity:0.5;\"></div>";
 7         temp_float+= "<div id=\"floatBox\" class=\"floatBox\">";
 8         temp_float+= "   <div class=\"title\"><h4></h4><a><img src='images/close.gif'></a></div>";
 9         temp_float+= "   <div class=\"content\"></div>";
10         temp_float+= "</div>";
11         $("body").append(temp_float);
12         dialogFirst=false;
13     }
14 
15     $("#floatBox .title a").click(function(){
16         $("#floatBoxBg").animate({opacity:"0"},"normal",function(){$(this).hide();});
17         $("#floatBox").animate({top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)))+"px"},"normal",function(){$(this).hide();}); 
18 
19         //fixed hit it more and it not popup the windows error
20         var floatBox = document.getElementById("floatBox");
21         window.document.body.removeChild(floatBox);
22         var floatBoxBg = document.getElementById("floatBoxBg");
23         window.document.body.removeChild(floatBoxBg);
24         dialogFirst=true;
25     });
26 
27     $("#floatBox .title h4").html(title);
28     contentType=content.substring(0,content.indexOf(":"));
29     content=content.substring(content.indexOf(":")+1,content.length);
30     switch(contentType){
31         case "url":
32             var content_array=content.split("?");
33             $("#floatBox .content").ajaxStart(function(){
34                 $(this).html("loading。。。。。。<img src='images/loading.gif'>");
35             });
36             $.ajax({
37                 type:content_array[0],
38                 url:content_array[1],
39                 data:content_array[2],
40                 error:function(){ $("#floatBox .content").html("Error..."); },
41                 success:function(html){ $("#floatBox .content").html(html); }
42             });
43             break;
44         case "text":
45             $("#floatBox .content").html(content);
46             break;
47         case "id":
48             $("#floatBox .content").html($("#"+content+"").html());
49             break;
50         case "iframe":
51             $("#floatBox .content").html("<iframe src=\""+content+"\" width=\"100%\" height=\""+(parseInt(height)-30)+"px"+"\" scrolling=\"auto\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>");
52             break;
53     }
54 
55     /* me add line */
56     $("#floatBox").css("top",$(document).scrollTop());
57     $("#floatBox").css("display","block");
58 
59     $("#floatBoxBg").show();
60     $("#floatBoxBg").animate({opacity:"0.5"},"normal");
61     $("#floatBox").attr("class","floatBox "+cssName);
62     $("#floatBox").css({display:"block",left:(($(document).width())/2-(parseInt(width)/2))+"px",top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)))+"px",width:width,height:height});
63     $("#floatBox").animate({top:((document.documentElement.clientHeight-parseInt(height))/2) - 20 + "px"},"normal");
64 }