OpenLayers.Control.HSLayerSwitcher=OpenLayers.Class(OpenLayers.Control,{oneChangesAll:true,groups:{},baseLayersNode:null,treePanel:null,layerIcon:"maplayer.png",layerInfoIcon:"maplayer-queryable.png",layerLoadingIcon:"indicator.gif",container:null,extGui:false,position:null,initialize:function(options){OpenLayers.Control.prototype.initialize.apply(this,[options]);},clear:function(){return;},deactivate:function(){if(this.active){if(this.handler){this.handler.deactivate();}
this.active=false;this.events.triggerEvent("deactivate");return true;}
return false;},getContainerHeight:function(cont){if(cont.body){return parseInt(cont.body.dom.style.height)-1;}
else{return parseInt(cont.dom.style.height)-1;}},getRenderToId:function(elem){var id=null;switch(typeof(elem)){case"string":id=elem;break;case typeof({}):if(elem!=null){id=elem.body?elem.body.id:elem.id;}
break;default:id=null;}
return id;},destroy:function(){OpenLayers.Event.stopObservingElement(this.div);this.map.events.unregister("addlayer",this,this.onAddLayer);this.map.events.unregister("changelayer",this,this.onChangeLayer);this.map.events.unregister("removelayer",this,this.onRemoveLayer);this.map.events.unregister("changebaselayer",this,this.onChangeBaseLayer);this.map.events.unregister("moveend",this,this.onMoveEnd);for(var i=0;i<this.groups.length;i++){this.events.unregister("loadstart",this.groups[i],this.groupLoadStart);this.events.unregister("loadend",this.groups[i],this.groupLoadEnd);}
OpenLayers.Control.prototype.destroy.apply(this,arguments);},setMap:function(map){OpenLayers.Control.prototype.setMap.apply(this,arguments);this.map.events.on({"changelayer":this.redraw,scope:this});},draw:function(){OpenLayers.Control.prototype.draw.apply(this);this.div=OpenLayers.Util.createDiv(this.id);this.initBaseNodes();this.initGroups();this.initPanel();this.map.events.register("addlayer",this,this.onAddLayer);this.map.events.register("changelayer",this,this.onChangeLayer);this.map.events.register("removelayer",this,this.onRemoveLayer);this.map.events.register("changebaselayer",this,this.onChangeBaseLayer);this.map.events.register("moveend",this,this.onMoveEnd);return this.div;},redraw:function(){},onAddLayer:function(e){this.initGroups();},onChangeLayer:function(e){var allSame=true;var group=null;for(var i in this.groups){for(var j=0;j<this.groups[i].layers.length;j++){if(e.layer==this.groups[i].layers[j]){group=this.groups[i];if(j>0&&(this.groups[i].layers[j].getVisibility()==this.groups[i].layers[j-1].getVisibility())){allSame=true;}
else{allSame=false;}}}}
if((group&&this.oneChangesAll)||(group&&allSame)){group.setVisibility(e.layer.getVisibility());}},onMoveEnd:function(e){for(var i in this.groups){var group=this.groups[i];}},onRemoveLayer:function(e){var group=null;for(var i in this.groups){for(var j=0;j<this.groups[i].layers.length;j++){if(this.groups[i].layers[j]==e.layer){group=this.groups[i];}}}
var layers=[];if(group){for(var i=0;group.layers.length;i++){if(group.layers[i]!=e.layer){layers.push(group.layers[i]);}}
group.layers=layers;if(group.layers.length==0){group.ls.removeGroup(group);}}},onRemoveLayerClicked:function(item){Ext.MessageBox.confirm(OpenLayers.i18n("HSLayerSwitcher:Confirm"),OpenLayers.i18n("HSLayerSwitcher:Really remove?"),function(yesno){if(yesno=="yes"){item.group.ls.removeGroup(item.group);}});},removeGroup:function(group){if(!group){return;}
var layers=[];for(var i=0;i<group.layers.length;i++){layers.push(group.layers[i]);}
group.layers=[];for(var i=0;i<layers.length;i++){layers[i].group=undefined;if(layers[i].isBaseLayer&&layers[i].getVisibility()){layers[i].setVisibility(false);}
else{this.map.removeLayer(layers[i]);}}
group.node.parentNode.removeChild(group.node);this.groups[group.name]=undefined;var groups={};for(var g in this.groups){if(this.groups[g]){groups[g]=this.groups[g];}}
this.groups=groups;},initPanel:function(){this.treePanel=new Ext.tree.TreePanel({layout:'fit',ls:this,enableDD:true,useArrows:true,autoScroll:true,region:'center',rootVisible:false,root:this.groupsRoot,renderTo:(this.container instanceof Ext.Panel?this.container.body:this.getRenderToId(this.container)),bbar:[{text:OpenLayers.i18n("Show legend"),ls:this,handler:this.onShowLegendClicked,cls:'x-btn-text-icon',icon:OpenLayers.Util.getImagesLocation()+"/legend.gif"},{text:OpenLayers.i18n("Reset project"),scope:this,handler:this.onClearLayersClicked,cls:'x-btn-text-icon',icon:OpenLayers.Util.getImagesLocation()+'/empty.gif'}]});this.treePanel.on("enddrag",this.onEndDrag);this.treePanel.on("startdrag",this.onStartDrag);this.treePanel.on("nodedragover",this.onNodeDragOver);if(!this.container){this.container=new Ext.Window({title:OpenLayers.i18n("Layers"),layout:"fit",closable:false,collapsible:true,width:200,height:500,items:[this.treePanel]});this.container.show();}
else{if(typeof(this.container)=="string"){this.container=Ext.get(this.container);}
else{this.container=this.container;}
this.treePanel.setHeight(this.getContainerHeight(this.container));this.container.on("resize",function(panel,adjWidth,adjHeight){this.ls.treePanel.setHeight(adjHeight-1);this.ls.treePanel.setWidth(adjWidth-1);},{ls:this});}},initBaseNodes:function(){this.groupsRoot=new Ext.tree.TreeNode({text:"Groups root",allowChildren:true,leaf:false,expanded:true,ls:this});this.baseLayersNode=new Ext.tree.TreeNode({text:OpenLayers.i18n("baseLayer"),draggable:false,expanded:true,allowDrop:false,ls:this});},initGroups:function(){for(var i=0;i<this.map.layers.length;i++){var layer=this.map.layers[i];if(!layer.displayInLayerSwitcher){continue;}
if(!layer.group){layer.group=layer.name;}
if(!this.groups[layer.group]){this.groups[layer.group]=this.createGroup(layer.group);}
this.groups[layer.group].addLayer(layer);var group=this.groups[layer.group];layer.events.unregister("loadstart",group,this.groupLoadStart);layer.events.unregister("loadend",group,this.groupLoadEnd);layer.events.register("loadstart",group,this.groupLoadStart);layer.events.register("loadend",group,this.groupLoadEnd);}
for(var i in this.groups){if(this.groups[i].node){if(this.groups[i].isBaseGroup&&this.groups[i].node.parentNode==this.groupsRoot){this.groupsRoot.removeChild(this.groups[i].node);this.baseLayersNode.appendChild(this.groups[i].node);}
if(!this.groups[i].isBaseGroup){this.groups[i].node.draggable=true;}
if(this.groups[i].queryable){this.groups[i].setIcon(this.layerInfoIcon);}
this.groups[i].node.checked=this.groups[i].getVisibility();continue;}
if(this.groups[i].isBaseGroup&&!this.baseLayersNode.parentNode){this.groupsRoot.appendChild(this.baseLayersNode);}
var groupNames=this.groups[i].name;for(var j=0;j<groupNames.length;j++){var name=groupNames[j];}
var parentNode=null;if(this.groups[i].name.split("/").length>1){var name=this.groups[i].name.split("/");name=this.groups[i].name.replace("/"+name[name.length-1],"");thisParentNode=this.groups[i].isBaseGroup?this.baseLayersNode:this.groupsRoot;parentNode=this.createTreeNode(name,thisParentNode);}
this.createGroupNode(this.groups[i]);if(!parentNode){parentNode=this.groups[i].isBaseGroup?this.baseLayersNode:this.groupsRoot;}
if(parentNode.childNodes.length){parentNode.insertBefore(this.groups[i].node,parentNode.firstChild);}
else{parentNode.appendChild(this.groups[i].node);}}},createGroup:function(name){var group={};group.name=name;group.layers=[];group.visibility=false;group.icon=OpenLayers.Util.getImagesLocation()+this.layerIcon;group.legendURLs=[];group.metadataURLs=[];group.sources=[];group.removable=false;group.isBaseGroup=false;group.node=null;group.opacity=null;group.setVisibility=this.groupSetVisibility;group.setOpacity=this.groupSetOpacity;group.calculateInRange=this.groupInRange;group.getVisibility=this.groupGetVisibility;group.addLayer=this.groupAddLayer;group.addAttribute=this.groupAddAttribute;group.setIcon=this.groupSetIcon;group.properties=null;group.ls=this;group.loading=0;group.minResolution=null;group.maxResolution=null;group.queryable=false;return group;},createGroupNode:function(group){var text=group.name.split("/");text=text[text.length-1];group.node=new Ext.tree.TreeNode({checked:group.getVisibility(),allowDrag:true,style:{color:(group.calculateInRange()?"black":"#999")},draggable:!group.isBaseGroup,cls:"LayerSwitcherGroupNode",allowChildren:true,expandable:(group.legendURLs.length?true:false),leaf:true,text:text,icon:group.icon,expanded:false,group:group,myNodeType:"group",ls:this});group.node.on("contextmenu",this.onRightClick);group.node.on("click",this.onRightClick);group.node.on("checkchange",this.onCheckboxChange);this.createLegendNodes(group);return;},createTreeNode:function(groupName,parentNode){var text=groupName;var groupName=groupName.split("/");if(groupName.length>1){var withoutLast=text.replace("/"+groupName[groupName.length-1],"");parentNode=this.createTreeNode(withoutLast,parentNode);}
groupName=groupName[groupName.length-1];var onCheckboxChange=function(node){var cascade=function(node,checked){var checked=node.parentNode.getUI().checkbox.checked;node.getUI().checkbox.checked=checked;var group=node.attributes.group;if(group){group.setVisibility(checked);}};for(var i=0;i<node.childNodes.length;i++){node.childNodes[i].cascade(cascade);}}
for(var i=0;i<parentNode.childNodes.length;i++){if(parentNode.childNodes[i].text==groupName){return parentNode.childNodes[i];}}
var node=new Ext.tree.TreeNode({checked:false,allowDrag:false,draggable:false,allowChildren:true,expandable:true,leaf:true,text:groupName,fullGroupName:text,expanded:true,myNodeType:"group",ls:this});node.on("checkchange",onCheckboxChange);parentNode.appendChild(node);return node;},createLegendNodes:function(group){for(var i=0;i<group.legendURLs.length;i++){var nodeExists=false;for(var j=0;j<group.node.childNodes.length;j++){if(group.node.childNodes[j].getUI().node.attributes.icon==group.legendURLs[i]){nodeExists=true}}
if(!nodeExists){var node=new Ext.tree.TreeNode({draggable:false,allowChildren:false,allowDrag:true,allowDrop:true,iconCls:"legend",icon:group.legendURLs[i]});group.node.appendChild(node);}}},groupSetVisibility:function(visibility){for(var i=0;i<this.layers.length;i++){this.layers[i].setVisibility(visibility);if(this.layers[i].isBaseLayer&&visibility){this.ls.map.setBaseLayer(this.layers[i]);}
if(this.layers[i].isBaseGroup&&visibility){for(var g in this.ls.groups){if(this.ls.groups[g].name!=this.layers[i].group){if(this.ls.groups[g].isBaseGroup){this.ls.groups[g].setVisibility(false);}}}}}
this.visibility=visibility;if(this.node){if(this.node.getUI().checkbox){this.node.getUI().checkbox.checked=this.getVisibility();}}},groupGetVisibility:function(){return this.visibility;},groupAddLayer:function(layer){if(layer.isBaseLayer||layer.isBaseGroup){if(!this.isBaseGroup){if(this.node&&this.node.parentNode){if(this.node.parentNode!=this.ls.baseLayersNode){this.ls.baseLayersNode.appendChild(this.node);}}}
this.isBaseGroup=true;}
for(var i=0;i<this.layers.length;i++){if(this.layers[i]==layer){return;}}
this.layers.push(layer);if(layer.legendURL){this.addAttribute("legendURLs",layer.legendURL);}
if(layer.metadataURL){this.addAttribute("metadataURLs",layer.metadataURL);}
if(layer.source){this.addAttribute("sources",layer.source);}
if(layer.removable){this.removable=true;}
if(layer.info_format){this.addAttribute("queryable",true);this.icon=OpenLayers.Util.getImagesLocation()+this.ls.layerInfoIcon;}
if(this.minResolution==null||this.maxResolution==null){this.minResolution=layer.minResolution;this.maxResolution=layer.maxResolution;}
if(layer.minResolution&&(this.minResolution>=layer.minResolution)){this.minResolution=layer.minResolution;}
if(layer.maxResolution&&(this.maxResolution<=layer.maxResolution)){this.maxResolution=layer.maxResolution;}
if(layer.getVisibility()){this.setVisibility(true);}},groupRemoveLayer:function(layer){var layers=[];for(var i=0;i<this.layers;i++){if(layer!=this.layers[i]){layers.push(this.layers[i]);}}
this.layers=layers;},onShowLegendClicked:function(){var show=true;if(this.text==OpenLayers.i18n("Show legend")){this.setText(OpenLayers.i18n("Hide legend"))}
else{show=false;this.setText(OpenLayers.i18n("Show legend"));}
for(var i in this.ls.groups){show?this.ls.groups[i].node.expand():this.ls.groups[i].node.collapse();}},onClearLayersClicked:function(){var layersToRemove=[];for(var i=0;i<this.map.layers.length;i++){var layer=this.map.layers[i];if(layer.displayInLayerSwitcher&&layer.saveWMC!=false&&layer.group){layersToRemove.push(layer);}}
for(var j=0;j<layersToRemove.length;j++){var idx=layersToRemove.length-1-j;var layer=layersToRemove[idx];this.removeGroup(this.groups[layer.group]);layer=null;}},onRightClick:function(node,evt){var group=node.attributes.group;if(!group){return;}
var menu=new Ext.menu.Menu({id:'layerMenu',items:[{text:group.name,canActivate:false,style:"font-weight:bold;"}]});menu.addSeparator();var items=[];if(group.removable){var item=menu.add({text:OpenLayers.i18n("Remove layer")});item.on("click",group.ls.onRemoveLayerClicked);item.group=group;items.push(item);}
if(group.metadataURLs.length){var item=menu.add({text:OpenLayers.i18n("Layer metadata")});item.on("click",function(){for(var i=0;i<group.metadataURLs.length;i++){open(group.metadataURLs[i]);}});items.push(item);}
if(group.sources.length){var item=menu.add({text:OpenLayers.i18n("Download layer")});item.on("click",function(){for(var i=0;i<group.sources.length;i++){open(group.sources[i]);}});items.push(item);}
if(group.properties){var item=menu.add({text:OpenLayers.i18n("Layer Properties")});items.push(item);}
menu.show(evt.target);evt.stopEvent();var onDrag=function(e){var min=this.minValue;var max=this.maxValue;var val=this.getValue();this.group.setOpacity((max-val)/100);};var slider=new Ext.Slider({width:250,minValue:0,group:group,listeners:{'drag':onDrag},maxValue:100});var sliderpanel=new Ext.FormPanel({labelWidth:70,frame:true,width:"100%",defaults:{width:190},renderTo:menu.el.dom,items:[{html:OpenLayers.i18n("Transparency")},slider]});if(group.opacity){slider.setValue(slider.minValue+(1-group.opacity)*100);}
menu.ul.dom.style.width="200px";},groupAddAttribute:function(key,value){for(var i=0;i<this[key].length;i++){if(this[key][i]==value){return;}}
switch(typeof(this[key])){case typeof([]):this[key].push(value);break;default:this[key]=value;break;}},onCheckboxChange:function(node,checked){var group=node.attributes.group;if(group){group.setVisibility(checked);}},onStartDrag:function(panel,node,e){var ls=panel.ls;},onEndDrag:function(panel,node,e){var idx=null;try{var maxIndex=-1;var group=node.nextSibling.attributes.group;var map=group.layers[0].map;for(var i=0;i<group.layers.length;i++){maxIndex=(maxIndex>map.getLayerIndex(group.layers[i])?maxIndex:map.getLayerIndex(group.layers[i]));}
idx=maxIndex;}
catch(e){if(!node.previousSibling){return;}
var minIndex=1000000;var group=node.previousSibling.attributes.group;var map=group.layers[0].map;for(var i=0;i<group.layers.length;i++){minIndex=(minIndex<map.getLayerIndex(group.layers[i])?minIndex:map.getLayerIndex(group.layers[i]));}
group=node.attributes.group;for(var i=0;i<group.layers.length;i++){map.setLayerIndex(group.layers[i],minIndex-1);}
idx=minIndex-1;}
group=node.attributes.group;for(var i=0;i<group.layers.length;i++){map.setLayerIndex(group.layers[i],idx);}},groupLoadStart:function(e){this.setIcon(this.ls.layerLoadingIcon);this.loading+=1;},groupLoadEnd:function(e){this.loading-=1;if(this.loading<=0){this.setIcon(this.ls.layerIcon);this.loading=0;}},groupInRange:function(){if(this.minResolution<=this.ls.map.getResolution()&&this.ls.map.getResolution()<=this.maxResolution){return true;}
else{return false;}},groupSetIcon:function(icon){if(this.node.getUI().getIconEl()){this.node.getUI().getIconEl().src=OpenLayers.Util.getImagesLocation()+icon;}
return true;},groupSetOpacity:function(opacity){for(var i=0;i<this.layers.length;i++){this.layers[i].setOpacity(opacity);}
this.opacity=opacity;return true;},onNodeDragOver:function(de){},CLASS_NAME:"OpenLayers.Control.HSLayerSwitcher"});OpenLayers.Lang["cs-CZ"]['Show legend']="Zobrazit legendy";OpenLayers.Lang["cs-CZ"]['Layers']="Vrstvy";OpenLayers.Lang["cs-CZ"]['baseLayer']="Základní vrstvy";OpenLayers.Lang["cs-CZ"]['Hide legend']="Skrýt legendy";OpenLayers.Lang["cs-CZ"]['Remove layer']="Odstranit vrstvu";OpenLayers.Lang["cs-CZ"]['Layer metadata']="Metadata";OpenLayers.Lang["cs-CZ"]['Download layer']="Ztáhnout data";OpenLayers.Lang["cs-CZ"]['Layer Properties']="Vlastnosti vrstvy";OpenLayers.Lang["cs-CZ"]['Transparency']="Průhlednost";OpenLayers.Lang["cs-CZ"]['HSLayerSwitcher:Confirm']="Potvrzení";OpenLayers.Lang["cs-CZ"]['HSLayerSwitcher:Really remove?']="Opravdu smazat?";OpenLayers.Lang["cs-CZ"]['Reset project']="Vyčistit";OpenLayers.Lang["en"]['Show legend']="Show legend";OpenLayers.Lang["en"]['Hide legend']="Hide legend";OpenLayers.Lang["en"]['Layers']="Layers";OpenLayers.Lang["en"]['baseLayer']="Base layers";OpenLayers.Lang["en"]['Remove layer']="Remove layer";OpenLayers.Lang["en"]['Layer metadata']="Layer metadata";OpenLayers.Lang["en"]['Download layer']="Download data";OpenLayers.Lang["en"]['Layer Properties']="Layer properties";OpenLayers.Lang["en"]['Transparency']="Transparency";OpenLayers.Lang["en"]['HSLayerSwitcher:Confirm']="Confirm";OpenLayers.Lang["en"]['HSLayerSwitcher:Really remove?']="Really remove?";OpenLayers.Control.HSLayerSwitcher.HSLayer=OpenLayers.Class(OpenLayers.Control.HSLayerSwitcher,{legendNodes:[],_objectToBeUnregistered:null,destroy:function(){OpenLayers.Event.stopObservingElement(this.div);this.map.events.unregister("addlayer",this,this.onAddLayer);this.map.events.unregister("changelayer",this,this.onChangeLayer);this.map.events.unregister("removelayer",this,this.onRemoveLayer);this.map.events.unregister("changebaselayer",this,this.onChangeBaseLayer);this.map.events.unregister("moveend",this,this.onMoveEnd);for(var i=0;i<this.groups.length;i++){this.events.unregister("loadstart",this.groups[i],this.groupLoadStart);this.events.unregister("loadend",this.groups[i],this.groupLoadEnd);}
OpenLayers.Control.prototype.destroy.apply(this,arguments);},createGroupNode:function(group){var HSLayer=false;for(var i=0;i<group.layers.length;i++){var layer=group.layers[i];if(layer.CLASS_NAME.search("OpenLayers.Layer.HSMapServer")>-1){this._objectToBeUnregistered={ls:this,group:group,layer:layer};layer.events.register("layerloaded",this._objectToBeUnregistered,this.hsLayerCreateNodes);HSLayer=true;}}
group.node=new Ext.tree.TreeNode({checked:group.getVisibility(),allowDrag:true,allowDrop:false,draggable:!group.isBaseGroup,allowChildren:true,expandable:(group.legendURLs.length||HSLayer?true:false),leaf:true,text:group.name,icon:group.icon,style:{color:(group.calculateInRange()?"black":"#999")},expanded:HSLayer,cls:"LayerSwitcherGroupNode",group:group,myNodeType:"group",ls:this});group.node.on("contextmenu",this.onRightClick);group.node.on("click",this.onRightClick);group.node.on("checkchange",this.onCheckboxChange);this.createLegendNodes(group);return;},hsLayerCreateNodes:function(e){this.ls.createHSGroupNodes(this.group,this.layer);this.layer.events.unregister("layerloaded",this.ls._objectToBeUnregistered,this.ls.hsLayerCreateNodes);},createHSGroupNodes:function(group,layer){for(var i=0;i<layer.groups.length;i++){var hsGroup=layer.groups[i];var name=(hsGroup.title?hsGroup.title:hsGroup.name);hsGroup.node=new Ext.tree.TreeNode({checked:hsGroup.getVisibility(),allowChildren:true,allowDrag:false,allowDrop:false,expandable:true,leaf:true,text:name,icon:group.icon,expanded:true,group:group,hsGroup:hsGroup,myNodeType:"group",ls:this});hsGroup.node.on("checkchange",this.onGroupCheckboxChange);group.node.appendChild(hsGroup.node);this.createHSLayerNodes(group,hsGroup,layer);}
layer.baseGroup.node=group.node;this.createHSLayerNodes(group,layer.baseGroup);},createHSLayerNodes:function(group,hsGroup,olLayer){for(var i=0;i<hsGroup.layers.length;i++){var layer=hsGroup.layers[i];var name=(layer.title?layer.title:layer.name);layer.node=new Ext.tree.TreeNode({checked:layer.getVisibility(),style:{color:(group.calculateInRange()?"black":"#999")},allowChildren:true,allowDrag:false,allowDrop:false,expanded:false,leaf:true,text:name,expandable:layer.legendURL,group:group,hsGroup:hsGroup,hsLayer:layer,icon:OpenLayers.Util.getImagesLocation()+(layer.queryable?this.layerInfoIcon:this.layerIcon),myNodeType:"group",ls:this});hsGroup.node.appendChild(layer.node);if(layer.legendURL){this.createHSLayerLegendNode(hsGroup,layer);}
layer.node.on("checkchange",this.onLayerCheckboxChange);layer.node.on("contextmenu",this.onLayerRightClick);}},createHSLayerLegendNode:function(hsGroup,layer){var node=new Ext.tree.TreeNode({draggable:false,allowChildren:false,iconCls:"legend",icon:layer.legendURL});layer.node.appendChild(node);this.legendNodes.push(node);},onMoveEnd:function(e){for(var i in this.groups){var group=this.groups[i];for(var j=0;j<group.node.childNodes.length;j++){var node=group.node.childNodes[j];if(node.attributes.hsGroup||node.attributes.hsLayer){for(var k=0;k<node.attributes.hsGroup.layers.length;k++){var layer=node.attributes.hsGroup.layers[k];}}}}},onLayerCheckboxChange:function(node,checked){if(checked){for(var i=0;i<node.attributes.hsLayer.switchers.length;i++){var name=node.attributes.hsLayer.switchers[i];if(!name){continue;}
var layer=node.attributes.hsLayer.group.layer.getLayer(name);var group=node.attributes.hsLayer.group.layer.getGroup(name);if(layer){layer.node.getUI().checkbox.checked=false;}
else if(group){group.node.getUI().checkbox.checked=false;for(var j=0;j<group.layers.length;j++){if(group.layers[j]!=node.attributes.hsLayer){group.layers[j].node.getUI().checkbox.checked=false;}}}}}
node.attributes.hsLayer.setVisibility(checked);},onGroupCheckboxChange:function(node,checked){for(var i=0;i<node.childNodes.length;i++){node.childNodes[i].getUI().checkbox.checked=checked;}
node.attributes.hsGroup.setVisibility(checked);},onShowLegendClicked:function(){var show=true;if(this.text==OpenLayers.i18n("Show legend")){this.setText(OpenLayers.i18n("Hide legend"))}
else{show=false;this.setText(OpenLayers.i18n("Show legend"));}
for(var i in this.ls.groups){var hsLayer=false;for(var j=0;j<this.ls.groups[i].layers.length;j++){if(this.ls.groups[i].layers[j].CLASS_NAME.search("OpenLayers.Layer.HSMapServer")>-1){hsLayer=true;}}
if(hsLayer==false){show?this.ls.groups[i].node.expand():this.ls.groups[i].node.collapse();}}
for(var i=0;i<this.ls.legendNodes.length;i++){var parNode=this.ls.legendNodes[i].parentNode;show?parNode.expand():parNode.collapse();}},onLayerRightClick:function(node,evt){var layer=node.attributes.hsLayer;var menu=new Ext.menu.Menu({id:'layerMenu',items:[{text:layer.title,canActivate:false,style:"font-weight:bold;"}]});menu.addSeparator();var items=[];if(layer.metadataURL){var item=menu.add({text:OpenLayers.i18n("Layer metadata")});item.on("click",function(){open(layer.metadataURL);});items.push(item);}
if(layer.source){var item=menu.add({text:OpenLayers.i18n("Download layer")});item.on("click",function(){open(layer.source);});items.push(item);}
if(layer.properties){var item=menu.add({text:OpenLayers.i18n("Layer Properties")});items.push(item);}
if(items.length>0){menu.show(evt.target);}
evt.stopEvent();},onNodeDragOver:function(de){if(!!de.target.attributes.hsGroup==true&&!!de.data.node.attributes.hsGroup!=true){de.cancel=true;}},CLASS_NAME:"OpenLayers.Control.HSLayerSwitcher.HSLayer"});
