function dialog(title,content,width,height,cssName){
	if($('#floatBoxBg').html() == null){
		var temp_float=new String;
		temp_float="<div id=\"floatBoxBg\" style=\"height:"+$(document).height()+"px;filter:alpha(opacity=0);opacity:0;\"></div>";
		temp_float+="<div id=\"floatBox\" class=\"floatBox\">";
		temp_float+="<div class=\"title\"><h4></h4><span>close</span></div>";
		temp_float+="<div class=\"content\"></div>";
		temp_float+="</div>";
		$("body").append(temp_float);
	}
	
	$("#floatBox .title span").click(function(){
		$("#floatBox").animate({top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)))+"px",width:0,height:0},600,function(){$(this).hide();});
		$("#floatBoxBg").animate({opacity:"0"},"normal",function(){$(this).hide();});
	});

	$("#floatBox .title h4").html(title);
	contentType=content.substring(0,content.indexOf(":"));
	content=content.substring(content.indexOf(":")+1,content.length);
	switch(contentType){
		case "url":
		var content_array=content.split("?");
		$("#floatBox .content").ajaxStart(function(){
			$(this).html("loading...");
		});
		$.ajax({
			type:content_array[0],
			url:content_array[1],
			data:content_array[2],
			error:function(){
				$("#floatBox .content").html("error...");
			},
			success:function(html){
				$("#floatBox .content").html(html);
			}
		});
		break;
		case "text":
		$("#floatBox .content").html(content);
		break;
		case "id":
		$("#floatBox .content").html($("#"+content+"").html());
		break;
		case "iframe":
		$("#floatBox .content").html("<iframe src=\""+content+"\" width=\"100%\" height=\""+(parseInt(height)-30)+"px"+"\" scrolling=\"auto\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>");
	}

	$("#floatBoxBg").show();
	$("#floatBoxBg").animate({opacity:"0.9"},"normal");
	$("#floatBox").attr("class","floatBox "+cssName);
	
	
	var scrollTop = 0;
	var scrollLeft = 0;
	var browserWidth = 0;
	var browserHeight = 0;
	
	if(document.documentElement && document.documentElement.scrollTop) {
		scrollTop = document.documentElement.scrollTop;
		scrollLeft = document.documentElement.scrollLeft;
	} else {
		scrollTop = document.body.scrollTop;
		scrollLeft = document.body.scrollLeft;
	}
	
	if(document.documentElement && document.documentElement.clientWidth) {
		browserWidth = document.documentElement.clientWidth;
		browserHeight = document.documentElement.clientHeight;
	} else {
		browserWidth = self.innerWidth;
		browserHeight = self.innerHeight;
	}
	
	var top = scrollTop;
	var left = scrollLeft;

	if(browserHeight > parseInt(height)) {
		top += (browserHeight-(height=="auto"?300:parseInt(height))) / 2 - parseInt($('#floatBox').css('border-top-width'));
	} 
	if(browserWidth > parseInt(width)) {
		left += (browserWidth - parseInt(width)) / 2  - parseInt($('#floatBox').css('border-left-width'));
	}

	$("#floatBox").css({display:"block",left:left+"px",top:scrollTop+'px',width:0,height:0});
	
	$("#floatBox").animate({left:left+"px",top:top+"px",width:width,height:height},"normal");
}

$(function(){
	$("#newsMap").click(function() {
		dialog("Global Times News Map","iframe:http://www.globaltimes.cn/map-china/NewsMap.html","920px","630px","iframe");
	});
});
