//广告信息
var adid=308;
var client="tcl";
var urls="http://sy.xinge365.com/";
/*var urls="http://tuan.xinge365.com/";*/
var Today = new Date();
var ExecuteYear=Today.getYear();
var ExecuteMonth=Today.getMonth()+1;
var ExecuteDay=Today.getDate();
var ExecuteDate=ExecuteYear+""+ExecuteMonth+""+ExecuteDay;
var date=ExecuteDate;
var channel="sszh";
//浮层 flash 定义
var ad750500Src="http://www.xinge365.com/coolad/swf/20110509/960-400.swf"; //修改位置 750 500 src
//var ad750500Src="960-400.swf";
var ad750500Width=960; //浮层宽
var ad750500Height=400; //浮层高
var ad750500Id = client+date+channel+"750500"; //浮层 div id
var flashId750500 = client+date+channel+"big"; //浮层 flash id

//漂浮 flash 定义
var ad8080Src = "http://www.xinge365.com/coolad/swf/20110509/20-270.swf"; //修改位置 80 80 src
//var ad8080Src = "20-270.swf";
var ad8080Flash = "flash"; //漂浮类型
var ad8080Href = ""; //漂浮链接
var ad8080Width = 20; //漂浮宽
var ad8080Height = 270; //漂浮高
var ad8080marginTop = 0; //漂浮上或下边距
var ad8080marginLeft = 0; //漂浮左或右边距
var ad8080Id = client+date+channel+"8080"; //浮层 div id
var flashId8080 = client+date+channel+"mini"; //浮层 flash id
var ad8080Id2 = client+date+channel+"80802"; //浮层 div id
var flashId80802 = client+date+channel+"mini2"; //浮层 flash id
//漂浮位置定义
//漂浮位置定义
//漂浮位置定义
//漂浮位置定义
//漂浮位置定义
var Xposition = "left"; //设置漂浮位置 left/center/right 中缝设置为center
var Xposition2 = "right"; //设置漂浮位置 left/center/right 中缝设置为center
var Yposition = "middle"; //设置漂浮位置 top/middle/bottom 中缝设置为bottom
//中缝后设置以下值
var minH=100; //中缝时设置 790 设置中缝位置，距顶最小距离(保证不压页头)
var maxH=4350; //中缝时设置 1290 设置中缝位置，距顶最大距离，根据页面实际高设置(保证不压页尾)
var minW=13; //中缝时设置 648 设置中缝位置，距左最小距离(保证页面缩小是不压页面)
var posX=-502; //中缝时设置 169 设置中缝位置，距垂直中线距离
var posX2=482; //中缝时设置 169 设置中缝位置，距垂直中线距离
var posY=0; //中缝时设置 0 设置中缝位置，距水平中线距离

//cookies 定义
var cookiesid=client+date+channel+'cookies';
var cookieseventid=client+date+channel+'eventcookies';

var divUpInterval;
var checkPlayInterval;
var cookiecount;
var cookieeventcount;

var loc;
var lid;
richcity=new Array("0","安徽","北京","福建","甘肃","广东","广西","贵州","海南","河北","河南","黑龙江","湖北","湖南","吉林","江苏","江西","辽宁","内蒙古","宁夏","青海","山东","山西","陕西","上海","四川","天津","西藏","新疆","云南","浙江","重庆","其他");



//可以修改
var za=0;  //移动层初始值
var za2=401; //移动距离
var sd=20; //移动速度
var stime=8000 //延时执行收回动作


//以下不用修改
var za1=za; //复制移动层初始值
var za3=-za2;//广告层初始
var za4=za3; //复制广告层初始值

/*
document.write("<div id=\"" + ad8080Id + "\" style=\"position: absolute;width:" + ad8080Width + ";visibility:hidden;\">");
if(ad8080Flash=="flash"){
	document.write("<embed wmode=\"\" src=\"" + ad8080Src + "\" quality=\"high\" width=\"" + ad8080Width + "\" height=\"" + ad8080Height + "\" type=\"application/x-shockwave-flash\" allowScriptAccess=\"always\" id=\"" + flashId8080 + "\"></embed>");
}else{
	document.write("<a href=\""+ad8080Href+"\" target=\"_blank\"><img src=\""+ad8080Src+"\" width=\""+ad8080Width+"\" height=\""+ad8080Height+"\" id=\"" + flashId8080 + "\" /></a>");
}
document.write("</div>");
*/

