function $$0(a){return($$(a))[0]}if(!window.dbus_firebug_lite_loaded){if(!window.console||!console.firebug){var names=["log","debug","info","warn","error","assert","dir","dirxml","group","groupEnd","time","timeEnd","count","trace","profile","profileEnd"];window.console={};for(var i=0;i<names.length;i++){window.console[names[i]]=function(){}}}}var DBUS={};DBUS.Main=Class.create({_config:null,_MERCATOR_PROYECTION:"EPSG:900913",_DISPLAY_PROYECTION:"EPSG:4326",_map:null,_mapLayer:null,_lineLayers:{},_popup:null,initialize:function(){Event.observe(window,"load",function(a){this._onload()}.bindAsEventListener(this))},initMap:function(a){this._initMap(a)},showLineMap:function(a){this._showLineGeometry(a);this._showLineStops(a);this._removePopup()},hideLineMap:function(a){this._hideLineGeometry(a);this._hideLineStops(a);this._removePopup()},initLineMap:function(){var a=$$(this._config.markupConstants.lineMap.checkBoxSelector);a.each(function(c){var b=c.id.replace(this._config.markupConstants.lineMap.checkBoxIDPrefix,"");c.checked=false;c.observe("click",function(d){if(c.checked){this.showLineMap(b)}else{this.hideLineMap(b)}}.bindAsEventListener(this))}.bind(this))},initModelForm:function(){var a=this._config.markupConstants.modelForm;$$0(a.deliveryDbusSelector).observe("click",function(c){$$0(a.optionalBlockSelector).hide();this._updateModelFormTotal(a.defaultPrice)}.bindAsEventListener(this));$$0(a.deliveryHome).observe("click",function(c){$$0(a.optionalBlockSelector).show();this._calculateModelFormPrice()}.bindAsEventListener(this));$$0(a.countrySelectSelector).observe("change",function(c){this._calculateModelFormPrice()}.bindAsEventListener(this));var b=$$0(a.acceptanceCheckboxSelector);b.observe("change",function(c){var d=$$0(a.acceptanceMessageSelector),e=$$0(a.submitSelector);if(b.getValue()){d.hide();e.enable()}else{d.show();e.disable()}}.bindAsEventListener(this))},_calculateModelFormPrice:function(){var a=this._config.markupConstants.modelForm,c=a.defaultPrice,b=$$0(a.countrySelectSelector).getValue();if(b==a.selectLabelValue){}else{if(b==a.deliveryToGipuzkoa.optionValue){c+=a.deliveryToGipuzkoa.priceIncrement}else{if(b==a.deliveryToSpain.optionValue){c+=a.deliveryToSpain.priceIncrement}else{c+=a.deliveryToEurope.priceIncrement}}}this._updateModelFormTotal(c)},_updateModelFormTotal:function(a){$$0(this._config.markupConstants.modelForm.totalElementSelector).innerHTML=""+a;$$0(this._config.markupConstants.modelForm.totalCostSelector).value=""+a},_onload:function(){this._initAlertHandler()},_initAlertHandler:function(){var c=$$0(this._config.markupConstants.alertDiv.selector),b=$$0(this._config.markupConstants.alertDiv.closeSelector);if(b){b.observe("click",function(a){a.stop();c.hide()})}},_initMap:function(c){var j=new OpenLayers.Bounds(-290161.04,5295335.5,-191077.32,5373290.31),h=new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508.34),f=new OpenLayers.Bounds(-224779.99454734594,5358980.567203188,-218946.8938273783,5362319.909875799);if(this._config.b5map){this._map=new OpenLayersExt.Map(c)}else{var g="map",a="png";var e={controls:[new OpenLayers.Control.Navigation({zoomWheelEnabled:false}),new OpenLayers.Control.PanZoomBar()],maxExtent:h,maxResolution:156543.0339,numZoomLevels:20,units:"m",projection:new OpenLayers.Projection(this._MERCATOR_PROYECTION),displayProjection:new OpenLayers.Projection(this._DISPLAY_PROYECTION)};var b="http://b5m.gipuzkoa.net/api/1.0/es/";this._map=new OpenLayers.Map(c,e);if(this._developmentMode()){this._map.addControl(new OpenLayers.Control.LayerSwitcher())}this._mapLayer=new OpenLayers.Layer.TMS("Gipuzkoa",b+"osgeo/tms/tileset/",{layername:g,type:a,proyection:this._MERCATOR_PROYECTION,displayOutsideMaxExtent:false,isBaseLayer:true});this._map.addLayer(this._mapLayer);if(this._config.googleMaps){var d=new OpenLayers.Layer.Google("Google Maps",{type:G_NORMAL_MAP,sphericalMercator:true,isBaseLayer:false,transitionEffect:"resize"});this._map.addLayer(d)}this._map.zoomToExtent(f)}},_showLineGeometry:function(a){var c=this._layersForLine(a),d=c.geometryLayer,b=this._config.urls.gml.replace(":line_number",a).replace(":format","kml");if(!d){d=new OpenLayers.Layer.GML("Recorrido línea "+a,b,{projection:this._map.displayProjection,format:OpenLayers.Format.KML,formatOptions:{extractStyles:true,extractAttributes:true}});c.geometryLayer=d;d.events.register("loadend",this,function(e){this._map.zoomToExtent.bind(this._map).defer(d.getDataExtent())}.bind(this));this._map.addLayer(d)}else{d.setVisibility(true);this._map.zoomToExtent(d.getDataExtent())}},_hideLineGeometry:function(a){var b=this._layersForLine(a),c=b.geometryLayer;if(c){c.setVisibility(false)}},_showLineStops:function(a){var c=this._layersForLine(a),b=c.markerLayer;if(!b){b=new OpenLayers.Layer.Markers("Paradas línea "+a,{proyection:new OpenLayers.Projection(this._MERCATOR_PROYECTION)});c.markerLayer=b;this._map.addLayer(b);this._loadLineStops(a,b)}else{b.setVisibility(true)}},_hideLineStops:function(a){var c=this._layersForLine(a),b=c.markerLayer;if(b){b.setVisibility(false)}},_loadLineStops:function(a,b){var c=this._config.urls.stopsForLine.replace(":line_number",a).replace(":format","json");new Ajax.Request(c,{method:"get",evalJSON:true,onSuccess:function(d){this._handleLineStops(a,b,d.responseJSON)}.bind(this),onException:function(d,e){console.log(e)}})},_handleLineStops:function(a,b,c){c.each(function(k){k=k.stop;var h=new OpenLayers.LonLat(k.lon,k.lat),m=new OpenLayers.Size(this._config.markupConstants.placeMarker.width,this._config.markupConstants.placeMarker.height),e=new OpenLayers.Pixel(this._config.markupConstants.placeMarker.x,this._config.markupConstants.placeMarker.y),j=new OpenLayers.Icon("",m,e),g=new OpenLayers.Marker(h,j);b.addMarker(g);var d=$(g.icon.imageDiv),l=this._config.htmlTemplates.placeMarker.replace(this._config.markupConstants.placeMarker.stopCodeAnchor,k.code).replace(this._config.markupConstants.placeMarker.stopNameAnchor,k.name_es),f=new Element("div").update(l).firstDescendant();d.innerHTML="";d.insert(f);g.events.register("mousedown",this,function(n){this._clickOnMarkerEventHandler(k)}.bind(this))}.bind(this))},_clickOnMarkerEventHandler:function(c){var b=c.code,a=this._config.urls.arrivalTimesForStop.replace(":stop_code",b).replace(":format","html");this._initPopup(c);new Ajax.Request(a,{method:"get",onSuccess:function(d){this._updatePopup(b,d.responseText)}.bind(this),onFailure:function(d){this._errorPopup()}.bind(this),onException:function(d,e){console.log(e)}})},_initPopup:function(e){var b=this._config.markupConstants,d=new OpenLayers.LonLat(e.lon,e.lat),c={size:new OpenLayers.Size(0,0),offset:new OpenLayers.Pixel(0,0)},a;if(this._config.b5map){a=new OpenLayersExt.Popup.FramedB5Map(b.popup.idPrefix,d,this._config.htmlTemplates.popupInit,c,true,null)}else{a=new OpenLayers.Popup.FramedCloud(b.popup.idPrefix,d,new OpenLayers.Size(b.popup.width,b.popup.height),this._config.htmlTemplates.popupInit,c,true,null)}a.autoSize=true;this._removePopup();this._map.addPopup(a);this._popup=a},_updatePopup:function(a,b){this._updatePopupHTML(b)},_errorPopup:function(){this._updatePopupHTML(this._config.htmlTemplates.popupError)},_removePopup:function(){if(this._popup){this._map.removePopup(this._popup);this._popup.destroy();this._popup=null}},_updatePopupHTML:function(a){if(this._config.b5map){this._popup.updateContentHTML(a);return}this._popup.setContentHTML(a);this._popup.updateSize.bind(this._popup).defer()},_layersForLine:function(a){if(!this._lineLayers[a]){this._lineLayers[a]={geometryLayer:null,markerLayer:null}}return this._lineLayers[a]},_developmentMode:function(){return this._config.environment=="development"}});window.dbus=new DBUS.Main();