var oVenuesMaps=null;$(document).ready(function(){$("div.carousel").carousel({autoSlide:false});$('#mapa a').bind('click',initializeMap);$.datepick.setDefaults($.datepick.regional['es']);$('#date_pick').bind('click',function(){$('#date_picker').toggle();$('#date_picker').datepick({rangeSelect:true,monthsToShow:2,dateFormat:'dd-mm-YY',onSelect:function(aDates)
{sStartDate=aDates[0].getDate()+'-'+(aDates[0].getMonth()+1)+'-'+aDates[0].getFullYear();sEndDate=aDates[1].getDate()+'-'+(aDates[1].getMonth()+1)+'-'+aDates[1].getFullYear();if(sStartDate!=sEndDate)
{console.log('date selected: '+sStartDate+' '+sEndDate);url=FW.base_url+'from/'+sStartDate+'/to/'+sEndDate+'/';window.location.href=url;}}});});});function initializeMap()
{$('#mapa').animate({'height':'400px'},function(){oVenuesMaps=new venuesMap();});return false;}
var venuesMap=function()
{this.oLatlng=new google.maps.LatLng(41.388143,2.1698);this.oOptions={zoom:10,center:this.oLatlng,mapTypeId:google.maps.MapTypeId.ROADMAP,};this.oMap=new google.maps.Map(document.getElementById('mapa'),this.oOptions);this.oData=null;this.aPendingMarkers=[];this.oMarkers={};this.oWindows={};this.runAction();}
this.venuesMap.prototype.runAction=function()
{url=FW.action_url+'ctrl/maps/load/'+parseInt(Math.random()*100000000);var self=this;$.getJSON(url,function(data)
{self.updateMap(data);});}
this.venuesMap.prototype.updateMap=function(oData)
{var self=this;this.oData=oData;for(sKey in oData)
{this.aPendingMarkers.push(sKey);}
setTimeout(function()
{return self.addMarker()},200);}
this.venuesMap.prototype.addMarker=function()
{var self=this;var sKey=this.aPendingMarkers.pop();var oItem=this.oData[sKey];var oLatlng=new google.maps.LatLng(oItem.location.latitude,oItem.location.longitude);var oIcon=new google.maps.MarkerImage(oItem.icon,new google.maps.Size(16,16),new google.maps.Point(0,0),new google.maps.Point(0,0));this.oMarkers[sKey]=new google.maps.Marker({position:oLatlng,map:this.oMap,title:oItem.venue,icon:oIcon,animation:google.maps.Animation.DROP});this.oWindows[sKey]=new google.maps.InfoWindow({content:oItem.info,maxWidth:400});google.maps.event.addListener(this.oMarkers[sKey],'click',(function(sKey,self){return function()
{var sCurrentKey;for(sCurrentKey in self.oWindows)
{self.oWindows[sCurrentKey].close();}
self.oWindows[sKey].open(self.oMap,self.oMarkers[sKey]);}}(sKey,self)));if(this.aPendingMarkers.length>0)
{setTimeout(function()
{return self.addMarker()},200);}}
