// Lee dialog 1.0 http://www.xij.cn/blog/?p=68

var divW;	//DIV宽度
//var divH;	//DIV高度

function dialog(title,content,width,height,cssName){
	if($(document).scrollTop()<100)
		window.scroll(0,100);
	
	divW=width;
  var temp_float=new String;
  temp_float="<div id=\"floatBoxBg\" style=\"height:"+$(document).height()+"px;filter:alpha(opacity=0);opacity:0;z-index:100\"></div>";
  temp_float+="<div id=\"floatBox\" class=\"floatBox\" style=\"z-index:200\">";
  temp_float+="<div class=\"title\"><h4></h4><img src='images/Close-1.gif' id='x' /></div>";
  temp_float+="<div class=\"content\"></div>";
  temp_float+="</div>";
  $("body").append(temp_float);
  
//交换X图片
	$("#x").hover(
		function(){
			$(this).attr("src","images/Close-2.gif");
		},
		function(){
			$(this).attr("src","images/Close-1.gif");
		}
	);

$("#x").click(function(){
  $("#floatBoxBg").animate({opacity:"0"},"normal",function(){$(this).remove();});
  $("#floatBox").animate({top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)))+"px"},"normal",function(){$(this).remove();}); 
});

$("#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.5"},"normal");
$("#floatBox").attr("class","floatBox "+cssName);
$("#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});

$("#floatBox").animate({top:($(document).scrollTop()+(($(window).height()<parseInt(height))?0:($(window).height()-parseInt(height))/2))+"px"},"normal"); 

$("#floatBox").easydrag(); 
$("#floatBox").setHandler("#floatBox .title");
}

//清除DIV窗口
function clearDivWindow(){
	$("#floatBoxBg").remove();
	$("#floatBox").remove();
}

//窗口大小改变时
$(window).resize(
		function(){
			$("#floatBox").css("left",((($(window).width())/2-(parseInt(divW)/2))+"px"));
			
		}
);

