;(function($) {
	$ieframe = $('<iframe class="popupwinieframe" frameborder="0" src="#"></iframe>').css({ position: "absolute", display: "none", zIndex: -1,"overflow":"hidden"});
	jQuery.msgbox={ //弹出窗口
//	a:$('<iframe class="popupwinieframe" frameborder="0" src="#"></iframe>').css({ position: "absolute", display: "none", zIndex: -1}),
	confirmbox:function(title,content,leftto,topto){
///alert( $ieframea.attr("class"));
		var popwinstr="<div id=\"popwincontainer\">";//<div id=\"header\"></div>
		popwinstr+="<div class=\"border\"><div id=\"content\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td>$content</td></tr></table></div></div></div>";
		$.msgbox.closemsgbox();
		
		//this.ieframe = $('<iframe class="popupPanel_ieframe" frameborder="0" src="#"></iframe>').css({ position: "absolute", display: "none", zIndex: -1});
		$("#container").before(popwinstr.replace("$content",content).replace("$title",title));
		$("#popwincontainer").prepend($ieframe);
		$("#close").click(function(){
								   $.msgbox.closemsgbox();
								   })
		tablewidth=$("#popwincontainer > .border > #content > table").width()+16;
		$ieframe.css({height:($("#popwincontainer").height())+"px",width:($("#popwincontainer").width())+"px"});
		$ieframe.show();
		$("#popwincontainer").css({"left":leftto+"px","top":topto+"px","position":"absolute","width":tablewidth+"px"});
		$("#popwincontainer").draggable({cursor:"move",revert: false,ghosting: true, opacity: 0.7,handle:"#popwincontainer"});
		return $("#popwincontainer");
		
		},
	msgbox:function(width,height,title,content){
		
		var popwinstr="<div id=\"popwincontainer\">";//<div id=\"header\"></div>
		popwinstr+="<div class=\"border\"><div id=\"title\"><span id=\"close\" title=\"关闭\">X</span>$title</div>";
		popwinstr+="<div id=\"content\"><table style=\"width:100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td align=\"center\" valign=\"middle\">$content</td></tr></table></div></div></div>";
		this.ieframe = $('<iframe class="popupPanel_ieframe" frameborder="0" src="#"></iframe>').css({ position: "absolute", display: "none", zIndex: -1});
		$.msgbox.closemsgbox();
		$("#container").before(popwinstr.replace("$title",title).replace("$content",content));
		$("#popwincontainer").prepend(this.ieframe);
		$("#popwincontainer > .border > #title > #close").click(function(){
															   $.msgbox.closemsgbox();
															   })
		this.ieframe.css({height:(height/1+4)+"px",width:(width/1+4)+"px"});
		$("#popwincontainer").css({height:(height/1+4)+"px",width:(width/1+4)+"px"});
		$("#popwincontainer > .border").css({height:(height/1)+"px",width:(width/1)+"px"});
		this.ieframe.show();		
		$("#popwincontainer > .border > #content").css({height:(height/1-35)+"px",width:(width/1-10)+"px"});
		//$("#popwincontainer > #content > table").css({height:(height/1-65)+"px"});
		scrolltop=$(window).scrollTop()
		leftto=$("#popwincontainer").offset().left-(width/2);
		if (($(window).height()/2) > (height/2)) {
			topto=$("#popwincontainer").offset().top-(height/2);
		}else{
			topto=$(window).height()/2;//-((height/2) - ((height/2) - (document.body.clientHeight/2)));
		}		
		topto=(topto+scrolltop);
		$("#popwincontainer").css({"left":leftto+"px","top":topto+"px","position":"absolute"});
		//$("#popwincontainer").animate({opacity:1},3000);
		$("#popwincontainer").draggable({cursor:"move",revert: false,ghosting: true, opacity: 0.7,handle:"#popwincontainer > #title"});
		return $("#popwincontainer");
		
		},		
	popupwin:function(width,height,title,content){
		var popwinstr="<div id=\"popwincontainer\">";//<div id=\"header\"></div>
		popwinstr+="<div class=\"border\"><div id=\"title\"><span id=\"close\" title=\"关闭\">X</span>$title</div>";
		popwinstr+="<div id=\"content\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td align=\"center\" valign=\"top\">$content</td></tr></table></div></div></div>";	//<div id=\"footer\"></div>
		this.ieframe = $('<iframe class="popupPanel_ieframe" frameborder="0" src="#"></iframe>').css({ position: "absolute", display: "none", zIndex: -1});
		
		$.msgbox.closemsgbox();
		$("#container").before(popwinstr.replace("$title",title).replace("$content",content));
		$("#popwincontainer").prepend($ieframe);
		$("#popwincontainer > .border > #title > #close").click(function(){
															   $.msgbox.closemsgbox();
															   })
		
		//$("#popwincontainer > #content").css({height:(height/1-54)+"px",width:(width/1-10)+"px"});
		
		

		
//		//表格内写内容读取中
//		
//		//判断是否有图片
//		
//		var $imgs=$("#popwincontainer").find("img");
//		var imglength=$imgs.length;
//		var loadedimgs=0;
//		//判断图片是否读取完成
//		$("#txtcomment").val( $("#txtcomment").val() + "\n 需要加载的图片数量 " +imglength)				
//		for (i=0;i<imglength;i++){
//			$("#txtcomment").val( $("#txtcomment").val() + "\n" +$imgs.eq(i).attr("src")+"加载中.....")
//			var img=new Image();
//			img.src=$imgs.eq(i).attr("src");
//			
//			if (img.complete){
//				$("#txtcomment").val( $("#txtcomment").val() + "\n" +$imgs.eq(i).attr("src")+"已经加载过！直接显示")
//				loadedimgs = loadedimgs + 1;
//				if (loadedimgs == imglength){
//					$("#txtcomment").val(  $("#txtcomment").val() + "\n" + " 全部图片已经预读，调整弹出层的数据！");
//					}
//				}
//			else{
//				$(img).load(function(){
//										   loadedimgs = loadedimgs + 1;
//										   
//										   $("#txtcomment").val( $("#txtcomment").val() + "\n" +$(this).attr("src")+" 加载完毕 " +loadedimgs+"  || " + (loadedimgs == imglength))						   
//										   
//										   if (loadedimgs == imglength){
//											   $("#txtcomment").val(  $("#txtcomment").val() + "\n" + " 全部图片加载完全，调整弹出层的数据！");
//											   $("#txtcomment").val(  $("#txtcomment").val() + "\n" + " #popwincontainer"+ $("#popwincontainer").height())									
//											   $("#txtcomment").val(  $("#txtcomment").val() + "\n" + " #popwincontainer > .border > #content > table "+ $("#popwincontainer > .border > #content > table").height())
//											   } 
//										   });
//				}
//			
//
//			
//			}
		
		
		
 
		
		
		$("#popwincontainer").draggable({cursor:"move",revert: false,ghosting: true, opacity: 0.7,handle:"#title"});
		$ieframe.show();
 
											
											
		
		//取得内容具体的宽高
		innerheight=$("#popwincontainer > .border > #content > table").height()+34;
//		if (height<innerheight){
//			height=innerheight+34;
//			}
		//宽未定义
		innerwidth=$("#popwincontainer > .border > #content > table").width()+16;		
		
		
		height=innerheight;//height<innerheight?innerheight:height;
		width=width>innerwidth?width:innerwidth;
		
		$("#popwincontainer > .border > #content > table").css({height:(height/1)+"px",width:(width/1-12)+"px"});
	
		$ieframe.css({height:(height/1+4)+"px",width:(width/1+4)+"px"});
		$("#popwincontainer").css({height:(height/1+4)+"px",width:(width/1+4)+"px"});
		$("#popwincontainer > .border").css({height:(height/1)+"px",width:(width/1)+"px"});
		
		
		
		
//		marginleft=-(width/2);
//		if (($(window).height()/2) > (height/2)) {
//			marginto=-(height/2);
//		}else{
//			marginto=-($(window).height()/2);//-((height/2) - ((height/2) - (document.body.clientHeight/2)));
//		}	
		scrolltop=$(window).scrollTop()
		leftto=$("#popwincontainer").offset().left-(width/2);
		if (($(window).height()/2) > (height/2)) {
			topto=$("#popwincontainer").offset().top-(height/2);
		}else{
			topto=$(window).height()/2;//-((height/2) - ((height/2) - (document.body.clientHeight/2)));
		}		
		topto=(topto+scrolltop);
		$("#popwincontainer").css({"left":leftto+"px","top":topto+"px","position":"absolute"});
		//this.ieframe.css({"left":leftto+"px","top":topto+"px","position":"absolute"});
		
		//$("#popwincontainer").animate({opacity:1},3000);#popwincontainer > 
		
		return $("#popwincontainer");
	 
		},
	closemsgbox:function(time,callbackfunction){
		//$("#popwincontainer").animate({opacity:0},2000,function(){$("#popwincontainer").remove()})//.remove()
		if (time){
			//window.setTimeout('$("#popwincontainer").hide("fast",'+callbackfunction+').remove()',time)
			window.setTimeout(function(){$("#popwincontainer").hide("fast",callbackfunction).remove()},time)
			}
		else{
			$("#popwincontainer").remove();
			}
		
		},
	resizemsgbox:function(msgbox){
		
		}
	
	}
})(jQuery);
