/* Bdis - Copyright (c) 2010 Vincent Calame - Exemole
* Logiciel libre donné sous triple licence :
* 1) selon les termes de la CeCILL V2 
* 2) selon les termes de l’EUPL V.1.1
* 3) selon les termes de la GNU GPLv3
* Voir le fichier licences.txt
*
* Version 1.2
*/
var Bdis = {
    singleFile: true
};

/* Bdis.js */
(function(){var g=(typeof Bdis=="object"&&Bdis.singleFile);window.Bdis={_scriptName:(!g)?"lib/Bdis.js":"Bdis.js",_getScriptLocation:function(){var p="";var r=new RegExp("(^|(.*?\\/))("+Bdis._scriptName+")(\\?|$)");var m=document.getElementsByTagName("script");for(var o=0,h=m.length;o<h;o++){var q=m[o].getAttribute("src");if(q){var n=q.match(r);if(n){p=n[1];break}}}return p}};if(!g){var j=new Array("Bdis/Entite.js","Bdis/Entites.js","Bdis/EntiteFilter.js","Bdis/Marqueur.js","Bdis/OpenLayers.js","Bdis/OpenLayersPopup.js","Bdis/FeatureControl.js","Bdis/Options.js","Bdis/Utils.js");var b=navigator.userAgent;var d=(b.match("MSIE")||b.match("Safari"));if(d){var a=new Array(j.length)}var k=Bdis._getScriptLocation()+"lib/";for(var c=0,f=j.length;c<f;c++){if(d){a[c]="<script src='"+k+j[c]+"'><\/script>"}else{var l=document.createElement("script");l.src=k+j[c];var e=document.getElementsByTagName("head").length?document.getElementsByTagName("head")[0]:document.body;e.appendChild(l)}}if(d){document.write(a.join(""))}}})();Bdis.VERSION_NUMBER="Bdis 1.2 -- Revision: 33";

/* Bdis/Entite.js */
Bdis.Entite=function(d,c,a,b){this.id=d;this.titre=c;this.lat=a;this.lon=b;this.attributes=new Object()};Bdis.Entite.prototype.addAttribute=function(a,b){if(this.attributes.hasOwnProperty(a)){var c=this.attributes[a];c[c.length]=b}else{var c=new Array();c[0]=b;this.attributes[a]=c}};Bdis.Entite.prototype.getAttribute=function(a){if(this.attributes.hasOwnProperty(a)){return this.attributes[a]}else{return null}};Bdis.Entite.prototype.containsValue=function(b,c){if(this.attributes.hasOwnProperty(b)){var d=this.attributes[b];for(var a=0;a<d.length;a++){if(d[a]==c){return true}}return false}else{return false}};

