var WESAD_DIV="WESAD",WESAD_LOADED=false,WESAD_O1,WESAD_O2,AD,WESAD_Ver="1.0";
var WESAD_S=new Array(),WESAD_RESIZE=new Array();
var WESAD_F="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0";
var WESAD_CE=document.all?1:(document.getElementById?0:-1);

document.write("<div id='"+WESAD_DIV+"'></div>");

function InitSchedule()
{
	WESAD_S.sort(WESAD_sort);

	/* setting indexes for advertisements */
	for(iAI=0;iAI<WESAD_S.length;iAI++)
		WESAD_S[iAI].i=iAI;
}

/**
 * call function for sorting WESAD_S
 * sort advertisements according there position
 */
function WESAD_sort(a,b)
{
	return(a.p>b.p)?1:((a.p==b.p)?0:-1);
}

/**
 * try to call ADTYPE_main() function 
 */
function WESAD_Start(o)
{
	if(eval("typeof("+o.t+"_main)")=="function") 
		eval(o.t+"_main(o)");
}

function DoSchedule()
{
	var p=-1;
	for(dAI=0;dAI<WESAD_S.length;dAI++)
	{
		switch(WESAD_S[dAI].s)
		{
			case 0:
				if(p==-1)
					p=WESAD_S[dAI].p;
				if(p==WESAD_S[dAI].p)
				{
					/* set status to "showing */
					WESAD_S[dAI].s=1;
					/* show it */
					WESAD_Start(WESAD_S[dAI]);
					break;
				}
			case 1:
				setTimeout("DoSchedule()",300);
				return;
			default :
		}
	}
}

/* startup WESAD only if browser support it */
if(WESAD_CE>-1)
{
	window.onload=function WESAD_PUSH()
	{
		if(!WESAD_LOADED)
		{
			WESAD_LOADED=true;
			InitSchedule();
			DoSchedule();
		}
	}
	window.onresize=function()
	{
		for(oAI=0;oAI<WESAD_RESIZE.length;oAI++)
			eval(WESAD_RESIZE[oAI]);
	}
}

function WriteAd(id,s)
{
	var o0=document.getElementById(id);
	if(o0==null)
	{
		o0=document.createElement("div");
		o0.id=id;
		if(WESAD_CE==1)
			document.getElementById(WESAD_DIV).insertAdjacentElement("beforeBegin",o0);
		else 
			document.getElementById(WESAD_DIV).insertBefore(o0,null);
	}
	o0.innerHTML=s;
}

/**
 * put the advertisement into WESAD_S 
 */
function AddSchedule(oo)
{
	if(oo!=null && oo instanceof WESAD)
		WESAD_S[WESAD_S.length]=oo;
}

/**
 * constructor for advertisement
 * @param t string the type of the advertisement
 * @param p integer the position of the advertisement
 */
function WESAD(t,p)
{
	/* type of the AD
	 * types:
	 * BOOKTURN: 
	 * COUPLET: fixed DUI LIAN
	 * FLOAT: like couplet, but can move according to page offset, and left and right can be different
	 * LIUMEITI: display the ad in a fixed position on the page
	 * POPUNDER: popup the ad behind the page
	 * POPUP: popup the ad
	 */
	this.t=t;

	/* position of the AD */
	this.p=p;

	/* status of the AD,
	 * 0 means not shown,
	 * 1 means showing
	 * 2 means closed
	 */
	this.s=0;

	/* index of the AD */
	this.i=0;

	this.style="position:absolute;";
}

function WESAD_Check(o)
{
	return o.CookieHour && WESAD_CheckCookie(o.t+o.p+location.host.substring(0,location.host.indexOf(".")),o);
}

function WESAD_CheckCookie(E,o)
{
	var Now=new Date();
	var s=String(Now.getYear())+String(Now.getMonth()+1)+String(Now.getDate());
	if(WESAD_GetCookie(E)==s)
		return true;
	else
	{
		Now.setTime(Now.getTime()+(parseFloat(typeof(o.CookieHour)=="undefined"?24:parseFloat(o.CookieHour))*60*60*1000));
		WESAD_SetCookie(E,s,Now);
		return false;
	}
}


