/*
	Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


window[esri._dojoScopeName||"dojo"]._xdResourceLoaded(function(_1,_2,_3){return {depends:[["provide","dojox.cometd.timesync"],["require","dojox.cometd._base"]],defineResource:function(_4,_5,_6){if(!_4._hasResource["dojox.cometd.timesync"]){_4._hasResource["dojox.cometd.timesync"]=true;_4.provide("dojox.cometd.timesync");_4.require("dojox.cometd._base");_6.cometd.timesync=new function(){this._window=10;this._lags=[];this._offsets=[];this.lag=0;this.offset=0;this.samples=0;this.getServerTime=function(){return new Date().getTime()+this.offset;};this.getServerDate=function(){return new Date(this.getServerTime());};this.setTimeout=function(_7,_8){var ts=(_8 instanceof Date)?_8.getTime():(0+_8);var tc=ts-this.offset;var _9=tc-new Date().getTime();if(_9<=0){_9=1;}return setTimeout(_7,_9);};this._in=function(_a){var _b=_a.channel;if(_b&&_b.indexOf("/meta/")==0){if(_a.ext&&_a.ext.timesync){var _c=_a.ext.timesync;var _d=new Date().getTime();var l=(_d-_c.tc-_c.p)/2-_c.a;var o=_c.ts-_c.tc-l;this._lags.push(l);this._offsets.push(o);if(this._offsets.length>this._window){this._offsets.shift();this._lags.shift();}this.samples++;l=0;o=0;for(var i in this._offsets){l+=this._lags[i];o+=this._offsets[i];}this.offset=parseInt((o/this._offsets.length).toFixed());this.lag=parseInt((l/this._lags.length).toFixed());}}return _a;};this._out=function(_e){var _f=_e.channel;if(_f&&_f.indexOf("/meta/")==0){var now=new Date().getTime();if(!_e.ext){_e.ext={};}_e.ext.timesync={tc:now,l:this.lag,o:this.offset};}return _e;};};_6.cometd._extendInList.push(_4.hitch(_6.cometd.timesync,"_in"));_6.cometd._extendOutList.push(_4.hitch(_6.cometd.timesync,"_out"));}}};});