Eachgain__name="一起推·网页互动联盟";
Eachgain__link="http://www.eachpush.cn/code/";
Eachgain__code="http://www.eachpush.cn/code/";



if(typeof(Eachgain__debug)!="undefined"){
	alert("提示：\n\n一个页面中只允许投放一个代码！");	
}
else{
	// 是否调试信息
	Eachgain__debug=0;

	// 环境检查
	function Eachgain__check(){
		if(top.location!=self.location){
			Eachgain__msg("请不要将代码放在框架页面里！",1);
			return false;
		}
		if(document==null||document.title==null||document.body==null){
			Eachgain__msg("请将代码放在规范的页面里！\n\n\n例如：页面中需包含 <title>,<body> 等标签",1);
			return false;	
		}
		if(typeof(Eachgain__name)!="string"){
			Eachgain__msg("代码不完整，缺少'联盟名称'！",0);
			return false;
		}
		if(typeof(Eachgain__link)!="string"||typeof(Eachgain__code)!="string"){
			Eachgain__msg("代码不完整，缺少'链接地址'或'代码地址'！",0);
			return false;
		}
		if(typeof(Eachgain_uid)!="number"||typeof(Eachgain_cid)!="number"){
			Eachgain__msg("代码不完整，缺少'用户编号'或'代码编号'！",0);
			return false;
		}
		if(typeof(Eachgain_style)!="number"){
			Eachgain__msg("代码不完整，缺少'代码样式'！",0);
			return false;
		}
		if(typeof(Eachgain_choose1)!="number"||typeof(Eachgain_choose2)!="number"){
			Eachgain__msg("代码不完整，缺少'缺省标签类型'或'缺省内容类型'！",0);
			return false;
		}
		if(typeof(Eachgain_status)!="number"){
			Eachgain__msg("代码不完整，缺少'代码状态'！",0);
			return false;
		}
		if(Eachgain_status<=0 || Eachgain_status>2){
			Eachgain__msg("代码非投放状态！",0);
			return false;
		}
		if(Eachgain_status==1){
			Eachgain__msg("代码暂停状态！",0);
			return false;
		}
		if( !( (Eachgain_style>10 && Eachgain_style<20) || (Eachgain_style>20 && Eachgain_style<25) || (Eachgain_style>30 && Eachgain_style<35) ) ){
			Eachgain__msg("代码样式错误！",0);
			return false;
		}
		return true;
	}

	// 显示信息
	function Eachgain__msg(str,level){
		if(Eachgain__debug>=0 && level>=0){	
			if(Eachgain__debug|level){
				alert("\n温馨提示：\n___________________________________________\n\n  "+str+"\n\n-------------------------------------------\n\t\tCopyright (C) Eachgain.CN");
			}
		}
	}

	// 显示框架
	function Eachgain__show_frame(cert){
		
		// 加载代码样式
		Eachgain__obj=document.createElement('link');
		Eachgain__obj.rel="stylesheet";
		Eachgain__obj.type="text/css";
		Eachgain__obj.href=Eachgain__code+"/style/style"+Eachgain__style+".css";
		document.body.insertAdjacentElement("beforeBegin",Eachgain__obj);
		
		// 加载代码框架
		if(Eachgain__style>20){
			Eachgain__obj=document.createElement('div');
			Eachgain__obj.id="Eachgain_frame";
			Eachgain__obj.innerHTML="<div id='Eachgain_head'><div id='Eachgain_logo'>"+Eachgain__name+"</div><div id='Eachgain_tag'></div></div><div id='Eachgain_list'></div><div id='Eachgain_close' title='关闭'></div>";
			document.body.insertAdjacentElement("afterBegin",Eachgain__obj);
		}
		else{
			Eachgain__str="<div id='Eachgain_frame'><div id='Eachgain_head'><div id='Eachgain_logo'>"+Eachgain__name+"</div><div id='Eachgain_tag'></div></div><div id='Eachgain_list'></div><div id='Eachgain_close' title='关闭'></div></div>";
			document.write(Eachgain__str);
		}

		// 加载事件响应
		document.all.Eachgain_logo.onclick=new Function("window.open('"+Eachgain__link+"?uid="+Eachgain__uid+"');event.returnValue=true;");
		if(Eachgain__style>10){
			document.all.Eachgain_frame.oncontextmenu=new Function("Eachgain__msg('“Each”系列产品： 一起推·内容互动联盟',1);event.returnValue=false;");
			document.all.Eachgain_frame.onselectstart=new Function("event.returnValue=false;");
			if(Eachgain__style>20){
				window.onload=new Function("Eachgain__do_event_1(Eachgain__style);event.returnValue=true;");
				window.onresize=new Function("Eachgain__do_event_1(Eachgain__style);event.returnValue=true;");
				document.body.onscroll=new Function("Eachgain__do_event_1(Eachgain__style);event.returnValue=true;");
				document.all.Eachgain_close.onmousedown=new Function("Eachgain__do_event_2(Eachgain__style);event.returnValue=true;");
				if(Eachgain__style>30){
					document.all.Eachgain_head.onmouseover=new Function("Eachgain__do_event_3(Eachgain__style);event.returnValue=true;");
				}
			}
		}

		// 采集：采集数据并分析标签，通过回调函数显示标签
		Eachgain__str="<script id='Eachgain_pick' language='javascript' src='"+Eachgain__URI_pick+"&certificate="+cert+"&title="+document.title.replace(/ /g,"%20")+"'></script>";
		document.write(Eachgain__str);
	}

	// 显示标签
	function Eachgain__show_tag(obj){
		
		// 获取并分析参数
		cert=obj.certificate;
		list=obj.lists;
		
		// 生成并显示标签
		Eachgain__tag="";
		for(m in list){
			Eachgain__tag+="<li onclick=\"document.all.Eachgain_post.src=document.all.Eachgain_post.src.replace(/&tag=(.*)$/,'&tag="+list[m][0]+"')\" ondblclick=\"Eachgain__show_search('"+list[m][0]+"')\" title='单击改变代码框中现有内容&#13;双击显示更多{ "+list[m][0]+" }内容'>"+list[m][0]+"</li>";
		}
		Eachgain__tag="<ol>"+Eachgain__tag+"</ol>";
		document.all.Eachgain_tag.innerHTML=Eachgain__tag;
		
		// 投放：初始化代码投放，通过回调函数显示第一个标签的列表
		Eachgain__str="<script id='Eachgain_post' language='javascript' src='"+Eachgain__URI_post+"&certificate="+cert+"&tag="+list[0][0]+"'></script>";
		document.write(Eachgain__str);
	}

	// 显示列表
	function Eachgain__show_list(obj){
		
		// 获取并分析参数
		cert=obj.certificate;
		list=obj.lists;		
		type=Math.floor(Eachgain__style/10);		
		
		// 生成并显示列表
		Eachgain__list="";		
		for(n in list){
			id=list[n][0];
			title=list[n][1];
			str1="\n<dl>";
			str2="\n</dl>";
			str3="\n\t<dt onclick=\"Eachgain__show_content('"+id+"','"+cert+"')\"><span><img src='"+Eachgain__code+"/images/?id="+Eachgain__choose2+"&rand="+Math.random()+"'></span></dt>";
			str4="\n\t<dd onclick=\"Eachgain__show_content('"+id+"','"+cert+"')\" title='"+title.replace(/(<.*?>(.*?)<\/font>)/g,"$2")+"'>·"+title+"</dd>";
			switch(type){
				case 1:
					if(n%5==0){
						Eachgain__list+=str1+str3+str2;
					}
					if(n%5==0){
						Eachgain__list+=str1
					}
					Eachgain__list+=str4;
					if(n%5==4){
						Eachgain__list+=str2;
					}
					break;
				case 2:
					if(n==0){
						Eachgain__list+=str1;
					}
					Eachgain__list+=str4;
					if(n==10){
						Eachgain__list+=str2;
					}
					break;
				case 3:
					Eachgain__list+=str1+str3+str2+str1+str4+str2;
					break;
			}				
		}
		document.all.Eachgain_list.innerHTML=Eachgain__list;
	}
	
	// 显示页面内容
	function Eachgain__show_content(id,cert){		
		window.open(Eachgain__URI_page+"&certificate="+cert+"&lid="+id);
	}

	// 显示标签搜索
	function Eachgain__show_search(tag){		
		window.open(Eachgain__code+"?tag="+tag);
	}

	// 事件响应：onresize | onscroll
	function Eachgain__do_event_1(style){
		switch(style){
			case 21:
				x=document.body.scrollLeft;
				y=document.body.scrollTop;
				break;
			case 22:
				x=document.body.scrollLeft;
				y=document.body.scrollTop+document.body.clientHeight-220;
				break;
			case 23:
				x=document.body.scrollLeft+document.body.clientWidth-200;
				y=document.body.scrollTop;
				break;
			case 24:
				x=document.body.scrollLeft+document.body.clientWidth-200;
				y=document.body.scrollTop+document.body.clientHeight-220;
				break;
			case 31:
				x=document.body.scrollLeft;
				y=document.body.scrollTop+(document.body.clientHeight-260)/2;
				break;
			case 32:
				x=document.body.scrollLeft+document.body.clientWidth-100;
				y=document.body.scrollTop+(document.body.clientHeight-260)/2;
				break;
			case 33:
				x=document.body.scrollLeft;
				y=document.body.scrollTop+(document.body.clientHeight-500)/2;
				break;
			case 34:
				x=document.body.scrollLeft+document.body.clientWidth-100;
				y=document.body.scrollTop+(document.body.clientHeight-500)/2;				
				break;
		}
		document.all.Eachgain_frame.style.left=x;
		document.all.Eachgain_frame.style.top=y;
	}

	// 事件响应：onmousedown
	function Eachgain__do_event_2(style){
		switch(style){
			case 21:
			case 22:
			case 23:
			case 24:
				document.all.Eachgain_frame.style.visibility="hidden";
				break;				
			case 31:
			case 33:
			case 32:
			case 34:
				document.all.Eachgain_head.style.visibility="visible";
				document.all.Eachgain_list.style.visibility="hidden";
				document.all.Eachgain_close.style.visibility="hidden";
		}
	}

	// 事件响应：onmouseover
	function Eachgain__do_event_3(style){
		switch(style){
			case 31:
			case 32:
			case 33:
			case 34:
				document.all.Eachgain_head.style.visibility="hidden";
				document.all.Eachgain_list.style.visibility="visible";
				document.all.Eachgain_close.style.visibility="visible";
				break;
		}
	}

	
	if(Eachgain__check()==true){

		/* 初始私有变量 */

		// 用户编号
		var Eachgain__uid=Eachgain_uid;
		// 代码编号
		var Eachgain__cid=Eachgain_cid;
		// 代码显示样式
		var Eachgain__style=Eachgain_style;
		// 代码默认标签
		var Eachgain__choose1=Eachgain_choose1;
		// 代码默认内容
		var Eachgain__choose2=Eachgain_choose2;
		// 代码显示状态
		var Eachgain__status=Eachgain_status;

		// 数据对象
		var Eachgain__data=escape("{uid:"+Eachgain__uid+",cid:"+Eachgain__cid+",style:"+Eachgain__style+",choose1:"+Eachgain__choose1+",choose2:"+Eachgain__choose2+",position:\""+escape(window.location)+"\"}");

		// 信息验证地址
		var Eachgain__URI_validate=Eachgain__code+"/validate.php?data="+Eachgain__data+"&sn="+Math.random()+"&callback=Eachgain__show_frame";
		// 数据采集地址
		var Eachgain__URI_pick=Eachgain__code+"/pick.php?data="+Eachgain__data+"&sn="+Math.random()+"&callback=Eachgain__show_tag";
		// 代码投放地址
		var Eachgain__URI_post=Eachgain__code+"/post.php?data="+Eachgain__data+"&sn="+Math.random()+"&callback=Eachgain__show_list";
		// 页面显示地址
		var Eachgain__URI_page=Eachgain__code+"/page.php?data="+Eachgain__data+"&sn="+Math.random();
		// 远程脚本代码
		var Eachgain__str="<script id='Eachgain_validate' language='javascript' src='"+Eachgain__URI_validate+"'></script>";

		/* 服务器端验证 */
		document.write(Eachgain__str);
	}
}