// JavaScript Document


;(function($) {
	$ieframe = $('<iframe class="popupwinieframe" frameborder="0" src="#"></iframe>').css({ position: "absolute", display: "none", zIndex: -1,"overflow":"hidden"});
	jQuery.msgbox={ //弹出窗口
	confirmbox:function(id,title,content,leftto,topto){
		var popwinstr="<div id=\"" + id + "\" class=\"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(id);
		
		$("#container").before(popwinstr.replace("$content",content).replace("$title",title));
		$("#"+id).prepend($ieframe);
		$("#close").click(function(){
								   $.msgbox.closemsgbox(id);
								   })
		tablewidth=$("#"+id+" > .border > #content > table").width()+16;
		$ieframe.css({height:($("#"+id).height())+"px",width:($("#"+id).width())+"px"});
		$ieframe.show();
		$("#"+id).css({"left":leftto+"px","top":topto+"px","position":"absolute","width":tablewidth+"px"});
		$("#"+id).click(function(){
								 var maxzindex=10000;
								 $(".popwincontainer").each(function(){
																		if ($(this).css("z-index")/1 > maxzindex) maxzindex=$(this).css("z-index")/1+1;
																	 })
								 $(this).css("z-index",maxzindex/1+100);
								 })		
		$("#"+id).draggable({cursor:"move",revert: false,ghosting: true, opacity: 0.7,handle:"#"+id});

		return $("#"+id);
		
		},
	msgbox:function(id,width,height,title,content,rezindex){
		
		var popwinstr="<div id=\"" + id + "\"  class=\"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(id);
		$("#container").before(popwinstr.replace("$title",title).replace("$content",content));
		$("#"+id).prepend(this.ieframe);
		$("#"+id+" > .border > #title > #close").click(function(){
															   $.msgbox.closemsgbox(id);
															   })
		this.ieframe.css({height:(height/1+2)+"px",width:(width/1+2)+"px"});
		$("#"+id).css({height:(height/1+2)+"px",width:(width/1+24)+"px"});
		$("#"+id+" > .border").css({height:(height/1)+"px",width:(width/1)+"px"});
		this.ieframe.show();		
		$("#"+id+" > .border > #content").css({height:(height/1-35)+"px",width:(width/1-10)+"px"});
		scrolltop=$(window).scrollTop()
		leftto=$("#"+id).offset().left-(width/2);
		if (($(window).height()/2) > (height/2)) {
			topto=$("#"+id).offset().top-(height/2);
		}else{
			topto=$(window).height()/2;//-((height/2) - ((height/2) - (document.body.clientHeight/2)));
		}		
		topto=(topto+scrolltop);
		$("#"+id).css({"left":leftto+"px","top":topto+"px","position":"absolute"});
		
		if (rezindex){
			$("#"+id).click(function(){
									 //alert($(this).css("z-index"));
									 var maxzindex=10000;
									 $(".popwincontainer").each(function(){
																			if ($(this).css("z-index")/1 > maxzindex) maxzindex=$(this).css("z-index")/1+1;
																		 })
									 $(this).css("z-index",maxzindex/1+1);
									 })
			}		
		
		$("#"+id).draggable({cursor:"move",revert: false,ghosting: true, opacity: 0.7,handle:"#title"});//#"+id+" > 
 
		return $("#"+id);
		
		},		
	popupwin:function(id,width,height,title,content,rezindex){
		var popwinstr="<div id=\"" + id + "\"  class=\"popwincontainer\">";//<div id=\"header\"></div>
		popwinstr+="<div class=\"border\"><div id=\"title\"><a id=\"close\" href=\"#\" title=\"关闭\">X</a>$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(id);
		$("#container").before(popwinstr.replace("$title",title).replace("$content",content));
		$("#"+id).prepend($ieframe);
		$("#"+id+" > .border > #title > #close").click(function(){
															   $.msgbox.closemsgbox(id);return false;
															   })
		
		
		if (rezindex){
			$("#"+id).click(function(){
									 //alert($(this).css("z-index"));
									 var maxzindex=10000;
									 $(".popwincontainer").each(function(){
																			if ($(this).css("z-index")/1 > maxzindex) maxzindex=$(this).css("z-index")/1+1;
																		 })
									 $(this).css("z-index",maxzindex/1+1);
									 })
			}

		
		
		$("#"+id).draggable({cursor:"move",revert: false,ghosting: true, opacity: 0.7,handle:"#title"});
		$ieframe.show();
 					
		
		//取得内容具体的宽高
		innerheight=$("#"+id+" > .border > #content > table").height()+34;

		//宽未定义
		innerwidth=$("#"+id+" > .border > #content > table").width()+16;		
		
		//alert(innerwidth +" - " +width)height=innerheight;//
		height=height<innerheight?innerheight:height;
		//width=width>innerwidth?width:innerwidth;
		
		$("#"+id+" > .border > #content > table").css({height:(height/1)+"px",width:(width/1-2)+"px"});
	
		$ieframe.css({height:(height/1+2)+"px",width:(width/1+2)+"px"});
		$("#"+id).css({height:(height/1+2)+"px",width:(width/1+2)+"px"});
		$("#"+id+" > .border").css({height:(height/1)+"px",width:(width/1)+"px"});
		

		scrolltop=$(window).scrollTop()
		leftto=$("#"+id).offset().left-(width/2);
		if (($(window).height()/2) > (height/2)) {
			topto=$("#"+id).offset().top-(height/2);
		}else{
			topto=$(window).height()/2;//-((height/2) - ((height/2) - (document.body.clientHeight/2)));
		}		
		topto=(topto+scrolltop);
		$("#"+id).css({"left":leftto+"px","top":topto+"px","position":"absolute"});
		//this.ieframe.css({"left":leftto+"px","top":topto+"px","position":"absolute"});
		
		//$("#"+id).animate({opacity:1},3000);.popwincontainer > 

		return $("#"+id);
	 
		},
	closemsgbox:function(id,time,callbackfunction){
		//$("#"+id).animate({opacity:0},2000,function(){$("#"+id).remove()})//.remove()
		if (time){
			//window.setTimeout('$("#"+id).hide("fast",'+callbackfunction+').remove()',time)
			window.setTimeout(function(){$("#"+id).hide("fast",callbackfunction).remove()},time)
			}
		else{
			$("#"+id).remove();
			}
		
		},
	resizemsgbox:function(msgbox){
		
		}
	
	}
})(jQuery);
