_zi={};(function(){var cookieProvider=function(config){};cookieProvider.prototype={path:null,domain:null,secure:false,expires:null,enable:navigator.cookieEnabled,set:function(name,value){if(this.enable){document.cookie=name+"="+this.encodeValue(value)+(this.expires==null?"":("; expires="+this.expires.toGMTString()))+((this.path==null)?"":("; path="+this.path))+((this.domain==null)?"":("; domain="+this.domain))+((this.secure==true)?"; secure":"")}return this},get:function(name){if(this.enable){var cookies={},c=document.cookie+";",re=new RegExp(name+"=([^;]*)");var macths=re.exec(c);if(macths){return this.decodeValue(macths[1])}}return null},remove:function(name){document.cookie=name+"=null; expires=Thu, 01-Jan-70 00:00:01 GMT"+((this.path==null)?"":("; path="+this.path))+((this.domain==null)?"":("; domain="+this.domain))+((this.secure==true)?"; secure":"")},getJson:function(name){return eval("("+(this.get(name))+")")},decodeValue:function(v){return decodeURIComponent(v)},encodeValue:function(v){return encodeURIComponent(v)}};var cookie=_zi.cookie=new cookieProvider();var checker=_zi.cookieChecker=(function(){var suspend=true,interval=Math.round(Math.random()*100)+300,timer,writer=false,lg,key,id=Math.round(Math.random()*200000000),count=0,receptInited=false,timerRecept,keyRecept,markRecept="recept:true",invalidTime=1000*3;function notify(){try{cookie.set(keyRecept,"{creator:'"+(window.name+id)+"',time:"+(+new Date())+"}")}catch(e){}}return{init:function(login,fn,scope){this.fn=fn;this.scope=scope;lg=login;key="ZhomaBar_"+lg;keyRecept=key+"_recept";window.name+="";if(window.name.search(login)==-1){window.name+=login}return this},start:function(){var _self=this;if(window.name&&window.name.search(lg)>-1&&window.name.search(markRecept)>-1){this.turnOnRecept()}else{timer=setInterval(function(){try{var has=cookie.getJson(keyRecept);if(has==null){_self.turnOnRecept();return}if(has.creator==(window.name+id)){if(count++>6){_self.turnOnRecept()}}else{count=0;if(has.creator!==undefined){if(has.time!==undefined){if((+new Date())-has.time>invalidTime){_self.rap()}}else{_self.rap()}}else{_self.rap()}}}catch(e){}},interval)}},turnOffRecept:function(change){receptInited=false;if(change){window.name=(""+window.name).replace(new RegExp(markRecept,"ig"),"")}if(timerRecept){clearInterval(timerRecept)}this.start()},rap:function(){notify()},turnOnRecept:function(){if(!receptInited){if(timer){clearInterval(timer)}count=0;this.beat()}if(this.fn){this.fn.call(this.scope||window,true)}},beat:function(){function clear(){if(receptInited){cookie.set(keyRecept,"{}")}if(timer){clearInterval(timer)}if(timerRecept){clearInterval(timerRecept)}}if(window.addEventListener){window.addEventListener("unload",clear,true)}else{if(window.attachEvent){window.attachEvent("onbeforeunload",clear)}}receptInited=true;window.name+=markRecept;notify();timerRecept=setInterval(notify,1000*1)}}})();window.Zibar={store:{addChatPanel:{},start:false},addChatPanel:function(blogin,config){this.store.addChatPanel[blogin]=config;this.start();return this},start:function(){checker.turnOnRecept();return this}};function bindReady(fn){if(document.addEventListener){document.addEventListener("DOMContentLoaded",function(){document.removeEventListener("DOMContentLoaded",arguments.callee,false);fn()},false);document.addEventListener("load",fn,true)}else{if(document.attachEvent){if(document.documentElement.doScroll&&window==window.top){(function(){try{document.documentElement.doScroll("left")}catch(e){setTimeout(arguments.callee,13);return}fn()})()}window.attachEvent("load",fn)}}}var inited=false;bindReady(function(){if(inited){return}inited=true;var script=document.getElementById("__zhoma__zibar");if(!script){var scripts=document.getElementsByTagName("script"),reg=/zibar[-]ws[.]zhoma[.]com(:\d*)?\/zibar\/embed.js$/;for(var i=0;i<scripts.length;i++){if(reg.test(scripts[i].src||"")){script=scripts[i];break}}if(!script){return false}}var config=_zi.config={anonymous:false,script:script,token:script.getAttribute("token")||"",stoken:script.getAttribute("stoken")||"",domain:script.getAttribute("domain"),alias:script.getAttribute("alias"),login:script.getAttribute("login"),nick:script.getAttribute("nick"),theme:script.getAttribute("theme")||"default",apis:script.getAttribute("apis"),version:script.getAttribute("version")||"1.0",prefPattern:script.getAttribute("profile"),avatarPattern:script.getAttribute("avatar")};if(typeof config.apis=="string"){var a=config.apis.split(",");for(var i=0;i<a.length;i++){if(a[i].length>0){eval(" config."+a[i].replace(/^\s+|\s+$/g,"")+"= true;")}}config.addable=config.buddyAddDirectly==true||config.buddyRequest==true;config.needRequest=config.buddyAddDirectly==true?false:true}if(config.login===null){config.anonymous=true;config.addable=false;config.statusChanged=config.userList=config.userSearch=true;var matches=(cookie.get(config.domain+"_anony")||"").split("/");if(matches[0]&&matches[1]){config.login=matches[0];config.nick=matches[1]}else{config.login=Math.round(Math.random()*99999999);config.nick=(config.nick||"\u6E38\u5BA2")+Math.round(Math.random()*1000);cookie.set(config.domain+"_anony",config.login+"/"+config.nick,null)}}function init(){var head=document.getElementsByTagName("head")[0];function script(url){var add=document.createElement("script");add.setAttribute("type","text/javascript");add.setAttribute("src",url);add.setAttribute("charset","utf-8");head.appendChild(add)}function css(url){var add=document.createElement("link");add.setAttribute("type","text/css");add.setAttribute("rel","stylesheet");add.setAttribute("media","screen");add.setAttribute("href",url);head.appendChild(add)}css("http://zibar-ws.zhoma.com/zibar/css/"+config.theme+"/zhoma_zibar.css");script("http://zibar-ws.zhoma.com/zibar/js/"+config.version+"/zhoma_zibar_load.js")}init()})})();