/* Bdis/Entites.js */
Bdis.Entites=function(){this.entiteArray=new Array();this.entiteMap=new Object()};Bdis.Entites.prototype.getEntiteCount=function(){return this.entiteArray.length};Bdis.Entites.prototype.getEntiteByIndex=function(a){return this.entiteArray[a]};Bdis.Entites.prototype.getEntiteById=function(b){var a="e_"+b;if(this.entiteMap.hasOwnProperty(a)){return this.entiteMap[a]}else{return null}};Bdis.Entites.prototype.addEntite=function(a){if(!a||(!(a instanceof Bdis.Entite))){return false}if(!a.id){return false}var b="e_"+a.id;if(this.entiteMap.hasOwnProperty(b)){return false}this.entiteMap[b]=a;this.entiteArray[this.entiteArray.length]=a};Bdis.Entites.prototype.containsEntite=function(b){var a="e_"+b;if(this.entiteMap.hasOwnProperty(a)){return true}else{return false}};Bdis.Entites.prototype.loadFromAjax=function(b,c){if(b.entitesSourceType=="scrutari"){this.loadFromAjaxScrutari(b.scrutariJSonUrl,b.motcleFiltre,b.langUi,c)}else{var a=b.functions.getEntitesURL(b);if((a)&&(a.length)&&(a.length>0)){this.loadFromAjaxXml(a,b.entiteFilter,c)}}};Bdis.Entites.prototype.loadFromAjaxXml=function(a,b,d){var c=this;$.ajax({url:a,dataType:"xml",success:function(e,f){Bdis.Entites.loadFromXml(c,e,b,d,f)},error:function(e,g,f){d(c,false,e,g,f)}})};Bdis.Entites.prototype.loadFromAjaxScrutari=function(b,e,c,d){var a=this;$.ajax({url:b,dataType:"jsonp",data:{type:"fiche",mode:"motcle",motcle:e,langui:c,prop:"titre, geo"},success:function(f,g){Bdis.Entites.loadFromScrutari(a,f,d,g)},error:function(f,h,g){d(a,false,f,h,g)}})};Bdis.Entites.loadFromXml=function(l,t,h,g,d){var a=$("entite",t);for(var s=0;s<a.length;s++){var e=a[s];var o=e.getAttribute("id");if((!o)||(l.containsEntite(o))){continue}var c=$("titre",e).text();var p=$("point",e);var u=p.length;var b;if(u==1){var m=p.attr("lat");var f=p.attr("lon");b=new Bdis.Entite(o,c,m,f)}else{continue}var n=$("attr",e);for(var r=0;r<n.length;r++){var v=n[r];var w=v.getAttribute("key");if((w)&&(w.length>0)){valList=$("val",v);for(var q=0;q<valList.length;q++){b.addAttribute(w,$(valList[q]).text())}}}if(h.accept(b)){l.addEntite(b)}}if(g){g(l,true,d)}};Bdis.Entites.loadFromScrutari=function(d,e,k,c){var j=e.ficheData;if(j.count>0){var l=j.infoMap;for(var f in l){var i=l[f];if(i.lat){var b=i.id;var h=i.titre;var g=i.lat;var a=i.lon;d.addEntite(new Bdis.Entite(b,h,g,a))}}}if(k){k(d,true,c)}};

/* Bdis/EntiteFilter.js */
Bdis.EntiteFilter=function(){};Bdis.EntiteFilter.prototype.accept=function(a){return true};Bdis.EntiteFilter.newAttributeInstance=function(b,c){var a=new Bdis.EntiteFilter();a.key=b;a.value=c;a.accept=function(d){return d.containsValue(this.key,this.value)};return a};

/* Bdis/Marqueur.js */
Bdis.Marqueur=function(b,c,a){this.url=b;this.width=c;this.height=a;this.centerX=(c/2);this.centerY=(a-1)};Bdis.Marqueur.prototype.setCenter=function(b,a){this.centerX=b;this.centerY=a};