document.write("<div id=\"" + ad8080Id2 + "\" style=\"position: absolute;width:" + ad8080Width + ";visibility:hidden;\">");
if(ad8080Flash=="flash"){
	document.write("<embed wmode=\"\" src=\"" + ad8080Src + "\" quality=\"high\" width=\"" + ad8080Width + "\" height=\"" + ad8080Height + "\" type=\"application/x-shockwave-flash\" allowScriptAccess=\"always\" id=\"" + flashId80802 + "\"></embed>");
}else{
	document.write("<a href=\""+ad8080Href+"\" target=\"_blank\"><img src=\""+ad8080Src+"\" width=\""+ad8080Width+"\" height=\""+ad8080Height+"\" id=\"" + flashId80802 + "\" /></a>");
}
document.write("</div>");



document.write("<div id='downpic' style='position:absolute;top:-425px;width:960px;height:400px;margin-left:auto;margin-right:auto;text-align:right;vertical-align :bottom;margin:0;padding:0;'>");
document.write("<embed wmode=\"transparent\" src=\"" + ad750500Src + "\" quality=\"high\" width=\"" + ad750500Width + "\" height=\"" + ad750500Height + "\" type=\"application/x-shockwave-flash\" allowScriptAccess=\"always\" id=\"" + flashId750500 + "\"></embed>");
document.write("</div>");

// 处理 Flash 影片中的所有 FSCommand 消息
document.write("<"+"SCRIPT FOR='"+flashId750500+"' EVENT='FSCommand()' LANGUAGE='Java"+"Script'>");
document.write("stopmovie();");
document.write("</sc"+"ript>");

/*
document.write("<"+"SCRIPT FOR='"+flashId8080+"' EVENT='FSCommand()' LANGUAGE='Java"+"Script'>");
document.write("replaymovie();");
document.write("</sc"+"ript>");
*/

document.write("<"+"SCRIPT FOR='"+flashId80802+"' EVENT='FSCommand()' LANGUAGE='Java"+"Script'>");
document.write("replaymovie();");
document.write("</sc"+"ript>");

//处理cookies

function GetCookie2 (name) { 
	var arg = name + "="; 
	var alen = arg.length; 
	var clen = document.cookie.length; 
	var i = 0; 
	while (i < clen) { 
		var j = i + alen; 
		if (document.cookie.substring(i, j) == arg){ 
			return getCookieVal2 (j);
		}
		i = document.cookie.indexOf(" ", i) + 1; 
		if (i == 0){
			break;
		}
	}
	return null;
}

function SetCookie2 (name, value) { 
	var argv = SetCookie2.arguments; 
	var argc = SetCookie2.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" : "");
}

function DeleteCookie (name) { 
	var exp = new Date(); 
	exp.setTime (exp.getTime() - 1); 
	// This cookie is history 
	var cval = 0; 
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}


//cookies
var expDays = 100;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));


function amt(){
	var count = GetCookie2(cookiesid)
	//alert(count)
	if(count == null) {
		SetCookie2(cookiesid,'1',exp)
		return 1;
	}else{
		var newcount = parseInt(count) + 1;
		if(newcount<2) count=1;
		SetCookie2(cookiesid,newcount,exp);
		//DeleteCookie(cookiesid);
		//return count;
		return newcount;

	}
}

function getCookieVal2(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1){
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}


//函数定义

nadScrollTop = function(){
	return document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop;
}

nadClientHeight = function(){
	return (document.body.clientHeight>document.documentElement.clientHeight)&&(document.documentElement.clientHeight!=0)?document.documentElement.clientHeight:document.body.clientHeight;
}

nadClientWidth = function(){
	return (document.documentElement.clientWidth>document.body.clientWidth)&&(document.documentElement.clientWidth!=0)?document.documentElement.clientWidth:document.body.clientWidth;
}

function getCityID(cityname){
	for(i=0;i<richcity.length;i++){
		if(richcity[i]==cityname){
			return i;
		}
	}
	return "0";
}

