/*
 COPYRIGHT 2009 ESRI

 TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
 Unpublished material - all rights reserved under the
 Copyright Laws of the United States and applicable international
 laws, treaties, and conventions.

 For additional information, contact:
 Environmental Systems Research Institute, Inc.
 Attn: Contracts and Legal Services Department
 380 New York Street
 Redlands, California, 92373
 USA

 email: contracts@esri.com
 */

window[esri._dojoScopeName||"dojo"]._xdResourceLoaded(function(_1,_2,_3){return {depends:[["provide","esri.dijit.TimeSlider"],["require","dojox.form.RangeSlider"],["require","dijit.form.HorizontalRuleLabels"],["require","dijit.form.HorizontalRule"],["require","dojox.timing._base"]],defineResource:function(_4,_5,_6){if(!_4._hasResource["esri.dijit.TimeSlider"]){_4._hasResource["esri.dijit.TimeSlider"]=true;_4.provide("esri.dijit.TimeSlider");_4.require("dojox.form.RangeSlider");_4.require("dijit.form.HorizontalRuleLabels");_4.require("dijit.form.HorizontalRule");_4.require("dojox.timing._base");(function(){var _7=[_4.moduleUrl("dojox","form/resources/RangeSlider.css"),_4.moduleUrl("esri.dijit","css/TimeSlider.css")];var _8=document.getElementsByTagName("head").item(0),_9;for(var i=0,il=_7.length;i<il;i++){_9=document.createElement("link");_9.type="text/css";_9.rel="stylesheet";_9.href=_7[i];_8.appendChild(_9);}})();_4.declare("esri.dijit.TimeSlider",[_5._Widget,_5._Templated],{widgetsInTemplate:true,templateString:"   <div class=\"esriTimeSlider\">\r\n   <table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\r\n   <tr>\r\n   <td align=\"right\" valign=\"middle\"><button dojoType=\"dijit.form.Button\" showLabel=\"false\" iconClass=\"tsButton tsPlayButton\" dojoAttachEvent=\"onClick:_onPlay\" dojoAttachPoint=\"playPauseBtn\" type=\"button\">${NLS_play}</button></td>\r\n   <td align=\"center\" valign=\"middle\" width=\"80%\" id=\"tsTmp\"></td>\r\n   <td align=\"left\" valign=\"middle\" width=\"30\"><button dojoType=\"dijit.form.Button\" showLabel=\"false\" iconClass=\"tsButton tsPrevButton\" dojoAttachEvent=\"onClick:_onPrev\" dojoAttachPoint=\"previousBtn\" type=\"button\">${NLS_previous}</button></td>\r\n   <td align=\"left\" valign=\"middle\"><button dojoType=\"dijit.form.Button\" showLabel=\"false\" iconClass=\"tsButton tsNextButton\" dojoAttachEvent=\"onClick:_onNext\" dojoAttachPoint=\"nextBtn\" type=\"button\">${NLS_next}</button></td>\r\n   </tr>    \r\n   </table>\r\n   </div>\r\n",basePath:_4.moduleUrl("esri.dijit"),_slideDuration:1000,_defaultCount:10,constructor:function(_a,_b){_4.mixin(this,esri.bundle.widgets.timeSlider);this._iconClass="tsButton tsPlayButton";this.playing=false;this.loop=false;this.thumbCount=1;this.thumbMovingRate=1000;this._createTimeInstants=false;this._options=_4.mixin({excludeDataAtTrailingThumb:false,excludeDataAtLeadingThumb:false},_a.options||{});},startup:function(){this.inherited(arguments);this._timer=new _6.timing.Timer();this._timer.setInterval(this.thumbMovingRate);this._timer.onTick=_4.hitch(this,"_bumpSlider",1);this._createSlider();},destroy:function(){this._timer.stop();this._timer=null;this.timeStops=null;this._slider.destroy();this._slider=null;if(this._hTicks){this._hTicks.destroyRecursive();this._hTicks=null;}if(this._hLabels){this._hLabels.destroyRecursive();this._hLabels=null;}this.inherited(arguments);},onTimeExtentChange:function(){},onPlay:function(){},onPause:function(){},onNext:function(){},onPrevious:function(){},_onHorizontalChange:function(){var _c=this._sliderToTimeExtent();this.onTimeExtentChange(_c);},_onPlay:function(){this.playing=!this.playing;this._updateUI();if(this.playing){this._timer.start();this.onPlay(this._sliderToTimeExtent());}else{this._timer.stop();this.onPause(this._sliderToTimeExtent());}var _d=this._getSliderValue();this._offset=_4.isArray(_d)?(_d[1]-_d[0]):0;},_onNext:function(){if(!this.playing){this._bumpSlider(1);this.onNext(this._sliderToTimeExtent());}},_onPrev:function(){if(!this.playing){this._bumpSlider(-1);this.onPrevious(this._sliderToTimeExtent());}},createTimeStopsByCount:function(_e,_f){if(!_e||!_e.startTime||!_e.endTime){console.log(this.NLS_invalidTimeExtent);return;}_f=_f||this._defaultCount;var _10=Math.ceil((_e.endTime-_e.startTime)/(_f-1));this.createTimeStopsByTimeInterval(_e,_10,"esriTimeUnitsMilliseconds");},createTimeStopsByTimeInterval:function(_11,_12,_13,_14){if(!_11||!_11.startTime||!_11.endTime){console.log(this.NLS_invalidTimeExtent);return;}this.fullTimeExtent=new esri.TimeExtent(_11.startTime,_11.endTime);if(_14&&_14.resetStartTime===true){this._resetStartTime(this.fullTimeExtent,_13);}this._timeIntervalUnits=_13;var te=this.fullTimeExtent.startTime;var _15=[];while(te<=_11.endTime){_15.push(te);te=_11._getOffsettedDate(te,_12,_13);}if(_15.length>0&&_15[_15.length-1]<_11.endTime){_15.push(te);}this.setTimeStops(_15);},getCurrentTimeExtent:function(){return this._sliderToTimeExtent();},setTimeStops:function(_16){this.timeStops=_16||[];this._numStops=this.timeStops.length;this._numTicks=this._numStops;if(esri._isDefined(this.fullTimeExtent)===false){this.fullTimeExtent=new esri.TimeExtent(_16[0],_16[_16.length-1]);}},setLoop:function(_17){this.loop=_17;},setThumbCount:function(_18){this.thumbCount=_18;this.singleThumbAsTimeInstant(this._createTimeInstants);if(this._slider){this._createSlider();}},setThumbIndexes:function(_19){this.thumbIndexes=_4.clone(_19)||[0,1];this._initializeThumbs();},setThumbMovingRate:function(_1a){this.thumbMovingRate=_1a;if(this._timer){this._timer.setInterval(this.thumbMovingRate);}},setLabels:function(_1b){this.labels=_1b;if(this._slider){this._createSlider();}},setTickCount:function(_1c){this._numTicks=_1c;if(this._slider){this._createSlider();}},singleThumbAsTimeInstant:function(_1d){this._createTimeInstants=(_1d&&this.thumbCount===1);},next:function(){this._onNext();},pause:function(){this.playing=false;this._updateUI();this._timer.stop();},play:function(){if(this.playing===true){return;}this.playing=false;this._onPlay();},previous:function(){this._onPrev();},_updateUI:function(){_4.removeClass(this.playPauseBtn.iconNode,this._iconClass);this._iconClass=this.playing?"tsButton tsPauseButton":"tsButton tsPlayButton";_4.addClass(this.playPauseBtn.iconNode,this._iconClass);this.previousBtn.set("disabled",this.playing);this.nextBtn.set("disabled",this.playing);},_createSlider:function(){if(this._slider){this._slider.destroy();this._slider=null;}var _1e=this.domNode;while(_1e.parentNode&&!_1e.dir){_1e=_1e.parentNode;}var _1f={onChange:_4.hitch(this,"_onHorizontalChange"),showButtons:false,discreteValues:this._numStops,slideDuration:this._slideDuration,"class":"ts",id:"ts",dir:_1e.dir};var ts=_4.create("div",{id:"ts"},_4.byId("tsTmp"),"first");_4.create("div",{id:"timeSliderTicks"},ts,"first");_4.create("div",{id:"timeSliderLabels"},ts);if(this.thumbCount===2){this._createRangeSlider(_1f);}else{this._createSingleSlider(_1f);}this.thumbIndexes=this.thumbIndexes||[0,1];this._createHorizRule();this._createLabels();if(this._createTimeInstants===true){_4.query(".dijitSliderProgressBarH, .dijitSliderLeftBumper, .dijitSliderRightBumper").forEach("dojo.style(item, { background: 'none' });");}this._initializeThumbs();_4.disconnect(this._onChangeConnect);this._onChangeConnect=_4.connect(this._slider,"onChange",_4.hitch(this,"_updateThumbIndexes"));},_createRangeSlider:function(_20){this._isRangeSlider=true;this._slider=new _6.form.HorizontalRangeSlider(_20,_4.byId("ts"));},_createSingleSlider:function(_21){this._isRangeSlider=false;this._slider=new _5.form.HorizontalSlider(_21,_4.byId("ts"));},_createHorizRule:function(){if(this._hTicks){this._hTicks.destroyRecursive();this._hTicks=null;}if(this._numTicks<2){return;}this._hTicks=new _5.form.HorizontalRule({container:"topDecoration",ruleStyle:"","class":"tsTicks",count:this._numTicks,id:"tsTicks"},_4.byId("timeSliderTicks"));},_createLabels:function(){if(this._hLabels){this._hLabels.destroyRecursive();this._hLabels=null;}if(this.labels&&this.labels.length>0){this._hLabels=new _5.form.HorizontalRuleLabels({labels:this.labels,labelStyle:"","class":"tsLabels",id:"tsLabels"},_4.byId("timeSliderLabels"));}},_initializeThumbs:function(){if(!this._slider){return;}this._offset=this._toSliderValue(this.thumbIndexes[1])||0;var t1=this._toSliderValue(this.thumbIndexes[0]);t1=(t1>this._slider.maximum||t1<this._slider.minimum)?this._slider.minimum:t1;if(this._isRangeSlider===true){var t2=this._toSliderValue(this.thumbIndexes[1]);t2=(t2>this._slider.maximum||t2<this._slider.minimum)?this._slider.maximum:t2;t2=t2<t1?t1:t2;this._setSliderValue([t1,t2]);}else{this._setSliderValue(t1);}this._onHorizontalChange();},_bumpSlider:function(dir){var val=this._getSliderValue();var max=val,min=max;var _22=dir;if(_4.isArray(val)){min=val[0];max=val[1];_22=[{"change":dir,"useMaxValue":true},{"change":dir,"useMaxValue":false}];}if((Math.abs(min-this._slider.minimum)<1e-10&&dir<0)||(Math.abs(max-this._slider.maximum)<1e-10&&dir>0)){if(this._timer.isRunning){if(this.loop){this._timer.stop();this._setSliderValue(this._getSliderMinValue());var _23=this._sliderToTimeExtent();this.onTimeExtentChange(_23);this._timer.start();this.playing=true;}else{this.pause();}}}else{this._slider._bumpValue(_22);}},_updateThumbIndexes:function(){var val=this._getSliderValue();if(_4.isArray(val)){this.thumbIndexes[0]=this._toSliderIndex(val[0]);this.thumbIndexes[1]=this._toSliderIndex(val[1]);}else{this.thumbIndexes[0]=this._toSliderIndex(val);}},_sliderToTimeExtent:function(){if(!this.timeStops||this.timeStops.length===0){return;}var _24=new esri.TimeExtent();var val=this._getSliderValue();if(_4.isArray(val)){_24.startTime=new Date(this.timeStops[this._toSliderIndex(val[0])]);_24.endTime=new Date(this.timeStops[this._toSliderIndex(val[1])]);this._adjustTimeExtent(_24);}else{_24.startTime=(this._createTimeInstants===true)?new Date(this.timeStops[this._toSliderIndex(val)]):new Date(this.fullTimeExtent.startTime);_24.endTime=(this._createTimeInstants===true)?_24.startTime:new Date(this.timeStops[this._toSliderIndex(val)]);}return _24;},_adjustTimeExtent:function(_25){if(this._options.excludeDataAtTrailingThumb===false&&this._options.excludeDataAtLeadingThumb===false){return;}if(_25.startTime.getTime()===_25.endTime.getTime()){return;}if(this._options.excludeDataAtTrailingThumb){var _26=_25.startTime;_26.setUTCSeconds(_26.getUTCSeconds()+1);}if(this._options.excludeDataAtLeadingThumb){var _27=_25.endTime;_27.setUTCSeconds(_27.getUTCSeconds()-1);}},_resetStartTime:function(_28,_29){switch(_29){case "esriTimeUnitsSeconds":_28.startTime.setUTCMilliseconds(0);break;case "esriTimeUnitsMinutes":_28.startTime.setUTCSeconds(0,0,0);break;case "esriTimeUnitsHours":_28.startTime.setUTCMinutes(0,0,0);break;case "esriTimeUnitsDays":_28.startTime.setUTCHours(0,0,0,0);break;case "esriTimeUnitsWeeks":_28.startTime.setUTCDate(_28.startTime.getUTCDate()-_28.startTime.getUTCDay());break;case "esriTimeUnitsMonths":_28.startTime.setUTCDate(1);_28.startTime.setUTCHours(0,0,0,0);break;case "esriTimeUnitsDecades":_28.startTime.setUTCFullYear(_28.startTime.getUTCFullYear()-(_28.startTime.getUTCFullYear()%10));break;case "esriTimeUnitsCenturies":_28.startTime.setUTCFullYear(_28.startTime.getUTCFullYear()-(_28.startTime.getUTCFullYear()%100));break;}},_getSliderMinValue:function(){if(this._isRangeSlider){return [this._slider.minimum,this._slider.minimum+this._offset];}else{return this._slider.minimum;}},_toSliderIndex:function(val){var idx=Math.floor((val-this._slider.minimum)*this._numStops/(this._slider.maximum-this._slider.minimum));if(idx<0){idx=0;}if(idx>=this._numStops){idx=this._numStops-1;}return idx;},_toSliderValue:function(val){return val*(this._slider.maximum-this._slider.minimum)/(this._numStops-1)+this._slider.minimum;},_getSliderValue:function(){return this._slider.get("value");},_setSliderValue:function(val){this._slider._setValueAttr(val,false,false);}});}}};});