function WESAD_GetCookie(n)
{
	var args=n+"=";
	var aLength=args.length,cLength=document.cookie.length,AAi=0;
	while(AAi<cLength)
	{
		var AAj=AAi+aLength;
		if(document.cookie.substring(AAi, AAj)==args)
			return WESAD_GetCookieVal(AAj);
		AAi=document.cookie.indexOf(" ", AAi)+1;
		if(AAi==0)
			break;
	}
	return null;
}

function WESAD_GetCookieVal(offset)
{
	var endstr=document.cookie.indexOf(";", offset);
	if(endstr==-1)
		endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function WESAD_SetCookie(name, value)
{
	var argv=WESAD_SetCookie.arguments;
	var argc=WESAD_SetCookie.arguments.length;
	var expires=(argc>2)?argv[2]:null;
	var path=(argc>3)?argv[3]:null;
	var domain=(argc>4)?argv[4]:null;
	var secure=(argc>5)?argv[5]:false;
	document.cookie=name+"="+escape(value)+((expires==null)?"":("; expires="+expires.toGMTString()))+((path==null)?"":("; path="+path))+((domain==null)?"":("; domain="+domain))+((secure==true)?"; secure":"");
}

/**
 * generate the AD html code
 *
 * @param a string the url of the AD
 * @param w integer width of the ad
 * @param h integer height of the ad
 * @param o the object of the AD
 * @param id string the id of the AD html element
 * @param href string the link of the AD
 */
function WESAD_Media(a,w,h,o,id,href)
{
	var s="";
	if(a.indexOf(".swf")!=-1)
	{
		if(WESAD_CE==1)
		{
			s="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='"+WESAD_F +"' id='"+((id==null)?o.t:id)+"' width='"+w+"' height='"+h+"' ";
			if(o.style)s+=" style='"+o.style+"'";
			if(o.extfunc)s+=" "+o.extfunc+" ";
			s+=" ><param name='movie' value='"+a+"'>";
			if(o.play)s+="<param name='play' value='"+o.play+"'>";
			if(o.wmode&&o.wmode!="")s+="<param name='wmode' value='"+o.wmode+"'>";
			if(typeof(o.loop)!="undefined")
				s+="<param name='loop' value='"+o.loop+"'>";
			s+="<param name='quality' value='autohigh'></object>";
		}
		else
		{
			s="<embed ";
			if(o.style)
				s+=" style='"+o.style+"'";
			if(o.extfunc)
				s+=" "+o.extfunc+" ";
			s+=" src='"+a+"'"+" quality='autohigh' id='"+((id==null)?o.t:id)+"' name='"+((id==null)?o.t:id)+"' width='"+w+"' height='"+h+"' ";
			if(o.wmode&&o.wmode!="")
				s+=" wmode='"+o.wmode+"' ";
			if(typeof(o.loop)!="undefined")
				s+=" loop='"+o.loop+"' ";
			s+="type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'></embed>";
		}
	}
	else if(a.indexOf(".gif")!=-1||a.indexOf(".jpg")!=-1||a.indexOf(".png")!=-1)
	{
		if (href == null)
			if (o.href)
				href = o.href;
		s = '';
		if (href != null)
			s += "<a href='"+((href==null)?o.href:href)+"' target='_blank'>";
		s += '<img ';
		if(o.style)
			s+=" style='"+o.style+"'";
		if(o.extfunc)
			s+=" "+o.extfunc+" ";
		s+=" id='"+((id==null)?o.t:id)+"' src='"+a+"' border='0' width='"+w+"' height='"+h+"'>";
		if (href != null)
			s += "</a>";
	}
	return s;
}

function WESAD_FSCommand(o,id)
{
	var s="";
	if(WESAD_CE==1)
	{
		s="<Script language='Javascript' for='"+((id==null)?o.t:id)+"' event='FSCommand(command,args)'>\n" +""+((id==null)?o.t:id)+"_DoFSCommand(command,args);\n" +"<\/Script>\n";
	}
	return s;
}

function WESAD_Close(o,n)
{
	WESAD_S[o].s=2;
	var OBJ=document.getElementById(n);
	if(OBJ)
		OBJ.style.display="none";
}

/**
 * @params array StartTime
 * @params Array EndTime
 * @params Array src
 * @params Array href
 * @param width
 * @param height
 */
function FULL_main(o)
{
	if(WESAD_Check(o))
	{
		o.s=2;
		return;
	}
	var IS_Find=false;
	if (!o.width) o.width = 770;
	if (!o.height) o.height = 450;
	if(o.StartTime.length==o.EndTime.length && o.EndTime.length==o.src.length && o.src.length==o.href.length)
	{
		for(FAi=0;FAi<o.src.length;FAi++)
		{
			var ST=new Date(o.StartTime[FAi]);
			var ET=new Date(o.EndTime[FAi]);
			var NT=new Date();
			if((ST<=ET)&&(NT<ET)&&(NT>=ST))
			{
				var OBJ=document.getElementById("fullscreenad");
				if(OBJ!=null)
				{
					self.scroll(0,0);OBJ.style.display="block";
					o.style="";
					OBJ.innerHTML=WESAD_Media(o.src[FAi],o.width,o.height,o,"",o.href[FAi]);
					IS_Find=true;
					setTimeout("WESAD_Close("+o.i+",'fullscreenad')",isNaN(parseInt(o.timeout))?7000:parseInt(o.timeout));
					return;
				}
				else
				{
					o.s=2;
					return;
				}
			}
		}
		if(!IS_Find)
			WESAD_Close(o.i,"fullscreenad");
	}
}

function POP_STRUCT(o)
{
	o.s=2;
	var WN=(o.name)?o.name:"";
	var Wi=(o.superad)?(screen.width-9):(parseInt((o.width)?o.width:350)-4);
	var Wh=(o.superad)?(screen.height-56):(parseInt((o.height)?o.height:250)-4);
	var Wl=(o.t=="POPUP")?((o.left)?o.left:0):(screen.width+10);
	var Wt=(o.t=="POPUP")?((o.top)?o.top:0):(screen.height+10);
	return window.open("about:blank",WN,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width="+Wi+",height="+Wh+",top="+Wt+",left="+Wl);
}

function POP_WINDOW(o)
{
	var SK="<html><head><meta http-equiv='content-type' content='text/html; charset=gb2312'><title>";
	SK+=(o.title)?o.title:((o.superad)?("WESCMS ±³Í¶¹ã¸æ"):("WESCMS "+o.t+" Ad"));
	SK+="</title>";
	SK+="\n<Script language='Javascript'>\n";
	if(o.t=="POPUP")
	{
		SK+="function Load(){\n";
		if(WESAD_CE==1)
			SK+="setTimeout('blur();',";
		else
			SK+="setTimeout('self.opener.focus()',";
		SK+=isNaN(parseInt(o.timeout))?7000:o.timeout;
		SK+=");\n}\n";
	}
	SK+="<\/Script>";
	SK+="</head><body scroll=no style='margin:0;border:none'>";
	SK+="<iframe id='iFrame' ";
	if(o.t=="POPUP")
		SK+=" onload='Load()' ";
	SK+=" marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no width=100% height=100% src='"+o.src+"'>wait</iframe>";
	SK+="</body></html>";
	return SK;
}

/**
 * @param name
 * @param boolean superad (display in full screen mode)
 * @param string t (type of the ad:'POPUP' only)
 * @param string src
 * @param title
 * @param timeout
 */
function POPUP_main(o)
{
	if(WESAD_Check(o))
	{
		o.s=2;
		return;
	}
	if(o.src&&o.src!="")
	{
		var OK=POP_STRUCT(o);
		if(OK)
			OK.document.write(POP_WINDOW(o));
	}
}

/**
 * @param string src
 * @param string t (type of the ad)
 * @param string title
 * @param timeout
 * @param left
 * @param top
 */
function POPUNDER_main(o)
{
	if(WESAD_Check(o))
	{
		o.s=2;
		return;
	}
	if(o.src&&o.src!="")
	{
		var OK=POP_STRUCT(o);
		if(OK)
		{
			if(WESAD_CE==1)
				OK.blur();
			else 
				OK.opener.focus();
			OK.moveTo(((o.left)?o.left:0),((o.top)?o.top:0));
			OK.document.write(POP_WINDOW(o));
		}
	}
}

/**
 * conflict with BOOKTURN/COUPLET type
 * @param leftHref
 * @param rightHref
 * @param href
 * @param offsetX
 * @param offsetY
 * @param leftSrc
 * @param rightSrc
 * @param width
 * @param height
 * @param wmode
 * @param style
 */
function FLOAT_main(o)
{
	var HasBOOKTURN=false;
	for(CAI=0;CAI<WESAD_S.length;CAI++)
	{
		if(WESAD_S[CAI].t=="BOOKTURN")
		{
			HasBOOKTURN=true;
			break;
		}
	}
	var HasCOUPLET=false;
	for(CAC=0;CAC<WESAD_S.length;CAC++)
	{
		if(WESAD_S[CAC].t=="COUPLET")
		{
			HasCOUPLET=true;
			break;
		}
	}
	o.style+="z-index:10;";
	if(!o.leftHref)
		o.leftHref="";
	if(!o.rightHref)
		o.rightHref="";
	if(isNaN(parseInt(o.offsetX)))
		o.offsetX=30;
	if(screen.width<1024)
		o.offsetX+=100;
	if(isNaN(parseInt(o.offsetY)))
		o.offsetY=(HasBOOKTURN&&HasCOUPLET)?0:20;
	var s="";

	var width = o.width ? o.width : 80;
	var height = o.height ? o.height : 80;
	if(o.leftSrc && o.leftSrc!="")
		s+=WESAD_Media(o.leftSrc,width,height,o,WESAD_DIV+"left",o.leftHref);
	if(o.rightSrc && o.rightSrc!="")
		s+=WESAD_Media(o.rightSrc,width,height,o,WESAD_DIV+"right",o.rightHref);
	if(s!="")
	{
		WriteAd(WESAD_DIV+"FLOAT",s);
		WESAD_O1=document.getElementById(WESAD_DIV+"left");
		WESAD_O2=document.getElementById(WESAD_DIV+"right");
		if(WESAD_O1!=null||WESAD_O2!=null)
		{
			window.setInterval("FLOAT_position("+o.offsetX+","+(parseInt(o.offsetY)+height)+"," + width + ")",400);
		}
	}
	o.s=2;
}

function FLOAT_position(a,b, width)
{
	if(WESAD_CE==1)
	{
		if(WESAD_O1!=null)
		{
			WESAD_O1.style.top=parseInt((parseInt(document.body.scrollTop)+parseInt(document.body.clientHeight)-b))+"px";
			WESAD_O1.style.left=parseInt((parseInt(document.body.scrollLeft)+a))+"px";
		}
		if(WESAD_O2!=null)
		{
			WESAD_O2.style.top=parseInt((parseInt(document.body.scrollTop)+parseInt(document.body.clientHeight)-b))+"px";
			WESAD_O2.style.left=parseInt((parseInt(document.body.scrollLeft)+parseInt(document.body.clientWidth)-width-a))+"px";
		}
	}
	else
	{
		if(WESAD_O1!=null)
		{
			WESAD_O1.style.top=parseInt(0.75*(parseInt(document.body.scrollTop)+parseInt(document.body.clientHeight)-b))+"pt";
			WESAD_O1.style.left=parseInt(0.75*(parseInt(document.body.scrollLeft)+a))+"pt";
		}
		if(WESAD_O2!=null)
		{
			WESAD_O2.style.top=parseInt(0.75*(parseInt(document.body.scrollTop)+parseInt(document.body.clientHeight)-b))+"pt";
			WESAD_O2.style.left=parseInt(0.75*(parseInt(document.body.scrollLeft)+parseInt(document.body.clientWidth)-width-a))+"pt";
		}
	}
}

function LIUMEITI_main(o)
{
	if(WESAD_Check(o))
	{
		o.s=2;
		if(typeof(LIUMEITI_CALL)=="function")
			LIUMEITI_CALL();
		return;
	}
	if(!o.width)
		o.width=200;
	if(!o.height)
		o.height=150;
	if(!o.top)
		o.top="0";
	if(!o.left)
		o.left="-0";
	if(o.src&&o.src!="")
	{
		o.style+="top:"+(parseInt(document.body.scrollTop)+((String(o.top).indexOf("-")==-1)?parseInt(o.top):(parseInt(document.body.clientHeight)+parseInt(o.top)-o.height)));
		o.style+=";left:"+((String(o.left).indexOf("-")==-1)?parseInt(o.left):(parseInt(document.body.clientWidth)-o.width+parseInt(o.left)));WESAD_RESIZE[WESAD_RESIZE.length]="document.getElementById('"+WESAD_DIV+"lmt').style.left=(('"+o.left+"'.indexOf('-')==-1)?"+o.left+":(parseInt(document.body.clientWidth)-"+(o.width+parseInt(o.left))+"))";
		WriteAd(WESAD_DIV+"LIUMEITI",WESAD_Media(o.src,o.width,o.height,o,WESAD_DIV+"lmt"));
		if(o.eval&&o.eval!="")
			eval(o.eval);
		setTimeout("WESAD_Close("+o.i+",'"+WESAD_DIV+"lmt')",isNaN(parseInt(o.timeout))?8000:parseInt(o.timeout));
	}
}

/**
 * @param top
 * @param left
 * @param boolean loop
 * @param CookieHour
 * @param src
 * @param srcButton
 * @param style
 * @param wmode
 */
function BOOKTURN_main(o)
{
	self.scroll(0,0);
	if(!o.top)
		o.top="0";
	if(!o.left)
		o.left="-0";
	if(!o.loop)
		o.loop=false;
	if(!o.CookieHour)
		o.CookieHour=1;
	if(o.src&&o.srcButton)
	{
		var show=(WESAD_Check(o));
		o.style+="z-index:10000;";
		if(show)
			o.style+="visibility:hidden;";
		o.style+="top:"+(parseInt(document.body.scrollTop)+(String(o.top).indexOf("-")==-1)?parseInt(o.top):(parseInt(document.body.clientHeight)+parseInt(o.top)-250));
		o.style+=";left:"+((String(o.left).indexOf("-")==-1)?parseInt(o.left):(parseInt(document.body.clientWidth)-350+parseInt(o.left)));
		var s1=WESAD_Media(o.src,350,250,o,WESAD_DIV+"book1");
		o.style=o.style.substring(0,o.style.lastIndexOf("z-index:10000;"));
		if(!show)
			o.style+="visibility:hidden;";
		o.style+="z-index:11;";
		o.style+="top:"+(parseInt(document.body.scrollTop)+(String(o.top).indexOf("-")==-1)?parseInt(o.top):(parseInt(document.body.clientHeight)+parseInt(o.top)-250));
		o.style+=";left:"+((String(o.left).indexOf("-")==-1)?parseInt(o.left):(parseInt(document.body.clientWidth)-80+parseInt(o.left)));
		s1+=WESAD_Media(o.srcButton,80,80,o,WESAD_DIV+"book2");
		WESAD_RESIZE[WESAD_RESIZE.length]="document.getElementById('"+WESAD_DIV+"book1').style.left=(('"+o.left+"'.indexOf('-')==-1)?"+o.left+":(parseInt(document.body.clientWidth)-"+(350+parseInt(o.left))+"))";
		WESAD_RESIZE[WESAD_RESIZE.length]="document.getElementById('"+WESAD_DIV+"book2').style.left=(('"+o.left+"'.indexOf('-')==-1)?"+o.left+":(parseInt(document.body.clientWidth)-"+(80+parseInt(o.left))+"))";
		s1+=WESAD_FSCommand(o,WESAD_DIV+"book1");
		s1+=WESAD_FSCommand(o,WESAD_DIV+"book2");
		WriteAd(WESAD_DIV+"book",s1);
		document.getElementById(WESAD_DIV).i=o.i;
		if(show)
			o.s=2;
	}
	else
		o.s=2;
}

function ADAREAbook1_DoFSCommand(commands,args)
{
	WESAD_S[document.getElementById(WESAD_DIV).i].s=2;
	document.getElementById(WESAD_DIV+"book1").style.visibility='hidden';
	var OBJ=document.getElementById(WESAD_DIV+"book2");
	OBJ.style.visibility='visible';OBJ.style.display='block';
}

function ADAREAbook2_DoFSCommand(commands,args)
{
	document.getElementById(WESAD_DIV+"book2").style.visibility='hidden';
	var OBJ=document.getElementById(WESAD_DIV+"book1");
	OBJ.style.visibility='visible';
	OBJ.style.display='block';
	OBJ.Play();
}

/**
 * @param offsetX
 * @param offsetY
 * @param src
 * @param src2
 * @param wmode
 * @param style
 */
function COUPLET_main(o)
{
	if(((WESAD_CE==1)&&(screen.width<1000))||((WESAD_CE==0)&&(document.body.scrollWidth<1000)))
	{
		o.s=2;
		return;
	}
	var HasBOOKTURN=false;
	for(CAI=0;CAI<WESAD_S.length;CAI++)
	{
		if(WESAD_S[CAI].t=="BOOKTURN")
		{
			HasBOOKTURN=true;break;
		}
	}
	if(WESAD_Check(o))
	{
		o.s=2;
		return;
	}
	if(!o.offsetX)
		o.offsetX=0;
	if(!o.offsetY)
		o.offsetY=(HasBOOKTURN)?250:100;
	if (!o.leftHref)
		o.leftHref = '###';
	if (!o.width)
		o.width = 120;
	if (!o.height)
		o.height = 300;
	if (o.leftSrc && !o.rightSrc)
	{
		o.rightSrc = o.leftSrc;
		if (o.leftHref) o.rightHref = o.leftHref;
	}
	if (o.rightSrc && !o.leftSrc)
	{
		o.leftSrc = o.rightSrc;
		if (o.rightHref) o.leftHref = o.rightHref;
	}
	if(o.leftSrc||o.rightSrc)
	{
		o.style+="top:"+o.offsetY;
		o.style+=";left:"+(parseInt(document.body.scrollLeft)+o.offsetX);
		var s1=WESAD_Media(o.leftSrc,o.width,o.height,o,WESAD_DIV+"Couplet1", (o.leftHref ? o.leftHref : null));
		o.style=o.style.substring(0,o.style.lastIndexOf("left:"));
		o.style+="left:"+((parseInt(document.body.scrollLeft)+parseInt(document.body.clientWidth)-o.width-o.offsetX ));

		s1+=WESAD_Media(o.rightSrc,o.width,o.height,o,WESAD_DIV+"Couplet2", (o.rightHref ? o.rightHref : null));
		s1+=WESAD_FSCommand(o,WESAD_DIV+"Couplet2");
		WESAD_RESIZE[WESAD_RESIZE.length]="document.getElementById('"+WESAD_DIV+"Couplet2').style.left=parseInt(document.body.scrollLeft)+parseInt(document.body.clientWidth)-"+(120+o.offsetX);

		s1+=WESAD_FSCommand(o,WESAD_DIV+"Couplet1");
		WriteAd(WESAD_DIV+"Couplet",s1);
		
		if(o.timeout)
			setTimeout("ADAREACouplet1_DoFSCommand()",o.timeout);
	}
	o.s=2;
}

function ADAREACouplet1_DoFSCommand(commands,args)
{
	document.getElementById(WESAD_DIV+"Couplet1").style.visibility='hidden';
	document.getElementById(WESAD_DIV+"Couplet2").style.visibility='hidden';
}

function ADAREACouplet2_DoFSCommand(commands,args)
{
	ADAREACouplet1_DoFSCommand(commands,args);
}


setTimeout("WESAD_PUSH()",2000);