/* 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.1
*/
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/Options.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.1 -- $Revision: 1 $";

/* 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.calqueMap=new Object();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 b=this.options;var c=this.map;var a=new OpenLayers.LonLat(b.longitudeDepart,b.latitudeDepart).transform(c.displayProjection,c.projection);if(b.openLayersMap.withLayerSwitcher){c.addControl(new OpenLayers.Control.LayerSwitcher())}c.setCenter(a,b.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,d){if(this.calqueMap.hasOwnProperty(b)){return}var a=new OpenLayers.Layer.Markers(d);var c=new Bdis.OpenLayers.Calque(b,a);this.calqueMap[b]=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(a,d){var f=this.options;var e=this.getCalque(d);if(e==null){return}var c=new OpenLayers.Feature(e.layer,this.getLonLat(a));c.data.icon=this.getMarkerIcon(a,d);c.data.popupContentHTML=f.functions.getPopupContentHTML(a,d,f);c.popupClass=f.openLayersPopupClass;var b=c.createMarker();e.addMarker(b);var h=new Object();h.feature=c;h.options=f;h.map=this.map;b.events.register("mouseover",h,Bdis.OpenLayers.showPopup);b.events.register("mouseout",h,Bdis.OpenLayers.hidePopup);var g=new Object();g.entite=a;g.layerKey=d;g.options=f;b.events.register("click",g,Bdis.OpenLayers.selectEntite)};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);this.map.setCenter(c,b)};Bdis.OpenLayers.showPopup=function(b){var a=this.feature.popup;var c=true;if(a==null){var a=this.feature.createPopup(false);a.autoSize=true}else{if(a.visible()){a.hide();c=false;this.map.removePopup(a)}else{a.show()}}if(c){this.map.addPopup(a,true)}OpenLayers.Event.stop(b)};Bdis.OpenLayers.hidePopup=function(b){var a=this.feature.popup;if(a!=null){if(a.visible()){a.hide();visible=false;this.map.removePopup(a)}}OpenLayers.Event.stop(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.markerArray=new Array()};Bdis.OpenLayers.Calque.prototype.clear=function(){for(var a=0;a<this.markerArray.length;a++){this.layer.removeMarker(this.markerArray[a])}};Bdis.OpenLayers.Calque.prototype.addMarker=function(a){this.layer.addMarker(a);this.markerArray[this.markerArray.length]=a};

/* 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/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)}};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}};

