/*
QQ:260912391	王健
弹出层
dialog(title,content,width,height,cssName)
dialog('弹出来的内容','text:看一看如何！','270px','auto',"text")
顺序				参数	 
1 title			弹出层的标题 必填，纯文本 
2 content		弹出层的内容 
	:url		get或post某一页面里的html，该页面要求只包含body的子标签 
	:text		直接写入内容 
	:id			显示页面里某id的子标签 
	:iframe		层内内容以框架显示 
3 width			弹出层的宽 必填，css值，比如“200px” 
4 height		弹出层的高 如上，但是可用“auto” 
5 cssName		弹出层的css 给id floatBox加入的样式名，层内样式可以通过这个样式名来定制 

所需要的CSS

#floatBoxBg{display:none;width:100%;height:100%;background:#000;position:absolute;top:0;left:0;}
.floatBox{border:#666 5px solid;width:300px;position:absolute;top:50px;left:40%;}
.floatBox .title{height:23px;padding:7px 10px 0;background:#333;color:#fff;}
.floatBox .title h4{float:left;padding:0;margin:0;font-size:14px;line-height:16px;color:#fff}
.floatBox .title span{float:right;cursor:pointer;}
.floatBox .content{padding:2px 2px;background:#fff;}

*/
var dialogFirst=true;
function dialog(title,content,width,height,cssName){

if(dialogFirst==true){
  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>关闭</span></div>";
  temp_float+="<div class=\"content\"></div>";
  temp_float+="<div class=\"adtitle\"><a href=\"http://www.maicai.cn/BuyFunction.php\"  style=\"color:#fff;text-decoration:none;\" target=\"_blank\">黄金广告位招租，联系电话：028-89838838</a></div></div>";
  $("body").append(temp_float);
  dialogFirst=false;
}

$("#floatBox .title span").click(function(){
closedialog();
});


function closedialog() {
  $("#floatBoxBg").animate({opacity:"0"},"normal",function(){$(this).hide();}); $("#floatBox").animate({top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)))+"px"},"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.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()+80)+"px"},"normal"); 
}
