﻿// JavaScript Document
function crAD(k,p1,p2,p3,p4,n){
	this.w=k;//关键词
	this.t=p1;//标题
	this.m=p2;//描述 
	this.h=p3;//广告链接
	this.p=p4;//广告图标
	this.n=n;//电话号码
};
function crFAD(t,c){
	this.t = t;
	this.c = c;
	};
function kwM(){//关键词移动 
    $jE.MoW();
};
function kwL(){//关键词移开
	$jE.OuK()
};
function kwE(o,i){
	$jE.s(o,i);
};
var JE_HOST='http://www.57joy.com'
$jE = new function(){
	var keyWord
	,T = this, d = document, b = d.body, w = window
	,head = d.getElementsByTagName('head')[0],url = d.location.href
	,u = navigator.userAgent.toLowerCase()
	,IE = T.IE = u.indexOf("msie") != -1 && u.indexOf("opera") == -1
	,IE7 = u.indexOf("opera") == -1 && u.indexOf("msie 7") > -1
	,creElm = function(n, a){//创建节点
        var e = d.createElement(n),k;
        for (k in a) {
            k == 'style' ? e.style.cssText = a[k] : e.setAttribute(k, a[k])
        }
        return e
    }
	,$$ = function(e){
        return typeof e == 'string' ? document.getElementById(e) : e
    }
	,$$S = function(e,s){
       for(var p in s){
       	typeof s[p] == 'object'?$$S(e[p],s[p]):e[p]=s[p];
       	
       }
    };
	T.s = function(o,i){
		try{
			if(document.all)o = event;
			var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
			var oLeft = o.clientX;
			var oTop = o.clientY;
			
			var scrnHeight = d.documentElement.clientHeight;
			var scrnWidth = d.documentElement.clientWidth;
			var objHeight = T.eN.offsetHeight;
			//var objWidth = obj.offsetWidth;
			if(oLeft<0)oLeft = 0;
			if(oTop+objHeight>scrnHeight)oTop=oTop-objHeight;
			if(oLeft+296>scrnWidth)oLeft=oLeft-296;
			$$S(T.eN.style,{display:'inline'});
			$$S(T.eN.style,{left:oLeft-40+"px"});
			$$S(T.eN.style,{top:oTop+st+"px"});
			T.eN.innerHTML = T.C(i);
		}catch(e){}
		};
		
	T.OuK = function(){//离开关键词
		T.tiH = setTimeout(function(){
			$$S(T.eN.style,{display:'none'});
            //T.eN.innerHTML = ''
        }, 500);
      	//addEvt(d,"mouseup",T.rand);
    };
    T.MoW = function(){//在橱窗中移动
     	T.tiH&&clearTimeout(T.tiH)
    };
	T.H = function(){
		$$S(T.eN.style,{display:'none'});
	}
 	T.iniWin = function(){
    	if(IE && !IE7){
	        try{
	        	document.execCommand("BackgroundImageCache", false, true);
	        }catch(e){}
	    }
		T.eN = b.insertBefore(creElm('div',{style: 'position:absolute;display:none;z-index:100000;width:296px',id:'popbox'})
			,b.insertBefore(creElm('div',{'style':IE7&&/itkeys|xwhb/.test(d.location.href)?'height:0px':''}),b.firstChild));
		T.eN.onmouseover = T.MoW;
		T.eN.onmouseout = T.OuK;
    };
	T.iniFlotWin = function(){
		//页面新建浮动DIV
		T.fW = b.insertBefore(creElm('div',{style:'width:260px;height:180px;position:fixed; overflow:hidden;_position:absolute;_bottom:e-xpression(eval(document.documentElement.scrollBottom));z-index:1000;right:0;bottom:0',id:'floatbox'})
			,b.insertBefore(creElm('div',{'style':IE7&&/itkeys|xwhb/.test(d.location.href)?'height:0px':''}),b.firstChild));
		//新建DIV插入元素
		T.fiW = T.fW.insertBefore(creElm('div',{style:'width:260px;height:180px;position:relative;top:180px;',id:'floatinbox'})
			,T.fW.insertBefore(creElm('div',{'style':IE7&&/itkeys|xwhb/.test(d.location.href)?'height:0px':''}),T.fW.firstChild));
		
			T.fiW.innerHTML = "<div id='fTitle'><div id='t' style='float:left'>"+ T.FData[0].t +"</div><div class='fbclose' style='float:right'><a href='javascript:$jE.playW(0);' id='fCl'><img src='"+JE_HOST+"/bz/popimg/c.gif'/></a></div></div>";
			T.fiW.innerHTML = T.fiW.innerHTML +"<div id='fCon'>"+ T.FData[0].c +"</div>"
		//设置 Cookie 24小时弹出一次
		if(T.getCookie("isOpen") == ""){
			T.playW(1);
			T.setCookie("isOpen","true");
		}
		};
		T.playW = function(p){
		try{
		var num = T.fiW.style.top.replace('px','')
			,n;
			if(p!=undefined) T.pW = p;
			T.pW == 1 ? n = 0 : n = 180;  
			if(Math.floor(num) == n){
				this.clearInterval();
			}else{
				T.pW == 1 ? num = Number(num)-1 : num = Number(num)+1;
				//alert(num);
				$$S(T.fiW.style,{top:num+'px'});
				setInterval(T.playW,100);
			}
		}catch(e){
			}
		};
	T.addKWord = function(l,id){//页面匹配关键字
			var obj = $$(id);
			var objHtml = obj.innerHTML;
			for(var i=0;i<l;i++){
				var cN = T.Data[i].n;
				var str = T.Data[i].w;
				var reg = new RegExp(str,"g");
					//闪动呼叫号吗
					if(cN!=""){
					var cnum = ",\'"+cN +"\'";
					}else{
					var cnum = "";
					}
			var rep = '<nobr style="color:#6600FF;border-bottom: 1px dotted #6600FF; text-decoration: underline;font-weight:bold" onmouseover="kwE(event,'+ i +')" onmousemove="kwM()" onmouseout="kwL()" id="keyword2">'+ str +'</nobr>'; 
			objHtml = objHtml.replace(reg,rep);
			obj.innerHTML = objHtml;//输出替换后的文本
			}
		};
	T.setData = function(d,f,id){//返回广告数据
	 	T.Data = d;
		T.FData = f;
		T.cID = id;//页面容器ID 
		try{
			T.dL = T.Data.length;
			if(T.dL<0) return;
		}catch(e){};
        T.addKWord(T.dL,T.cID);
		T.iniWin();
		T.iniFlotWin()
    };
	T.getCookie = function(Name){ 
		var search = Name + "=" 
		var returnvalue = ""; 
		if (document.cookie.length > 0) { 
		offset = document.cookie.indexOf(search) 
		if (offset != -1) { 
		offset += search.length 
		end = document.cookie.indexOf(";", offset); 
		if (end == -1) 
		end = document.cookie.length; 
		returnvalue=unescape(document.cookie.substring(offset, end)) 
		} 
	 } 
		return returnvalue; 
	 }; 
	T.setCookie = function(name, value,savedays){	
		var today = new Date();
		var expires = new Date();
		var saveTime;
		if(savedays==null){saveTime=100*365*24*60*60*1000;}
		else{saveTime=savedays;}
		if(value instanceof Array){	value=value.join();}
		if(saveTime==0){	
			d.cookie = name + "=" + escape(value)+";";
		}else{	
			expires.setTime(today.getTime() + Number(saveTime));
			d.cookie = name + "=" + escape(value)	+ "; expires=" + expires.toGMTString();
		}
	};
	//闪动电话
	T.oP = function(n,id){
		window.open('http://www.aiyah.cn/CallPage.html?free=1&accountId=test&callNum=KjDoK?end','win','width=360,height=610,menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no');
	};

	T.C = function(i){
		var t = T.Data[i].t;
		var m = T.Data[i].m;
		var r = '<div id="pTitle"><div id="ptc">'+ t +'</div><div id="pClose"><a href="javascript:;" onclick="$jE.H()"><img src="'+JE_HOST+'/bz/popimg/close.gif" alt="关闭" /></a></div></div><div id="pContent">'+ m +'</div><div id="pCall" style="display:none"><div id="callnum"></div></div><div id="pFoot"></div>'
		return r;
		};
//(function(){
		  //var elms;
		  //elms = [
			//creElm('link',{rel:'stylesheet',type:'text/css',href:JE_HOST+'/bz/popcss.css'})
//];
			//,creElm('script',{src:JE_HOST+'/js/crAd.js',charset:'utf-8'})
		
		//j=elms.length;while(j--){head.appendChild(elms[j])};
			
			 //})()
};