/* Bdis/OpenLayers.js */
Bdis.OpenLayers=function(c){this.options=c;this.calqueArray=new Array();this.calqueMap=new Object();this.defaultAnchor={size:new OpenLayers.Size(5,5),offset:new OpenLayers.Pixel(-2,-2)};OpenLayers.Lang.setCode(c.langUi);OpenLayers.Popup.COLOR=c.openLayersPopupColor;var b=c.openLayersMap;var a=new Array();a[0]=new OpenLayers.Control.Navigation({zoomWheelEnabled:b.zoomWheelEnabled});a[1]=new OpenLayers.Control.Attribution();if(b.withPanZoomBar){a[a.length]=new OpenLayers.Control.PanZoomBar()}this.map=new OpenLayers.Map("BLOC_CARTE",{numZoomLevels:b.numZoomLevels,maxResolution:b.maxResolution,units:b.units,controls:a,projection:new OpenLayers.Projection("EPSG:900913"),displayProjection:new OpenLayers.Projection("EPSG:4326")})};Bdis.OpenLayers.prototype.endInit=function(){var c=this.options;var e=this.map;var d=new Array();for(var a=0;a<this.calqueArray.length;a++){d.push(this.calqueArray[a].layer)}var f=new Bdis.FeatureControl(d,{scope:this,onMouseOver:Bdis.OpenLayers.mouseOverFeature,onMouseOut:Bdis.OpenLayers.mouseOutFeature,onClick:Bdis.OpenLayers.clickFeature});e.addControl(f);f.activate();var b=new OpenLayers.LonLat(c.longitudeDepart,c.latitudeDepart).transform(e.displayProjection,e.projection);if(c.openLayersMap.withLayerSwitcher){e.addControl(new OpenLayers.Control.LayerSwitcher())}e.setCenter(b,c.zoomDepart)};Bdis.OpenLayers.prototype.addBasicLayer=function(a,b){if(a=="Osmarender"){this.map.addLayer(new OpenLayers.Layer.OSM.Osmarender(b))}else{if(a=="Mapnik"){this.map.addLayer(new OpenLayers.Layer.OSM.Mapnik(b))}}};Bdis.OpenLayers.prototype.addMarkersLayer=function(b,f){if(this.calqueMap.hasOwnProperty(b)){return}var d=this.options.functions._getStyleMap(b);var e=this.options.functions._getStrategyArray(b);var a=new OpenLayers.Layer.Vector(f,{strategies:e,styleMap:d});var c=new Bdis.OpenLayers.Calque(b,a);this.calqueMap[b]=c;this.calqueArray.push(c);this.map.addLayer(a)};Bdis.OpenLayers.prototype.getCalque=function(a){if(this.calqueMap.hasOwnProperty(a)){return this.calqueMap[a]}else{return null}};Bdis.OpenLayers.prototype.addMarker=function(b,d){var g=this.options;var e=this.getCalque(d);if(e==null){return}var f=this.getLonLat(b);var a=new OpenLayers.Geometry.Point(f.lon,f.lat);var c=new OpenLayers.Feature.Vector(a,null,null);c.data.icon=this.getMarkerIcon(b,d);c.data.popupContentHTML=g.functions.getPopupContentHTML(b,d,g);c.popupClass=g.openLayersPopupClass;c.data.bdis=new Object();c.data.bdis.entite=b;c.data.bdis.layerKey=d;c.data.bdis.options=g;e.addFeature(c)};Bdis.OpenLayers.prototype.flushEntites=function(a){var b=this.getCalque(a);if(b==null){return}b.flushFeatures()};Bdis.OpenLayers.prototype.getMarkerIcon=function(a,e){var f=this.options.functions.getMarqueur(a,e,this.options);var b=f.url;var c=new OpenLayers.Size(f.width,f.height);var d=new OpenLayers.Pixel(-(f.centerX),-(f.centerY));return new OpenLayers.Icon(f.url,c,d)};Bdis.OpenLayers.prototype.clearLayer=function(a){var b=this.getCalque(a);if(b==null){return}b.clear()};Bdis.OpenLayers.prototype.zoomOnLayerContent=function(c){var e=this.getCalque(c);if(e==null){return}var a=e.layer;var b=a.getDataExtent();var d=a.getZoomForExtent(b);if(d>5){d=d-1}if(d>11){d=11}this.map.setCenter(b.getCenterLonLat(),d)};Bdis.OpenLayers.prototype.setLayerVisibility=function(b,a){var c=this.getCalque(b);if(c==null){return}c.layer.setVisibility(a)};Bdis.OpenLayers.prototype.getLonLat=function(a){return new OpenLayers.LonLat(a.lon,a.lat).transform(this.map.displayProjection,this.map.projection)};Bdis.OpenLayers.prototype.setMapCenter=function(a,b){if(!b){b=this.options.zoomCentrage}var c=this.getLonLat(a);if(b==-1){this.map.setCenter(c)}else{this.map.setCenter(c,b)}};Bdis.OpenLayers.selectEntite=function(c){var a=this.entite;var b=this.layerKey;var d=this.options;d.functions.selectEntite(a,b,d);OpenLayers.Event.stop(c)};Bdis.OpenLayers.Calque=function(b,a){this.layerKey=b;this.layer=a;this.featuresCacheArray=new Array()};Bdis.OpenLayers.Calque.prototype.clear=function(){this.layer.destroyFeatures()};Bdis.OpenLayers.Calque.prototype.addFeature=function(a){this.featuresCacheArray.push(a)};Bdis.OpenLayers.Calque.prototype.flushFeatures=function(a){this.layer.addFeatures(this.featuresCacheArray);this.featuresCacheArray=new Array()};Bdis.OpenLayers.mouseOverFeature=function(a){if(a.cluster){if(a.attributes.count==1){this.showEntitePopup(a.cluster[0])}else{this.showClusterPopup(a)}}else{this.showEntitePopup(a)}};Bdis.OpenLayers.prototype.showEntitePopup=function(c){var a=c.geometry.getCentroid();var b=new c.popupClass(c.id+"_popup",new OpenLayers.LonLat(a.x,a.y),null,c.data.popupContentHTML,this.defaultAnchor,false,null);b.autoSize=true;c.popup=b;this.map.addPopup(b)};Bdis.OpenLayers.prototype.showClusterPopup=function(e){var a=e.geometry.getCentroid();var d=e.cluster[0];var c=this.options.functions._getClusterPopupContentHTML(e,d.data.bdis.layerKey,this.options);var b=new d.popupClass(e.id+"_popup",new OpenLayers.LonLat(a.x,a.y),null,c,this.defaultAnchor,false,null);b.autoSize=true;e.popup=b;this.map.addPopup(b)};Bdis.OpenLayers.mouseOutFeature=function(a){if(a.cluster){if(a.attributes.count==1){a=a.cluster[0]}}this.map.removePopup(a.popup);a.popup.destroy();a.popup=null};Bdis.OpenLayers.clickFeature=function(a){if(a.cluster){if(a.attributes.count==1){this.clickEntite(a.cluster[0])}else{this.clickCluster(a)}}else{this.clickEntite(a)}};Bdis.OpenLayers.prototype.clickEntite=function(b){var a=b.data.bdis.entite;var c=b.data.bdis.layerKey;this.options.functions.selectEntite(a,c,this.options)};Bdis.OpenLayers.prototype.clickCluster=function(b){var d=new Array();for(var a=0;a<b.cluster.length;a++){d.push(b.cluster[a].data.bdis.entite)}var c=b.cluster[0].data.bdis.layerKey;this.options.functions._listEntites(d,c,this.options)};

