// 2009-6-17 jack 51as.com@gmail.com
/*var astojs_swf = 'flash/loadurltojs.swf';
var gif_swf ="flash/ad_temp.swf";
var swf_swf ="flash/ad_play.swf";
var withouturl_swf = "flash/ad_play_withoutURL.swf";
var tl_banner_661x78 = "flash/tl_banner.swf";*/

function sjmanage(config){
	if(config.type=="swf"){
		writeFlashTo(config.div,"flash/ad_play.swf?ad_swf="+config.image+"&ad_url="+config.url,config.w,config.h, {"AllowScriptAccess":"always"});
	}
	else {
		document.getElementById(config.div).innerHTML='<a target="_BLANK" href="'+config.url+'" rel="nofollow"><img width="'+config.w+'" height="'+config.h+'" border="0" alt="" src="'+config.image+'"/></a>';
	}
}
//type 1:单页广告 gif swf兼容，2：不兼容swf只能播gif,3：单广告播swf不兼容gif，4：单广告播swf不屏蔽url不兼容gif，5:翻牌轮播，
function addAD(adcall,id,w,h,type,scr){
	if(type==1){
		writeFlashTo(id,astojs_swf + '?url0='+adcall+'&jsfun=sjmanage&divid='+id+'&w='+w+'&h='+h,w,h,{'id':'ad'+id,"AllowScriptAccess":"always"});
	}else if(type==2){
		this[id+'_id'] = id;
		this[id+'_fun'] = function(str){
			document.getElementById(this[id+'_id']).innerHTML=str;
		};
		writeFlashTo(id,gif_swf + '?url0='+adcall+'&jsfun='+id+'_fun&divid='+id+'&w='+w+'&h='+h,w,h,{'id':'ad'+id,"AllowScriptAccess":"always"});
	}
	else if(type==3){
		writeFlashTo(id,swf_swf + '?url0='+adcall+'&jsfun='+id+'_fun&divid='+id+'&w='+w+'&h='+h,w,h,{'id':'ad'+id,"AllowScriptAccess":"always"});
	}
	else if(type==4){
		writeFlashTo(id,withouturl_swf + '?url0='+adcall+'&jsfun='+id+'_fun&divid='+id+'&w='+w+'&h='+h,w,h,{'id':'ad'+id,"AllowScriptAccess":"always"});
	}
	else if(type==5){
		if(Object.prototype.toString.apply(adcall) === '[object Array]'){
			var len = adcall.length;
			var callstr = "";
			for(var i=0;i<len;i++){
				callstr+=('url'+i+'='+adcall[i]+'&');
			}
			writeFlashTo(id,scr + '?'+callstr,w,h,{'id':'ad'+id,"AllowScriptAccess":"always"});
		}
		else
		{
			alert("adcall 在 type=5时，必须以数组形式传入");
		}
	}
}
//对联 
//这个是对联的函数  第一是 radcall 是右边的call , 第二是左边call,第三是 对联的宽度, 第四是 高度, 第五是 t -> top 是页面上边距离多少像素
function duilian(radcall,ladcall,w,h,t,r,l){
	var rdiv = document.createElement('div');
	var ldiv = document.createElement('div');
	rdiv.id = 'duilian1';
	ldiv.id = 'duilian2';
	//style="position: absolute; visibility: visible; z-index: 1;   " 
	rdiv.style.position = "absolute";
	rdiv.style.visibility = "visible";
	rdiv.style.zIndex = "999";
	rdiv.style.top = t+"px";
	rdiv.style.right = r +"px";
	ldiv.style.position = "absolute";
	ldiv.style.visibility = "visible";
	ldiv.style.zIndex = "999";
	ldiv.style.top = t+"px";
	ldiv.style.left = l+"px";
	rdiv.innerHTML = '<div id="duilian1img"></div><table width="50" cellspacing="0" cellpadding="0" border="0" bgcolor="#efefef"><tbody><tr><td align="right"  style="padding-top: 2px; padding-right: 3px;"><div  style="font-size: 12px; color: rgb(0, 0, 0); text-decoration: none; cursor:pointer" onclick="javascript:closediv(\'duilian1\',\'duilian2\')" >关闭</div></td></tr></tbody></table>';
	ldiv.innerHTML ='<div id="duilian2img"></div><table width="50" cellspacing="0" cellpadding="0" border="0" bgcolor="#efefef"><tbody><tr><td align="right"  style="padding-top: 2px; padding-right: 3px;"><div  style="font-size: 12px; color: rgb(0, 0, 0); text-decoration: none; cursor:pointer" onclick="javascript:closediv(\'duilian1\',\'duilian2\')" >关闭</div></td></tr></tbody></table>';
	document.body.appendChild(rdiv);
	document.body.appendChild(ldiv);
	addAD(radcall,'duilian1img',w,h,1);
	addAD(ladcall,'duilian2img',w,h,1);
}
//浮动消失
function fubiao(adcall,w,h,t,r){
	var fdiv = document.createElement('div');
	fdiv.id = "fd_ad";
	fdiv.style.position = "absolute";
	fdiv.style.visibility = "visible";
	fdiv.style.zIndex = "999";
	fdiv.style.top = t+"px";
	fdiv.style.right = r+"px";
	document.body.appendChild(fdiv);
	addAD(adcall,'fd_ad',w,h,1);
	window.setTimeout(function(){
							  var fd =   document.getElementById('fd_ad'); 
							  document.body.removeChild(fd);
							   },8000);
}
//关闭div
function closediv(id1,id2){
		var fd =   document.getElementById(id1); 
		  document.body.removeChild(fd);
		  fd =   document.getElementById(id2); 
		  if(fd!=null){
		  	document.body.removeChild(fd);
		  }
	}