if(typeof window.parent.HTMLElement!="undefined" && !window.parent.HTMLElement.prototype.insertAdjacentElement){
     window.parent.HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode){
        switch (where){
            case 'beforeBegin':
                this.parentNode.insertBefore(parsedNode,this)
                break;
            case 'afterBegin':
                this.insertBefore(parsedNode,this.firstChild);
                break;
            case 'beforeEnd':
                this.appendChild(parsedNode);
                break;
            case 'afterEnd':
                if (this.nextSibling) this.parentNode.insertBefore(parsedNode,this.nextSibling);
                    else this.parentNode.appendChild(parsedNode);
                break;
         }
     }

     window.parent.HTMLElement.prototype.insertAdjacentHTML = function (where,htmlStr){
         var r = this.ownerDocument.createRange();
         r.setStartBefore(this);
         var parsedHTML = r.createContextualFragment(htmlStr);
         this.insertAdjacentElement(where,parsedHTML)
     }

     window.parent.HTMLElement.prototype.insertAdjacentText = function (where,txtStr){
         var parsedText = document.createTextNode(txtStr)
         this.insertAdjacentElement(where,parsedText)
     }
}

function load2(){
	judge2();
	move2();
}

function move2() {
	judge2();
	setTimeout("move2();",80)
}
function judge2(){
	var cw = nadClientWidth();
	var ch = nadClientHeight();
	var tw;
	var th;
	if(Yposition=="top"){
		th = document.documentElement.scrollTop + ad8080marginTop + ad8080Height;
	}
	if(Yposition=="middle"){
		th = document.documentElement.scrollTop + ch/2 + posY - ad8080Height;
	}
	if(Yposition=="bottom"){
		th = document.documentElement.scrollTop + ch - ad8080Height;
		if(th < minH && minH > 0){
			th=minH;
		}
		if(th > maxH && maxH > 0){
			th=maxH;
		}
	}
	if(th<0)th=0;
	//document.getElementById(ad8080Id).style.top=th+"px"
	document.getElementById(ad8080Id2).style.top=th+"px"
	if(Xposition=="left"){
		tw = ad8080marginLeft;
	}
	if(Xposition=="right"){
		tw = cw - ad8080Width - ad8080marginLeft;
	}
	if(Xposition2=="right"){
		tw2 = cw - ad8080Width - ad8080marginLeft;
	}
	if(Xposition=="center"){
		tw = cw/2 + posX - ad8080marginLeft;
		if(tw < minW && minW > 0){
			//tw=minW;
		}
	}
	if(Xposition2=="center"){
		tw2 = cw/2 + posX2 - ad8080marginLeft;
		if(tw2 < minW && minW > 0){
			tw2=minW;
		}
	}
	//if(tw<0)tw=0;
	if(tw2<0)tw2=0;
	//document.getElementById(ad8080Id).style.left= tw + 'px';
	document.getElementById(ad8080Id2).style.left= tw2 + 'px';
}

function divdown(){
	document.getElementById("downpic").style.top=za3+"px";
	document.getElementById("downdiv").style.height=za +"px";
	za3+=sd;
	za+=sd;
	if(za>=za2){
		clearInterval(divdowninterval);
		//setTimeout(closeswf,stime);	//过8秒
	}
}
function divup(){
	document.getElementById("downpic").style.top=za3+"px";
	document.getElementById("downdiv").style.height=za +"px";
	za3-=sd;
	za-=sd;
	if(za<=za1){
		clearInterval(divUpInterval);
		document.getElementById("downpic").style.top=za4+"px";
		document.getElementById("downdiv").style.height=za1+"px";
		//document.getElementById("downdiv").style.display='none';
		//document.getElementById(ad8080Id).style.visibility='visible';
		document.getElementById(ad8080Id2).style.visibility='visible';
		//thisMovie(flashId8080).TPlay("mc_1");
		thisMovie(flashId80802).Play();
		//document.getElementById("adLeftFloat").style.visibility='visible';
		thisMovie(flashId750500).Rewind();
	}
}