/* Bdis/OpenLayersPopup.js */
Bdis.OpenLayersPopup=OpenLayers.Class(OpenLayers.Popup.Anchored,{initialize:function(g,c,f,b,a,e,d){OpenLayers.Popup.Anchored.prototype.initialize.apply(this,arguments)},updateRelativePosition:function(){this.setOrientation()},setSize:function(a){OpenLayers.Popup.Anchored.prototype.setSize.apply(this,arguments);this.setOrientation()},setOrientation:function(){var d=this.relativePosition;var e=this.contentDiv.childNodes;for(var b=0;b<e.length;b++){var c=e[b];if(c.className){var a=c.className;if(a.length>0){classArray=a.split(" ");if(classArray.length>0){c.className=a+" "+classArray[classArray.length-1]+"_"+d;break}}}}},CLASS_NAME:"OpenLayers.Popup.Bdis"});

/* Bdis/FeatureControl.js */
Bdis.FeatureControl=OpenLayers.Class(OpenLayers.Control,{onMouseOver:function(){},onMouseOut:function(){},onClick:function(){},scope:null,geometryTypes:null,layer:null,layers:null,callbacks:null,selectStyle:null,renderIntent:"select",handlers:null,initialize:function(c,a){OpenLayers.Control.prototype.initialize.apply(this,[a]);if(this.scope===null){this.scope=this}this.initLayer(c);var b={click:this.clickFeature,over:this.overFeature,out:this.outFeature};this.callbacks=OpenLayers.Util.extend(b,this.callbacks);this.handlers={feature:new OpenLayers.Handler.Feature(this,this.layer,this.callbacks,{geometryTypes:this.geometryTypes})}},initLayer:function(a){if(a instanceof Array){this.layers=a;this.layer=new OpenLayers.Layer.Vector.RootContainer(this.id+"_container",{layers:a})}else{this.layer=a}},destroy:function(){if(this.active&&this.layers){this.map.removeLayer(this.layer)}OpenLayers.Control.prototype.destroy.apply(this,arguments);if(this.layers){this.layer.destroy()}},activate:function(){if(!this.active){if(this.layers){this.map.addLayer(this.layer)}this.handlers.feature.activate()}return OpenLayers.Control.prototype.activate.apply(this,arguments)},deactivate:function(){if(this.active){this.handlers.feature.deactivate();if(this.layers){this.map.removeLayer(this.layer)}}return OpenLayers.Control.prototype.deactivate.apply(this,arguments)},clickFeature:function(a){this.onClick.call(this.scope,a)},overFeature:function(a){this.highlight(a)},outFeature:function(a){if(a._lastHighlighter==this.id){if(a._prevHighlighter&&a._prevHighlighter!=this.id){delete a._lastHighlighter;var b=this.map.getControl(a._prevHighlighter);if(b){b.highlight(a)}}else{this.unhighlight(a)}}},highlight:function(b){var a=b.layer;b._prevHighlighter=b._lastHighlighter;b._lastHighlighter=this.id;var c=this.selectStyle||this.renderIntent;a.drawFeature(b,c);this.onMouseOver.call(this.scope,b)},unhighlight:function(b){var a=b.layer;b._lastHighlighter=b._prevHighlighter;delete b._prevHighlighter;a.drawFeature(b,b.style||b.layer.style||"default");this.onMouseOut.call(this.scope,b)},setMap:function(a){this.handlers.feature.setMap(a);OpenLayers.Control.prototype.setMap.apply(this,arguments)},setLayer:function(b){var a=this.active;this.deactivate();if(this.layers){this.layer.destroy();this.layers=null}this.initLayer(b);this.handlers.feature.layer=this.layer;if(a){this.activate()}},CLASS_NAME:"OpenLayers.Control.BdisFeature"});