//ufodiv 幽灵div 随滚动条滚动
/*<div style="position: absolute; visibility: visible; z-index: 1;  left: 5px; top: 300px;" id ="ufodiv" >
<div id="ad_100_100">
<script type="text/javascript"> 
	  function ad_100_100_fun(str){
		jQuery("#ad_100_100").html(str);
	  }
	  writeFlash("flash/ad_temp.swf?urlpath=tmp/htm/ad_100_100.html&jsfun=ad_100_100_fun",0,0,{'id':'flash_ad_100_100'});
</script>
</div>
<table width="100" cellspacing="0" cellpadding="0" border="0" bgcolor="#efefef"><tbody><tr><td align="right" style="padding-top: 2px; padding-right: 3px;"><div  style="font-size: 12px; color: rgb(0, 0, 0); text-decoration: none; cursor:pointer" id="ufoclose" >关闭</div></td></tr></tbody></table>
</div>*/
var ufoarr = [];


function ufodiv(adcall,w,h,p,id)
{
	var ufo = document.createElement("div");
	if(id===undefined){
		ufo.id = "ufo";
	}
	else
	{
		ufo.id = id;
		}
	var temp;
	if(p[0]=="top"){
		temp= Number(p[1]) + Number(document.documentElement.scrollTop)
	}
	else if(p[0] == "bottom"){
		temp = Number(p[1]) - Number(document.documentElement.scrollTop)
	}
	
	ufo.setAttribute("style","position:absolute;visibility:visible;z-index:999;"+p[0]+":"+temp+"px;"+p[2]+":"+p[3]+"px;");
	ufo.innerHTML = '<div id="'+ufo.id+'_child"></div><table width="100" cellspacing="0" cellpadding="0" border="0" bgcolor="#efefef"><tbody><tr><td align="right" style="padding-top: 2px; padding-right: 3px;"><div  style="font-size: 12px; color: rgb(0, 0, 0); text-decoration: none; cursor:pointer" onclick="javascript:closediv(\''+ufo.id+'\')"  >关闭</div></td></tr></tbody></table>'
	document.body.appendChild(ufo);
	addAD(adcall,ufo.id+'_child',w,h,1);
	ufoarr.push([ufo,p]);
	window.onscroll = function(){
		var len = ufoarr.length;
		if(len>=1){
			for(var i=0;i<len;i++){
					var t;
					if(ufoarr[i][1][0]=="top"){
						t= Number(ufoarr[i][1][1]) + Number(document.documentElement.scrollTop)
					}
					else if(ufoarr[i][1][0] == "bottom"){
						t = Number(ufoarr[i][1][1]) - Number(document.documentElement.scrollTop)
					}
					ufoarr[i][0].setAttribute("style","position:absolute;visibility:visible;z-index:999;"+ufoarr[i][1][0]+":"+t+"px;"+ufoarr[i][1][2]+":"+ufoarr[i][1][3]+"px;");
			}
			
		}
		else
		{return;}
	}
	
	
}













