var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(input){var chr1,chr2,chr3,enc1,enc2,enc3,enc4,output="",i=0;for(input=Base64._utf8_encode(input);i<input.length;)enc1=(chr1=input.charCodeAt(i++))>>2,enc2=(3&chr1)<<4|(chr2=input.charCodeAt(i++))>>4,enc3=(15&chr2)<<2|(chr3=input.charCodeAt(i++))>>6,enc4=63&chr3,isNaN(chr2)?enc3=enc4=64:isNaN(chr3)&&(enc4=64),output=output+this._keyStr.charAt(enc1)+this._keyStr.charAt(enc2)+this._keyStr.charAt(enc3)+this._keyStr.charAt(enc4);return output},decode:function(input){var chr1,chr2,chr3,enc2,enc3,enc4,output="",i=0;for(input=input.replace(/[^A-Za-z0-9\+\/\=]/g,"");i<input.length;)chr1=this._keyStr.indexOf(input.charAt(i++))<<2|(enc2=this._keyStr.indexOf(input.charAt(i++)))>>4,chr2=(15&enc2)<<4|(enc3=this._keyStr.indexOf(input.charAt(i++)))>>2,chr3=(3&enc3)<<6|(enc4=this._keyStr.indexOf(input.charAt(i++))),output+=String.fromCharCode(chr1),64!=enc3&&(output+=String.fromCharCode(chr2)),64!=enc4&&(output+=String.fromCharCode(chr3));return output=Base64._utf8_decode(output)},_utf8_encode:function(string){string=string.replace(/\r\n/g,"\n");for(var utftext="",n=0;n<string.length;n++){var c=string.charCodeAt(n);c<128?utftext+=String.fromCharCode(c):c>127&&c<2048?(utftext+=String.fromCharCode(c>>6|192),utftext+=String.fromCharCode(63&c|128)):(utftext+=String.fromCharCode(c>>12|224),utftext+=String.fromCharCode(c>>6&63|128),utftext+=String.fromCharCode(63&c|128))}return utftext},_utf8_decode:function(utftext){for(var string="",i=0,c=c1=c2=0;i<utftext.length;)(c=utftext.charCodeAt(i))<128?(string+=String.fromCharCode(c),i++):c>191&&c<224?(c2=utftext.charCodeAt(i+1),string+=String.fromCharCode((31&c)<<6|63&c2),i+=2):(c2=utftext.charCodeAt(i+1),c3=utftext.charCodeAt(i+2),string+=String.fromCharCode((15&c)<<12|(63&c2)<<6|63&c3),i+=3);return string}},oldErrHandler=window.onerror;if(window.onerror=function(msg,url,line){return(new Image).src="/log?reason=js_error&msg="+encodeURIComponent(msg+"|"+url+"|"+line),!!oldErrHandler&&oldErrHandler(msg,url,line)},window.self!=window.top){var img=new Image;img.src="/log?reason=iframe&msg="+encodeURIComponent("iframe; referer="+document.referrer)}MirrorsChecker={mirrors:{},mirrorsCounter:{},stats:{},isStarted:!1,foundIndex:-1,timeoutId:null,intervalId:null,startTime:0,position:0,orderPosition:null,settings:{mirrorTimeout:5,checkMirrorsOrder:["d","p","m"],noNeedRedirect:["d"],redirectUrl:"",async:!0,alias:null},getWorkTime:function(){return((new Date).getTime()-MirrorsChecker.startTime)/1e3},getAsync:function(order){switch(order){case"d":return!0;case"p":return!1;default:return MirrorsChecker.settings.async}},isPingDomains:function(order){for(var i=0;i<MirrorsChecker.settings.noNeedRedirect.length;i++)if(order==MirrorsChecker.settings.noNeedRedirect[i])return!0;return!1},init:function(mirrors){MirrorsChecker.setMirrors(mirrors),MirrorsChecker.settings.mirrorTimeout>0&&(MirrorsChecker.timeoutId=window.setTimeout(function(){MirrorsChecker.finish("m")},1e3*MirrorsChecker.settings.mirrorTimeout)),MirrorsChecker.intervalId=window.setInterval(function(){MirrorsChecker.run()},100)},setMirrors:function(mirrors){MirrorsChecker.mirrors=mirrors;for(var type in MirrorsChecker.mirrors)MirrorsChecker.mirrorsCounter[type]={},MirrorsChecker.mirrorsCounter[type].length=MirrorsChecker.mirrors[type].length,MirrorsChecker.mirrorsCounter[type].parsed=0},run:function(){if(!MirrorsChecker.isStarted){var order=MirrorsChecker.settings.checkMirrorsOrder[MirrorsChecker.position];if(void 0===MirrorsChecker.mirrors[order]||MirrorsChecker.mirrors[order].length<1)MirrorsChecker.position++;else{MirrorsChecker.isStarted=!0;var async=MirrorsChecker.getAsync(order);if(async)for(var index in MirrorsChecker.mirrors[order])MirrorsChecker.createPingImage(index,order,async);else MirrorsChecker.createPingImage(0,order,async);MirrorsChecker.isPingDomains(order)&&(MirrorsChecker.isStarted=!1,MirrorsChecker.position++)}MirrorsChecker.settings.checkMirrorsOrder.length<MirrorsChecker.position&&window.clearInterval(MirrorsChecker.intervalId)}},finish:function(order){MirrorsChecker.sendStats(order);var redirect_url="/redirect?t="+MirrorsChecker.getWorkTime()+"&reason=";MirrorsChecker.foundIndex>-1?(redirect_url+="success_ping&ri="+MirrorsChecker.foundIndex+"&ro="+order,MirrorsChecker.settings.alias&&(redirect_url+="&alias="+MirrorsChecker.settings.alias)):redirect_url+="no_mirrors",MirrorsChecker.redirect(redirect_url+"&to="+Base64.encode(MirrorsChecker.settings.redirectUrl))},createPingImage:function(index,order,isAsync){var img=new Image;MirrorsChecker.addEvent(img,"load",function(){MirrorsChecker.imgOnLoad(index,order)}),MirrorsChecker.addEvent(img,"error",function(){MirrorsChecker.imgOnError(index,order,isAsync)}),img.src=MirrorsChecker.decode(MirrorsChecker.mirrors[order][index])+"/ping.png?t="+(new Date).getTime()},imgOnLoad:function(index,order){return MirrorsChecker.setStats(index,order,1),!MirrorsChecker.isPingDomains(order)&&(MirrorsChecker.foundIndex<0&&(window.clearTimeout(MirrorsChecker.timeoutId),window.clearInterval(MirrorsChecker.intervalId),MirrorsChecker.foundIndex=index,window.setTimeout(function(){MirrorsChecker.finish(order)},500)),!1)},imgOnError:function(index,order,isAsync){return MirrorsChecker.setStats(index,order,0),!MirrorsChecker.isPingDomains(order)&&(!isAsync&&index+1<MirrorsChecker.mirrors[order].length&&MirrorsChecker.createPingImage(index+1,order,isAsync),MirrorsChecker.mirrorsCounter[order].parsed>=MirrorsChecker.mirrorsCounter[order].length&&(MirrorsChecker.position++,MirrorsChecker.isStarted=!1),!1)},setStats:function(index,order,status){void 0===MirrorsChecker.stats[order]&&(MirrorsChecker.stats[order]=[]),MirrorsChecker.stats[order][index]=status,MirrorsChecker.mirrorsCounter[order].parsed++},sendStats:function(order){var src="/send-stats?",value="";for(var xo in MirrorsChecker.stats)for(var index in MirrorsChecker.stats[xo])value+="domains["+encodeURIComponent(MirrorsChecker.mirrors[xo][index])+"]="+MirrorsChecker.stats[xo][index]+"&";src+=value,src+="ri="+MirrorsChecker.foundIndex,src+="ro="+order,(new Image).src=src},redirect:function(url){window.location.href=url},decode:function(url){return"string"!=typeof url?"":Base64.decode(url)},addEvent:function(obj,event,fn){obj.addEventListener?obj.addEventListener(event,fn,!1):obj.attachEvent?obj.attachEvent("on"+event,function(){return fn.call(obj,window.event)}):obj["on"+event]=fn}};