/* Bdis/Options.js */
Bdis.Options=function(){this.mapDivId="BLOC_CARTE";this.langUi="fr";this.functions=new Bdis.Options.Functions();this.openLayersMap=new Bdis.Options.OpenLayersMap();this.openLayersPopupClass=Bdis.OpenLayersPopup;this.entitesSourceType="xml";this.scrutariJSonUrl="";this.motcleFiltre="";this.zoomDepart=5;this.latitudeDepart=46.62;this.longitudeDepart=1.4;this.zoomCentrage=11;this.openLayersPopupColor="white";this.parameters=new Object();this.l10n=new Object();this.entiteFilter=new Bdis.EntiteFilter()};Bdis.Options.OpenLayersMap=function(){this.numZoomLevels=19;this.maxResolution=156543.0399;this.units="m";this.zoomWheelEnabled=false;this.withPanZoomBar=true;this.withPanZoomBar=true;this.withLayerSwitcher=true};Bdis.Options.Functions=function(){this.getEntitesURL=function(a){return""};this.getPopupContentHTML=function(a,c,b){return'<div class="Bdis_Bulle">'+a.titre+"</div>"};this.selectEntite=function(a,c,b){};this.getMarqueur=function(a,c,b){return new Bdis.Marqueur("http://bdis.exemole.fr/marqueur.png",22,33)};this._getClusterPopupContentHTML=function(a,c,b){return'<div class="Bdis_Bulle">'+a.attributes.count+"</div>"};this._getStyleMap=function(b){var a=new OpenLayers.Style({pointRadius:"${radius}",fillColor:"#ffcc66",fillOpacity:0.8,strokeColor:"#ff0000",strokeWidth:2,strokeOpacity:0.3},{context:{radius:function(d){return Math.min(d.attributes.count,7)+4}}});var c=new OpenLayers.StyleMap({"default":a,select:{fillColor:"#8aeeef",strokeColor:"#32a8a9"}});return c};this._getStrategyArray=function(a){return[]}};Bdis.Options.prototype.hasMotcleFiltre=function(){return(this.motcleFiltre.length>0)&&(this.scrutariJSonUrl.length>0)};Bdis.Options.prototype.setParameter=function(a,b){this.parameters[a]=b};Bdis.Options.prototype.getParameter=function(a){if(this.parameters.hasOwnProperty(a)){return this.parameters[a]}else{return null}};Bdis.Options.prototype.setL10n=function(b,a){this.l10n[b]=a};Bdis.Options.prototype.getL10n=function(a){if(this.l10n.hasOwnProperty(a)){return this.l10n[a]}else{return null}};

/* Bdis/Utils.js */
Bdis.Utils=function(){};Bdis.Utils.log=function(a){if(console){console.debug(a)}};