function playmovie(){
	za=0;
	za1=0; //复制移动层初始值
	za2=401;
	za3=-401;//广告层初始
	za4=-401; //复制广告层初始值

	//document.getElementById("adLeftFloat").style.visibility='hidden';
	//document.getElementById(ad8080Id).style.visibility='hidden';
	document.getElementById(ad8080Id2).style.visibility='hidden';
	
	//thisMovie(flashId8080).TGotoFrame("mc_1",0);
	thisMovie(flashId80802).TGotoFrame("mc_1",0);
	thisMovie(flashId750500).Rewind();
	thisMovie(flashId750500).Stop();
	thisMovie(flashId750500).Play();
	document.getElementById("downdiv").style.display='';
	lefts = (document.body.clientWidth) / 2 - ad750500Width/2;
	document.getElementById("downpic").style.left=lefts+"px";
	//alert("za="+za+"; za1="+za1+"; za2="+za2+"; za3="+za3);
	if(za<=za1){
		divdowninterval=setInterval("divdown();",1);
	}
	if(za>=za2){
		if(!divUpInterval){
			divUpInterval=setInterval("divup();",1);
		}
	}
}

function stopmovie(){
	if(za>=za2){
		document.getElementById("downdiv").style.display='';
		if(!divUpInterval){
			divUpInterval=setInterval("divup();",1);
		}
	}
}

function replaymovie(){
	thisMovie(flashId750500).SetVariable("isre",1);
	thisMovie(flashId750500).SetVariable("getevn",1);
	checkPlay();
}

cookiecount=amt();
loc = GetCookie2("theaddr");
lid=getCityID(loc);
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

function thisMovie(objid){
	var flashObj = isInternetExplorer ? document.all[objid] : document[objid];
	return flashObj;
}

function checkPlay(){
	divUpInterval=null;
	if (thisMovie(flashId750500).PercentLoaded() == 100){
		if(checkPlayInterval){
			clearInterval(checkPlayInterval);
		}
		if(cookiecount>1){
			thisMovie(flashId750500).SetVariable("getevn",1);
		}
		thisMovie(flashId750500).SetVariable("lid",lid);
		thisMovie(flashId750500).SetVariable("adid",adid);
		thisMovie(flashId750500).SetVariable("urls",urls);
		//thisMovie(flashId8080).SetVariable("lid",lid);
		//thisMovie(flashId8080).SetVariable("adid",adid);
		//thisMovie(flashId8080).SetVariable("urls",urls);
		thisMovie(flashId80802).SetVariable("lid",lid);
		thisMovie(flashId80802).SetVariable("adid",adid);
		thisMovie(flashId80802).SetVariable("urls",urls);
		playmovie();
	}else{
		if(!checkPlayInterval){
			checkPlayInterval=setInterval("checkPlay()",500);
		}
	}
}

function checkPlay2(){
	//if (thisMovie(flashId8080).PercentLoaded() == 100 && thisMovie(flashId80802).PercentLoaded() == 100){
	if (thisMovie(flashId80802).PercentLoaded() == 100){
		if(checkPlayInterval){
			clearInterval(checkPlayInterval);
		}
		//thisMovie(flashId8080).SetVariable("lid",lid);
		//thisMovie(flashId8080).SetVariable("adid",adid);
		//thisMovie(flashId8080).SetVariable("urls",urls);
		thisMovie(flashId80802).SetVariable("lid",lid);
		thisMovie(flashId80802).SetVariable("adid",adid);
		thisMovie(flashId80802).SetVariable("urls",urls);
		playmovie2();
	}else{
		if(!checkPlayInterval){
			checkPlayInterval=setInterval("checkPlay2()",500);
		}
	}
}

function playmovie2(){
	//document.getElementById(ad8080Id).style.visibility='visible';
	document.getElementById(ad8080Id2).style.visibility='visible';
	//thisMovie(flashId8080).Play();
	thisMovie(flashId80802).Play();
}

if(isInternetExplorer){
	document.body.insertAdjacentHTML("afterBegin","<div id='downdiv' style='font-size:1px;height:1px;'></div>");
	lefts = nadClientWidth() / 2 - ad750500Width/2;
	document.getElementById("downpic").style.left=lefts+"px";
	load2();
	if(cookiecount<=2){
		checkPlayInterval=setInterval("checkPlay()",500);
	}else{
		checkPlayInterval=setInterval("checkPlay2()",500);
	}
}
