function LayerGroup(C,B,A){this.datasetInfo=B;this.enabled=true;this.layers=[];this.u=C;this.interactive=((A===null)||(A===undefined))?true:A;if(this.interactive){}else{}this.loggerName="layergroup";Log.enable(this.loggerName);this.viewDirty=true;this.modelDirty=true;this.domNode=new Element("div",{"class":"_generated"});this.loadedframework=false;this.loadFramework();this.penalty=undefined;this.deferred=[];this.deferred.push(function(){this.renderHTML()}.bind(this));this.layerContainer=undefined;this.x=null;this.y=null}LayerGroup.prototype.isComplete=function(){for(var A=0;A<this.layers.length;A++){if(!this.layers[A].isComplete()){return false}}return true};LayerGroup.prototype.isRaster=function(){var B=this.datasetInfo.shape_types;for(var A=0;A<B.length;A++){if(B[A]=="raster"){return true}}return false};LayerGroup.prototype.toString=function(){var A={defererred:this.defererred,layerContainer:this.layerContainer.toString(),datasetInfo:this.datasetInfo,enabled:this.enabled,layers:this.layers};return Json.toString(A)};LayerGroup.prototype.enable=function(){this.enabled=true};LayerGroup.prototype.disable=function(){this.enabled=false};LayerGroup.prototype.getEnabledMask=function(){return this.enabled};LayerGroup.prototype.rendertiles=function(){for(var A=0;A<this.layers.length;A++){this.layers[A].rendertiles()}};LayerGroup.prototype.addHiddenLayer=function(){var A=function(){var B=new Layer(this,this.datasetInfo);B.setVirtual(true);this.add(B)}.bind(this);if(!this.datasetInfo){this.defererred.push(A);this.deferred.push(mapManager.checkModels)}else{A();mapManager.checkModels()}};LayerGroup.prototype.addVisibleLayer=function(A){var B=function(D){var C=function(){var E=new Layer(D,D.datasetInfo);if(A!==undefined){D.add(E,A)}else{D.add(E)}};return C};if(!this.datasetInfo){this.deferred.push(B(this))}else{B(this)()}};LayerGroup.prototype.addLiteral=function(B,C){console.log("adding literal:",B);var A=function(){var D=new Layer(this,this.datasetInfo,B);if(C){D.setVirtual(C)}this.add(D)}.bind(this);if(!this.datasetInfo){this.deferred.push(A)}else{A()}};LayerGroup.prototype.addChartLiteral=function(B){var A=(function(){var C=new Layer(this,this.datasetInfo);C.setmodel(B);this.add(C)}).bind(this);if(!this.datasetInfo){this.deferred.push(A)}else{A()}};LayerGroup.prototype.handleDeferred=function(){if(this.datasetInfo){console.log("handling",this.deferred.length,"deferred items");if(typeof (this.layerContainer)!=="undefined"){while(this.deferred.length>0){var A=this.deferred.shift();console.log("g:",A);A()}}}};LayerGroup.prototype.add=function(C,A){if(this.isRaster()&&!C.isVirtual()){return }if(this.isRaster()){console.assert(C.isVirtual(),"can only add virtual layers to raster layer groups");console.assert((this.layers.length==0),"can only add one layer to a raster layer group")}if(A===undefined){A=this.layers.length}if(!C.isVirtual()){if($defined($(this.layerContainer))){if(!($(this.layerContainer).getChildren().length==this.layers.length)){}}}if(!(this.layers.length>=A)){Log.logError("array index out of bounds",this.loggerName)}if(!C.isVirtual()&&$defined($(this.layerContainer))){if(A==this.layers.length){this.layerContainer.appendChild(C.domNode)}else{var B=this.layers[A];this.layerContainer.insertBefore(C.domNode,B.domNode)}}this.layers.splice(A,0,C);if(typeof (mapManager)!=="undefined"){mapManager.checkModels()}return };LayerGroup.prototype.remove=function(B){var A=this.indexOf(B);if(A<0){return }this.layers.splice(A,1);this.layerContainer.removeChild(B.domNode)};LayerGroup.prototype.indexOf=function(B){for(var A=0;A<this.layers.length;A++){if(this.layers[A]===B){return A}}return -1};LayerGroup.prototype.renderHTML=function(){if(!$defined(this.layerContainer)){return }console.log("rendering html for layer group.");if(!this.viewDirty){console.log("view is not dirty");return }else{console.log("view was dirty")}var D,B;var C,A;if(this.layers.length>0){C=this.layers[0];A=C.domNode.getElement("span[id=_plusbutton]");if(A){A.style.visibility="visible"}}if(this.layers.length==1){C=this.layers[0];A=C.domNode.getElement("span[id=_minusbutton]");if(A){A.style.visibility="hidden"}}else{for(D=0;D<this.layers.length;D++){C=this.layers[D];A=C.domNode.getElement("span[id=_minusbutton]");if(A){A.style.visibility="visible"}}}for(D=1;D<this.layers.length;D++){C=this.layers[D];A=C.domNode.getElement("span[id=_plusbutton]");if(A){A.style.visibility="hidden"}}for(D=0;D<this.layers.length;D++){C=this.layers[D];A=C.domNode.getElement("input[id=_order]");if(A){A.value=""+D}}if(!this.penalty){A=this.domNode.getElement("span[id=_penaltycontainer]");if(A){A.style.display="none"}}else{A=this.domNode.getElement("span[id=_penaltycontainer]");if(A){A.style.display="block"}A=this.domNode.getElement("span[id=_penaltytext]");if(A){A.innerHTML=this.penalty+" Items Omitted"}}var F,E;if($chk(this.x)){F=this.domNode.getElement("select[id=_x_attribute_select]");E=F.options;for(B=0;B<E.length;B++){if(E[B].value==this.x){E[B].selected=true;break}}}if($chk(this.y)){F=this.domNode.getElement("select[id=_y_attribute_select]");E=F.options;for(B=0;B<E.length;B++){if(E[B].value==this.y){E[B].selected=true;break}}}this.viewDirty=false};LayerGroup.prototype.loadFramework=function(){var A="/cbi/maptool/loaddatasetUI";var B=new Ajax(A,{data:Object.toQueryString({uuid:this.u,type:pageManager.getPageType()}),method:"get",evalScripts:true,update:this.domNode,onComplete:function(){this.loadDatasetInfo()}.bind(this)});B.request()};LayerGroup.prototype.setModel=function(B){this.x=B.x;this.y=B.y;var A=$merge(B,{});A["radius"]=B.radius_style;A["color"]=B.color_style;delete A.radius_style;delete A.color_style;this.addChartLiteral(A);this.viewDirty=true;if(this.loadedframework){this.renderHTML()}};LayerGroup.prototype.getModel=function(){if(this.layers.length!=1){console.trace();return }return{dataset:this.u,x_type:this.datasetInfo["attributes"][this.x][1],y_type:this.datasetInfo["attributes"][this.y][1],x:this.x,y:this.y,radius_style:this.layers[0].model.radius,color_style:this.layers[0].model.color}};LayerGroup.prototype.filterByType=function(A,J){var I,B;if(A=="x"){I=this.domNode.getElement("select[_x_attribute_select]");B=this.x}else{if(A=="y"){I=this.domNode.getElement("select[_y_attribute_select]");B=this.y}else{return }}if(I){var H=this.getsortedattributes();I.setHTML("");var D;for(var F=0;F<H.length;F++){var G=H[F];var K=G[0];var E=G[1][0];var C=G[1][1];if(!J||(J.length==0)){D=new Element("option",{value:K});D.setText(E);I.add(D,null);if(B==K){D.selected=true}}else{if(J.contains(C)){D=new Element("option",{value:K});D.setText(E);I.add(D,null);if(B==K){D.selected=true}}}}I.fireEvent("change")}};LayerGroup.prototype.configureDOM=function(){var A;A=this.domNode.getElement("div[id=_content]");if(A){this.layerContainer=A}else{this.layerContainer=null}if(!$defined(this.layerContainer)){this.disable();return }console.log("layer container is:",this.layerContainer);A=this.domNode.getElement("span[id=_render_on]");if(A){A.innerHTML="SHOW ON "+pageManager.getPageType().toUpperCase()+":"}console.log("render on is:",A);console.log("registering handlers");this.registerhandlers();console.log("filtering by type");this.filterByType("x",pageManager.x_filter);this.filterByType("y",pageManager.y_filter);console.log("handling deferred");this.handleDeferred();A=this.domNode.getElement("div[id=i1]");console.assert(A,"must have parent element");A.setStyle("display","block");this.loaded=true;console.log("configured dom")};LayerGroup.prototype.setCheckbox=function(A){var B=this.domNode.getElement("span[id=_render_on]");if(B){if(A){B.addClass("checked");this.enable()}else{B.removeClass("checked");this.disable()}}};LayerGroup.prototype.getsortedattributes=function(){var A=this.datasetInfo["attributes"];var C=[];for(var B in A){if(A.hasOwnProperty(B)){if($type(B)!="string"){continue}C.push([A[B][0],[B,A[B]]])}}C.sort();C=C.map(function(D){return D[1]});return C};LayerGroup.prototype.registerhandlers=function(){var A;A=this.domNode.getElement("select[id=_x_attribute_select]");if(A){A.addEvent("change",(function(D){var C=this.options[this.selectedIndex].value;if(C=="-- Choose --"){return }D.x=C;var B=D.datasetInfo["attributes"][C][1];D.x_type=B}).bind(A,this))}console.log("e:",A);A=this.domNode.getElement("select[_y_attribute_select]");if(A){A.addEvent("change",(function(D){var C=this.options[this.selectedIndex].value;if(C=="-- Choose --"){return }D.y=C;var B=D.datasetInfo["attributes"][C][1];D.y_type=B}).bind(A,this))}console.log("e:",A);A=this.domNode.getElement("div[id=move_ds_dn]");console.assert(A,"you need to a button to move datasets down");A.addEvent("click",(function(){pageManager.moveDown(this)}).bind(this));console.log("e:",A);A=this.domNode.getElement("div[id=move_ds_up]");console.assert(A,"you need to a button to move datasets up");A.addEvent("click",(function(){pageManager.moveUp(this)}).bind(this));console.log("e:",A);A=this.domNode.getElement("span[id=_render_on]");A.addEvent("click",(function(B){this.toggleClass("checked");if(this.hasClass("checked")){B.enable();B.rendertiles()}else{B.disable();B.rendertiles()}}).bind(A,this));console.log("e:",A)};LayerGroup.prototype.loadDatasetInfo=function(){var A="/cbi/maptool/loaddatasetOptions";var B=new Ajax(A,{data:Object.toQueryString({uuid:this.u}),method:"get",onComplete:function(C){console.log("got response from load dataset options");var D=Json.evaluate(C)[0];this.datasetInfo=D;if(!this.loaded){console.log("now loaded, calling configure dom");this.configureDOM()}console.log("handling",this.deferred.length,"deferred items");this.handleDeferred();if(this.interactive){if(this.isRaster()){this.addHiddenLayer()}}}.bind(this)});B.request()}