function ModelDataLayer(){}ModelDataLayer.prototype.initialize=function(C,B,D,A){this.map_=C;this.name_=B;this.sidebarPrefix_=D;this.options_=A||{};this.layer_=new ModelData(this.name_,this.sidebarPrefix_,this.options_);this.streets_=this.options_.streets||null;GEvent.bind(this.layer_,"loadstart",this,function(){GEvent.trigger(this,"loadstart")});GEvent.bind(this.layer_,"loadend",this,function(){GEvent.trigger(this,"loadend")});GEvent.bind(this.layer_,"loaderror",this,function(E){GEvent.trigger(this,"loaderror",E)});GEvent.bind(this.layer_,"settingschanged",this,function(){GEvent.trigger(this,"settingschanged")})};ModelDataLayer.prototype.toggle=function(A){if(A){this.map_.addOverlay(this.layer_);this.layer_.rememberToggleState(true);this.layer_.disabled_=true;if(this.streets_){this.streets_.attachTo(this.name_)}this.layer_.addClickListeners();this.keystrokeListener=GEvent.bindDom(document,"keydown",this.layer_,this.layer_.handleKeystroke);this.layer_.requestConfigTimerRestart(this.layer_.requestConfigInterval);this.layer_.requestConfig()}else{this.layer_.requestConfigTimerStop();GEvent.removeListener(this.keystrokeListener);this.layer_.removeClickListeners();if(this.streets_){this.streets_.detachFrom(this.name_)}this.layer_.removeMapTitle();this.layer_.rememberToggleState(false);this.map_.removeOverlay(this.layer_)}};ModelDataLayer.prototype.toQueryString=function(){return this.layer_.toQueryString()};ModelData.prototype=new WUI_ImageLayer();function ModelData(B,C,A){WUI_ImageLayer.call(this,B,C,A);this.clkObjects=[];this.clkListeners=[];this.incompleteCrossSection=-1;this.numClkObjects=0;this.maxClkObjects=A.maxClkObjects||10;this.displayAreaTab=this.options_.displayAreaTab||null;this.mapTitle=null;this.maptypeKeyLookup={};this.disabled_=true;this.periodEpochs=[];this.modelrunEpoch=0;this.hourEpoch=0;this.hourEpochSave=null;this.config=null;this.requestConfigInterval=600*1000;this.requestConfigTimer=null}ModelData.prototype.copy=function(){if(this.debug_==1){GLog.write("ModelData::copy")}return new ModelData(this.name_,this.sidebarPrefix_,this.options_)};ModelData.prototype.getURL=function(){var K=this.map_.getSize();var N=K.width;var L=K.height;var J=Math.floor(N*this.extraImageLoadFactor_);var I=Math.floor(L*this.extraImageLoadFactor_);var O=Math.floor((J-N)/2);var R=Math.floor((I-L)/2);var W=this.map_.fromContainerPixelToLatLng(new GPoint(0-O,0-R));var F=this.map_.fromContainerPixelToLatLng(new GPoint(N+O,L+R));var G=W.lat();var D=F.lng();var S=F.lat();var Q=W.lng();if(Q>D){Q-=360}var U=O+N-110;var T=R+41;var B=this.getModel();var M=this.getMaptype();var E=this.getHour();var V=this.getModelrunInitReadable();var C="http://modelmaps.wunderground.com/php/run.php?model="+B+"&script="+M+"&hour="+E+"&modelrun="+V+"&maxlat="+G+"&maxlon="+D+"&minlat="+S+"&minlon="+Q+"&width="+J+"&height="+I;var A=new Date();var H=A.getTime();var P=Math.floor(H/60000);C+="&rand="+P;return C};ModelData.prototype.addClickListeners=function(){this.mapClickListener_=GEvent.bind(this.map_,"click",this,function(D,A){if(!A){return }var C=this.clkObjects.length;if(this.numClkObjects>=this.maxClkObjects){GLog.write("Maximum of "+this.maxClkObjects+" profiles or cross sections at a time, please close some to continue.");return }else{if(this.getClickBehavior()=="1"){this.numClkObjects++;var G={marker1:new GMarker(A,{clickable:true,draggable:true}),index:C,container:new Element("p"),img:new Element("img"),isLoaded:false,popout:null,popoutUrl:"",type:"profile"};this.map_.addOverlay(G.marker1);this.clkObjects[C]=G;var H=GEvent.callbackArgs(this,this.profileDragEnd,G);GEvent.bind(G.marker1,"dragend",this,H);this.profileRequest(G)}else{if(this.getClickBehavior()=="2"&&this.incompleteCrossSection>=0){this.numClkObjects++;var B=this.clkObjects[this.incompleteCrossSection];B.marker2=new GMarker(A,{clickable:true,draggable:true});this.map_.addOverlay(B.marker2);this.snapToLine(B.marker1,B.marker2);B.line=this.makeCrossSectionLine(B);this.map_.addOverlay(B.line);var F=GEvent.callbackArgs(this,this.crossSectionDragEnd,B,1);var E=GEvent.callbackArgs(this,this.crossSectionDragEnd,B,2);GEvent.bind(B.marker1,"dragend",this,F);GEvent.bind(B.marker2,"dragend",this,E);this.incompleteCrossSection=-1;this.crossSectionRequest(B)}else{if(this.getClickBehavior()=="2"){var B={marker1:new GMarker(A,{clickable:true,draggable:true}),marker2:null,line:null,index:C,container:new Element("p"),img:new Element("img"),isLoaded:false,popout:null,popoutUrl:"",type:"crossSection"};this.map_.addOverlay(B.marker1);this.clkObjects[C]=B;this.incompleteCrossSection=C}}}}});this.bodyUnloadListener_=GEvent.bindDom(window,"beforeunload",this,this.closePopouts)};ModelData.prototype.removeClickListeners=function(){GEvent.removeListener(this.bodyUnloadListener_);GEvent.removeListener(this.mapClickListener_);this.closePopouts();this.removeClkObjects()};ModelData.prototype.profileDragEnd=function(A){this.profileRequest(A)};ModelData.prototype.crossSectionDragEnd=function(B,A){if(A==1){this.snapToLine(B.marker2,B.marker1)}else{if(A==2){this.snapToLine(B.marker1,B.marker2)}}this.map_.removeOverlay(B.line);B.line=null;B.line=this.makeCrossSectionLine(B);this.map_.addOverlay(B.line);this.crossSectionRequest(B)};ModelData.prototype.snapToLine=function(E,B){var F=this.map_.fromLatLngToDivPixel(E.getLatLng());var A=this.map_.fromLatLngToDivPixel(B.getLatLng());var D=Math.abs(A.x-F.x);var C=Math.abs(A.y-F.y);if(C<D){B.setLatLng(new GLatLng(E.getLatLng().lat(),B.getLatLng().lng()))}else{B.setLatLng(new GLatLng(B.getLatLng().lat(),E.getLatLng().lng()))}};ModelData.prototype.profileRequest=function(E){GEvent.trigger(this,"loadstart");var I=E.marker1.getLatLng().lat();var B=E.marker1.getLatLng().lng();var C=850/4;var K=1100/4;var J=600;var D=800;var G=this.getModel();var F=this.getHour();var H=this.getModelrunInitReadable();var A="http://modelmaps.wunderground.com/php/skewt.php?model="+G+"&script=plotskew&hour="+F+"&modelrun="+H+"&maxlat="+I+"&maxlon="+B;E.popoutUrl=A+"&width="+J+"&height="+D;A+="&width="+C+"&height="+K;if(this.debug_>0){GLog.write(A)}this.showDisplayAreaImage(A,J,D,E);GEvent.trigger(this,"loadend")};ModelData.prototype.crossSectionRequest=function(A){GEvent.trigger(this,"loadstart");var G=Math.max(A.marker1.getLatLng().lat(),A.marker2.getLatLng().lat());var L=Math.max(A.marker1.getLatLng().lng(),A.marker2.getLatLng().lng());var E=Math.min(A.marker1.getLatLng().lat(),A.marker2.getLatLng().lat());var J=Math.min(A.marker1.getLatLng().lng(),A.marker2.getLatLng().lng());var C=200;var M=150;var K=800;var D=600;var H=this.getModel();var F=this.getHour();var I=this.getModelrunInitReadable();var B="http://modelmaps.wunderground.com/php/cross.php?model="+H+"&script=cross&hour="+F+"&modelrun="+I+"&maxlat="+G+"&maxlon="+L+"&minlat="+E+"&minlon="+J;A.popoutUrl=B+"&width="+K+"&height="+D;B+="&width="+C+"&height="+M;if(this.debug_>0){GLog.write(B)}this.showDisplayAreaImage(B,K,D,A);GEvent.trigger(this,"loadend")};ModelData.prototype.showDisplayAreaImage=function(C,A,D,F){if(this.displayAreaTab&&!F.isLoaded){var G=F.index;var E=new Element("a",{href:"#",events:{click:function(J,H,I){J=new Event(J).stop();this.removeClkObject(I)}.bindAsEventListener(this,[F.container,F.index])}}).setText("(close)");var B=new Element("a",{href:"#",events:{click:function(K,J,H,I){K=new Event(K).stop();J.popout=this.popoutImage(H,I,J.index,J.type)}.bindAsEventListener(this,[F,A,D])}}).setText("(pop out)");F.isLoaded=true;F.container.appendText(G+" ");F.container.adopt(E);F.container.appendText(" ");F.container.adopt(B);F.container.adopt(new Element("br"));F.container.adopt(F.img);this.displayAreaTab.writeDom(F.container)}else{if(!F.isLoaded&&!this.displayAreaTab){F.popout=this.popoutImage(A,D,F.index,F.type);F.isLoaded=true}}if(F.popout){if(F.popout.closed||!F.popout.location){F.popout=this.popoutImage(A,D,F.index,F.type)}else{F.img.src=F.popoutUrl;if(window.focus){F.popout.focus()}}}else{F.img.src=C}};ModelData.prototype.popoutImage=function(E,A,C,D){var B=window.open("/stationmaps/gmap_popout.asp?index="+C+"&type="+D,C,"width="+E+",height="+A+",resizable=yes");if(window.focus){B.focus()}return B};ModelData.prototype.popoutLoaded=function(B){var D=this.clkObjects[B];D.container.empty().remove();D.container=null;this.numClkObjects--;var A=D.popout.document.getElementById("canvas");var C=D.popout.document.createElement("img");C.src=D.popoutUrl;A.appendChild(C);D.img=C};ModelData.prototype.popoutClosed=function(A){this.removeClkObject(A)};ModelData.prototype.makeCrossSectionLine=function(B){var A=[B.marker1.getLatLng(),B.marker2.getLatLng()];return new GPolyline(A)};ModelData.prototype.closePopouts=function(){for(var A=this.clkObjects.length-1;A>=0;A--){this.closePopout(A)}};ModelData.prototype.closePopout=function(B){if(this.clkObjects[B]){var A=this.clkObjects[B].popout;if(A&&(!A.closed)){A.close();this.clkObjects[B].popout=null}}};ModelData.prototype.removeClkObjects=function(){for(var A=this.clkObjects.length-1;A>=0;A--){this.removeClkObject(A)}this.incompleteCrossSection=-1;this.numClkObjects=0};ModelData.prototype.removeClkObject=function(A){if(this.clkObjects[A]){if(this.clkObjects[A].marker1){this.map_.removeOverlay(this.clkObjects[A].marker1);this.clkObjects[A].marker1=null}if(this.clkObjects[A].marker2){this.map_.removeOverlay(this.clkObjects[A].marker2);this.clkObjects[A].marker2=null}if(this.clkObjects[A].line){this.map_.removeOverlay(this.clkObjects[A].line);this.clkObjects[A].line=null}if(this.clkObjects[A].container){this.clkObjects[A].container.empty();this.clkObjects[A].container.remove();this.clkObjects[A].container=null}this.clkObjects[A]=null;this.numClkObjects--}};ModelData.prototype.addSidebarListeners=function(){try{this.modelListener=GEvent.bindDom($(this.sidebarPrefix_+"_model"),"change",this,function(){this.populateMaptypeOptions();this.populateModelrunOptions();this.populateHourOptions(true)})}catch(H){}try{this.maptypeListener=GEvent.bindDom($(this.sidebarPrefix_+"_maptype"),"change",this,function(){this.updateMaptypeDescription();GEvent.trigger(this,"settingschanged");this.redrawOnMoveEnd()})}catch(H){}try{this.modelrunListener=GEvent.bindDom($(this.sidebarPrefix_+"_modelrun"),"change",this,function(){this.modelrunEpoch=this.getModelrunInitEpoch();this.populateHourOptions(true)})}catch(H){}var G=document.getElementsByName(this.sidebarPrefix_+"_click");for(var E=0;E<G.length;E++){var C=GEvent.bindDom(G[E],"click",this,function(){GEvent.trigger(this,"settingschanged")});this.clkListeners.push(C)}try{if(!this.hourListener){var F=$(this.sidebarPrefix_+"_hour_slider");var B=$(this.sidebarPrefix_+"_hour_knob");var A=parseInt(this.getHourMax(),10);this.hourListener=new Slider(F,B,{steps:A,onChange:function(I){this.handleHourMoveChange(I)}.bind(this),onComplete:function(I){if(this.recallToggleState()==true){var I=parseInt(I,10);this.handleHourMoveComplete(I)}}.bind(this)});var D=this.getHourInit();this.hourListener.set(D)}}catch(H){}};ModelData.prototype.removeSidebarListeners=function(){try{GEvent.removeListener(this.modelListener)}catch(B){}try{GEvent.removeListener(this.maptypeListener)}catch(B){}try{GEvent.removeListener(this.modelrunListener)}catch(B){}for(var A=0;A<this.clkListeners.length;A++){GEvent.removeListener(this.clkListeners[A])}};ModelData.prototype.toQueryString=function(){var D=this.name_;var C=this.getModel();var F=this.getMaptype();var A=this.getHour();var B=this.getOpacity();var E=this.getClickBehavior();return D+".mdl="+C+"&"+D+".type="+F+"&"+D+".hour="+A+"&"+D+".opa="+B+"&"+D+".clk="+E};ModelData.prototype.toPrefsObject=function(){var A={};var B=this.name_.toUpperCase();A[B+"OPA"]=this.getOpacity();A[B+"MDL"]=this.getModel();A[B+"TYPE"]=this.getMaptype();A[B+"HOUR"]=this.getHour();A[B+"CLK"]=this.getClickBehavior();return A};ModelData.prototype.getModel=function(){try{return $(this.sidebarPrefix_+"_model").getValue()}catch(A){return"GFS"}};ModelData.prototype.getMaptype=function(){try{return $(this.sidebarPrefix_+"_maptype").getValue()}catch(A){return"500"}};ModelData.prototype.getHourInit=function(){try{return $(this.sidebarPrefix_+"_hour").getValue()}catch(A){return"0"}};ModelData.prototype.getHour=function(){try{return this.hour}catch(A){return"0"}};ModelData.prototype.getHourMax=function(){try{return this.periods.length}catch(A){return"29"}};ModelData.prototype.getModelrun=function(){try{return $(this.sidebarPrefix_+"_modelrun").getValue()}catch(A){return"node_0"}};ModelData.prototype.getModelrunInitReadable=function(){try{var A=this.getModel();var D=this.getModelrun();var B=this.config.MODEL[A].modelrun[D];return B.initialization.readable}catch(C){return"0"}};ModelData.prototype.getModelrunInitEpoch=function(){try{var A=this.getModel();var D=this.getModelrun();var B=this.config.MODEL[A].modelrun[D];return parseInt(B.initialization.epoch,10)}catch(C){return 0}};ModelData.prototype.getClickBehavior=function(){try{var C=document.getElementsByName(this.sidebarPrefix_+"_click");for(var A=0;A<C.length;A++){if(C[A].checked){return C[A].value}}throw"no elt is checked"}catch(B){return"0"}};ModelData.prototype.handleKeystroke=function(C){var C=new Event(C);try{var E="j";var B="l";var A="a";var H="d";var P="i";var N="k";var K="w";var F="s";var G="r";var M="f";if(C.key==E){this.hourListener.decrement(1)}else{if(C.key==B){this.hourListener.increment(1)}else{if(C.key==A){var I=this.hourEpoch-86400;var J=this.periodEpochs.indexOfClosest(I);this.hourListener.set(J)}else{if(C.key==H){var I=this.hourEpoch+86400;var J=this.periodEpochs.indexOfClosest(I);this.hourListener.set(J)}else{if([P,N,K,F,G,M].contains(C.key)){var D=null;if([G,M].contains(C.key)){D=$(this.sidebarPrefix_+"_model")}else{if([P,N].contains(C.key)){D=$(this.sidebarPrefix_+"_maptype")}else{if([K,F].contains(C.key)){D=$(this.sidebarPrefix_+"_modelrun")}}}var O=D.selectedIndex;var Q=0;if([G,P,K].contains(C.key)){Q=(O-1).limit(0,D.length-1)}else{Q=(O+1).limit(0,D.length-1)}if(O!=Q){D.selectedIndex=Q;GEvent.trigger(D,"change")}}}}}}}catch(L){GEvent.trigger(this,"loaderror",'error capturing keystroke: "'+C.key+'" ('+L.message+")")}};ModelData.prototype.requestConfig=function(){var A="/stationmaps/gmap_modeldata.asp";var C=this.handleConfig.bind(this);var B=new Json.Remote(A,{onComplete:C,onFailure:function(){GEvent.trigger(this,"loaderror","failed to load config file: "+A);this.loading_=false}.bind(this)}).send(null)};ModelData.prototype.handleConfig=function(C){var B=(this.config==null);var A="";this.config=C;if(!C){A="empty or invalid config file"}else{if(C.ERROR){A="error reading config file: "+C.ERROR}}if(A){GEvent.trigger(this,"loaderror",A);return }if(B){this.populateModelOptions();this.populateMaptypeOptions()}this.populateModelrunOptions();this.populateHourOptions();this.disabled_=false;this.redrawOnMoveEnd()};ModelData.prototype.populateModelOptions=function(){var F=$(this.sidebarPrefix_+"_model");for(var C in this.config.MODEL){var B=C;var E=B;var D=(B==this.defaultModel)?true:false;var A=new Option(E,B,D);F.options[F.length]=A}};ModelData.prototype.populateMaptypeOptions=function(){var C=$(this.sidebarPrefix_+"_maptype");var E=this.getModel();var A=this.config.MODEL[E].MAP;var F=$pick(this.getMaptype(),this.defaultMaptype);C.length=0;this.maptypeKeyLookup={};for(var D in A){var I=A[D].key;var H=A[D].abbreviation||I;var G=(I==F)?true:false;var B=new Option(H,I,G);C.options[C.length]=B;this.maptypeKeyLookup[I]=D}this.updateMaptypeDescription()};ModelData.prototype.populateModelrunOptions=function(){var C=$(this.sidebarPrefix_+"_modelrun");var I=this.getModel();var J=this.config.MODEL[I].modelrun;var Q=this.modelrunEpoch;var E=-1;var N=false;var K=0;var D=[];$each(J,function(R,U){try{var S=R.initialization.epoch}catch(T){GLog.write("Missing initialization.epoch for "+I+" modelrun: "+G);return }D.push({key:U,value:R})});D.sort(this.sortInitEpoch);D.reverse();if(Q){var M=[];for(var G=0;G<D.length;G++){M.push(parseInt(D[G].value.initialization.epoch,10))}E=M.indexOfClosest(Q)}C.length=0;for(var G=0;G<D.length;G++){var B=D[G].value.initialization.epoch;var F=D[G].value.finished;if(F!="1"){N=true;K+=1}var L=false;if(E>=0){if(G==E){L=true}}else{if(G==K){L=true}}var P=this.epochToString(B*1000);var O=P;var A=new Option(O,D[G].key,L);C.options[C.length]=A}this.modelrunEpoch=this.getModelrunInitEpoch();var H=$(this.sidebarPrefix_+"_unfinished");if(H&&N){H.setText("unfinished modelrun available")}else{if(H){H.empty()}}};ModelData.prototype.populateHourOptions=function(E){var A=this.getModel();var H=this.getModelrun();var C=this.config.MODEL[A].modelrun[H];if(!C){GEvent.trigger(this,"loaderror","invalid modelrun name: "+H);return }var G=this.hourEpoch;var F=this.hourEpochSave;var B=0;this.periods=[];$each(C.period,function(J,I){if(J.exists=="1"){this.periods.push(J)}},this);this.periods.sort(this.sortPeriodNumber);this.periodEpochs=[];$each(this.periods,function(J,I){this.periodEpochs.push(parseInt(J.valid,10))},this);if(E&&this.hourEpochSave){B=this.periodEpochs.indexOfClosest(this.hourEpochSave)}else{if(G){B=this.periodEpochs.indexOfClosest(G)}}var D=this.hourListener.get();this.hourListener.setMax(this.periods.length-1);this.hourListener.set(B);if(B==D){this.handleHourMoveChange(B);this.handleHourMoveComplete(B)}if(E){if(F){this.hourEpochSave=F}else{this.hourEpochSave=G}}};ModelData.prototype.calculateHour=function(A){try{this.hour=parseInt(this.periods[A].hour,10)}catch(B){this.hour=0}};ModelData.prototype.getHourString=function(A){try{this.hourEpoch=parseInt(this.periods[A].valid,10);var B=this.hourEpoch*1000;return this.epochToString(B)}catch(C){return"unknown"}};ModelData.prototype.epochToString=function(C){var E=new Date(C);var A=getDayAbbr(E.getUTCDay());var D=getMonthAbbr(E.getUTCMonth());var B=zeroPad(A+", "+E.getUTCDate(),2)+" "+D+" "+zeroPad(E.getUTCHours(),2)+":"+zeroPad(E.getUTCMinutes(),2)+" GMT";return B};ModelData.prototype.sortPeriodNumber=function(B,A){return parseInt(B.period)-parseInt(A.period)};ModelData.prototype.sortInitEpoch=function(B,A){return parseInt(B.value.initialization.epoch)-parseInt(A.value.initialization.epoch)};ModelData.prototype.handleHourMoveChange=function(B){this.calculateHour(B);var A=this.getHour();$(this.sidebarPrefix_+"_hour_value").setText(A)};ModelData.prototype.handleHourMoveComplete=function(D){var A=this.getHourString(D);this.hourEpochSave=null;if(this.mapTitle){this.mapTitle.setTitle(A)}else{var B={title:A,className:this.sidebarPrefix_+"_maptitle"};this.mapTitle=new MapTitleControl(B);var C=new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(140,7));this.map_.addControl(this.mapTitle,C)}GEvent.trigger(this,"settingschanged");this.redrawOnMoveEnd()};ModelData.prototype.updateMaptypeDescription=function(){var F=$(this.sidebarPrefix_+"_title");if(F){var B=this.getModel();var A=this.getMaptype();var E=this.maptypeKeyLookup[A];var D=this.config.MODEL[B].MAP[E];var C=D.description||"no description available";F.setText(C)}};ModelData.prototype.removeMapTitle=function(){if(this.mapTitle){this.map_.removeControl(this.mapTitle);this.mapTitle=null}};ModelData.prototype.requestConfigTimerStop=function(){if(this.requestConfigTimer){$clear(this.requestConfigTimer)}};ModelData.prototype.requestConfigTimerRestart=function(A){this.requestConfigTimerStop();this.requestConfigInterval=A;this.requestConfigTimer=this.requestConfig.periodical(this.requestConfigInterval,this)};