var infowindow=null;function Map_InfoBox(div,opts){google.maps.OverlayView.call(this);var self=this;infowindow=this;this.offsetVertical=-38;this.offsetHorizontal=-19;this.map=opts.map;this.div=div;this.marker=null;this.setMap(this.map);this.update_layout=function(){var img=document.getElementById('map_infobox_logo');setTimeout(function(){if(img.style.display!='none'&&img.width>0&&img.width<130){$('#map_infobox').addClass('two-column');var width=$('#map_infobox_body').width()-img.width-15;$('#map_infobox_desc').width(width);}else{$('#map_infobox').removeClass('two-column');$('#map_infobox_desc').css('width','auto');}},1);};$('#map_infobox_logo').load(this.update_layout);this.createElement=function(){var panes=this.getPanes();if(this.div.parent().get()!==panes.floatPane){this.div.appendTo(panes.floatPane);}};this.get_close_func=function(){return function(){self.hide();};};this.hide=function(){this.marker=null;$(this.div).hide().appendTo('#map_infobox_holder');};this.show=function(marker){this.marker=marker;this.draw();};this.setTitle=function(title){$('#map_infobox_title').text(title);};this.setSpriteRow=function(row){$('#map_infobox_icon').css('background-position',x='-129px -'+(row*41)+'px');};this.setLogo=function(logo_url){if(logo_url){$('#map_infobox_logo').attr('src',logo_url).show();}else{$('#map_infobox_logo').hide();}
this.update_layout();};this.setContent=function(content){$('#map_infobox_desc').html(content);};this.setLink=function(link,title,color){$('#map_infobox_link').attr('href',link).css('background-color',color);$('#map_infobox_link_title').text('Découvrez '+title);};this.draw=function(){this.createElement();if(!this.div||!this.marker){return;}
var pixPosition=this.getProjection().fromLatLngToDivPixel(this.marker.getPosition());if(!pixPosition){return;}
$(this.div).css({left:pixPosition.x+this.offsetHorizontal,top:pixPosition.y+this.offsetVertical,display:'block'});window.setTimeout(function(){self.panMap();},50);};this.panMap=function(){if(!this.map||!this.marker||!this.div){return;}
var map=this.map;var bounds=map.getBounds();if(!bounds){return;}
var position=this.marker.getPosition();var iwWidth=$('#map_infobox_wrapper').width();var iwHeight=$('#map_infobox_wrapper').height();var iwOffsetX=this.offsetHorizontal;var iwOffsetY=this.offsetVertical;var padX=80;var padY=80;var mapDiv=map.getDiv();var mapWidth=mapDiv.offsetWidth;var mapHeight=mapDiv.offsetHeight;var boundsSpan=bounds.toSpan();var longSpan=boundsSpan.lng();var latSpan=boundsSpan.lat();var degPixelX=longSpan/mapWidth;var degPixelY=latSpan/mapHeight;var mapWestLng=bounds.getSouthWest().lng();var mapEastLng=bounds.getNorthEast().lng();var mapNorthLat=bounds.getNorthEast().lat();var mapSouthLat=bounds.getSouthWest().lat();var iwWestLng=position.lng()+(iwOffsetX-padX)*degPixelX;var iwEastLng=position.lng()+(iwOffsetX+iwWidth+padX)*degPixelX;var iwNorthLat=position.lat()-(iwOffsetY-padY)*degPixelY;var iwSouthLat=position.lat()-(iwOffsetY+iwHeight+padY)*degPixelY;var shiftLng=(iwWestLng<mapWestLng?mapWestLng-iwWestLng:0)+
(iwEastLng>mapEastLng?mapEastLng-iwEastLng:0);var shiftLat=(iwNorthLat>mapNorthLat?mapNorthLat-iwNorthLat:0)+
(iwSouthLat<mapSouthLat?mapSouthLat-iwSouthLat:0);var center=map.getCenter();var centerX=center.lng()-shiftLng;var centerY=center.lat()-shiftLat;var shift_pos=new google.maps.LatLng(centerY,centerX);map.panTo(shift_pos);};google.maps.event.addDomListener(document.getElementById('map_infobox_close'),'click',this.get_close_func());google.maps.event.addListener(this.map,'click',this.get_close_func());}
Map_InfoBox.prototype=new google.maps.OverlayView();
;function Map_Location(map,data){var self=this;this.data=$.extend({},data);this.map=map;this.location_type=map.location_types[data.location_type];this.position=null;if(this.data.longitude&&this.data.latitude){this.position=new google.maps.LatLng(this.data.latitude,this.data.longitude);}
this.marker=new google.maps.Marker($.extend({},this.location_type.options,{map:this.map.map,optimized:true,position:this.position,visible:false}));this.show=function(delay){window.setTimeout(function(){if(self.position){self.place();}else{self.find();}},delay);};this.hide=function(){this.marker.setVisible(false);};this.blur=function(){this.marker.setIcon(this.location_type.trans_icon);this.marker.setShadow(this.location_type.options.trans_shadow);}
this.unblur=function(){this.marker.setIcon(this.location_type.icon);this.marker.setShadow(this.location_type.options.shadow);}
this.show_tooltip=function(){self.map.infobox.setSpriteRow(self.location_type.data.sprite_row);self.map.infobox.setTitle(self.location_type.data.name);self.map.infobox.setLogo(self.data.logo);self.map.infobox.setContent(self.data.description);self.map.infobox.setLink(self.data.website,self.data.tagname,self.location_type.data.color);self.map.infobox.show(self.marker);};google.maps.event.addListener(this.marker,"click",this.show_tooltip);this.place=function(position){if(position!==undefined){this.position=position;}
if(this.position){this.marker.setPosition(this.position);this.marker.setVisible(true);}else{this.marker.setVisible(false);}};this.get_full_address=function(){var parts=[];if(this.data.address){parts.push(this.data.address);}
if(this.data.city){parts.push(this.data.city);}
if(this.data.province){parts.push(this.data.province);}
if(this.data.postal_code){parts.push(this.data.postal_code);}
return parts.join(', ');};this.save_position=function(){$.post('?fct=save_partner_position',{id:self.data.id,lat:this.position.lat(),lng:this.position.lng()});};this.find=function(){var address=self.get_full_address();this.geocoder.geocode({address:address,region:'CA',language:'fr'},function(result,status){if(result&&result.length>0){var geocoding=result[0];self.place(geocoding.geometry.location);self.save_position();}else{self.place(false);}});};}
Map_Location.prototype.geocoder=new google.maps.Geocoder();
;function Map_LocationType(data){var self=this;this.data=$.extend({},data);this.sprite_top=this.data.sprite_row*35;this.icon=new google.maps.MarkerImage(this.icon_url,new google.maps.Size(30,35),new google.maps.Point(99,this.sprite_top));this.trans_icon=new google.maps.MarkerImage(this.icon_url,new google.maps.Size(30,35),new google.maps.Point(187,this.sprite_top));this.options=$.extend({},this.icons[this.data.shape],{icon:this.icon});this.filter=$('#map_sector_'+this.data.short);this.filter_func=function(){if(map){var p=self.filter;if(p.hasClass('on')){$('#map_explorer li').removeClass('on');map.filter_type(null);}else{$('#map_explorer li').removeClass('on');p.addClass('on');map.filter_type(self);}}
return false;};$('a',this.filter).click(this.filter_func);this.preload_img=function(){var img=new Image(32,35);img.src=this.icon_url;};this.preload_img();this.types.push(this);this.get_anchor=function(){var img=this.options.icon;var anchor=img.anchor;if(anchor===undefined){anchor=new google.maps.Point(img.size.width/2,img.size.height);}
return anchor;};}
Map_LocationType.prototype.icon_url='images/map/sprite.png';Map_LocationType.prototype.icons={};Map_LocationType.prototype.types=[];Map_LocationType.prototype.get_random=function(){return this.types[Math.floor(this.types.length*Math.random())];};Map_LocationType.prototype.icons.square={shadow:new google.maps.MarkerImage('images/map/shadow.png',new google.maps.Size(60,28),new google.maps.Point(0,0),new google.maps.Point(20,28)),trans_shadow:new google.maps.MarkerImage('images/map/shadow.png',new google.maps.Size(60,28),new google.maps.Point(60,0),new google.maps.Point(20,28)),shape:{type:'rect',coords:[0,0,32,32]}};Map_LocationType.prototype.icons.round={shadow:new google.maps.MarkerImage('images/map/shadow.png',new google.maps.Size(34,24),new google.maps.Point(0,28),new google.maps.Point(6,24)),trans_shadow:new google.maps.MarkerImage('images/map/shadow.png',new google.maps.Size(34,24),new google.maps.Point(34,28),new google.maps.Point(6,24)),shape:{type:'circle',coords:[16,16,16]}};
;function Map(){var self=this;this.map=null;this.infobox=null;this.mapCanvas=null;this.markers=[];this.bounds=new google.maps.LatLngBounds(new google.maps.LatLng(45.482,-73.616),new google.maps.LatLng(45.514,-73.553));this.mapOptions={minZoom:10,maxZoom:15,zoom:11,center:new google.maps.LatLng(45.497,-73.595),mapTypeControl:false,panControl:false,scaleControl:false,zoomControl:false,rotateControl:false,streetViewControl:false,backgroundColor:'#f4f4f4',zoomControlOptions:{position:google.maps.ControlPosition.LEFT_BOTTOM,style:google.maps.ZoomControlStyle.SMALL},panControlOptions:{position:google.maps.ControlPosition.LEFT_BOTTOM}};this.mapType=new google.maps.StyledMapType([{featureType:"all",elementType:"all",stylers:[{visibility:"off"}]},{featureType:"landscape",elementType:"geometry",stylers:[{lightness:37},{saturation:-100}]},{featureType:"road.arterial",elementType:"labels",stylers:[{visibility:"on"},{gamma:10},{hue:"#001111"}]},{featureType:"road.arterial",elementType:"geometry",stylers:[{visibility:"on"},{lightness:70},{saturation:-100}]},{featureType:"water",elementType:"geometry",stylers:[{visibility:"on"},{lightness:48},{saturation:-66},{hue:"#00ffff"}]}]);this.location_types={};this.locations=[];this.init=function(){this.mapCanvas=document.getElementById('map_canvas');this.map=new google.maps.Map(this.mapCanvas,this.mapOptions);this.map.mapTypes.set('styledMapType',this.mapType);this.map.setMapTypeId('styledMapType');this.infobox=new Map_InfoBox($('#map_infobox'),{map:this.map});$('#map_zoom_in').live('click',this.zoomIn);$('#map_zoom_out').live('click',this.zoomOut);$('#map_sector_all a').click(function(){$('#map_sectors li').removeClass('on');self.filter_type(null);return false;});};this.zoomIn=function(){self.map.setZoom(self.map.getZoom()+1);return false;};this.zoomOut=function(){self.map.setZoom(self.map.getZoom()-1);return false;};this.fitBounds=function(){this.map.fitBounds(this.bounds);};this.add_location_type=function(id,data){this.location_types[id]=new Map_LocationType(data);};this.add_location=function(data){var loc=new Map_Location(this,data);this.locations.push(loc);if(loc.data.must_fit&&loc.position){this.bounds.extend(loc.position);}};this.show=function(){this.fitBounds();var duration=800;var count=this.locations.length;var i;for(i=0;i<count;i++){var delay=i*duration/count;this.locations[i].show(delay);}};this.filter_type=function(show){if(infowindow){infowindow.hide();}
var managed=$(this.locations).not(function(){return this.location_type.data.shape==='square'});if(show){managed.not(function(){return this.location_type===show;}).each(function(){this.hide();});managed.not(function(){return this.location_type!==show;}).each(function(){this.show();});$(this.locations).not(managed).each(function(){this.blur();});}else{managed.each(function(){this.show();});$(this.locations).not(managed).each(function(){this.unblur();});}};}
$(function(){if((navigator.userAgent.match(/iPhone/i))||(navigator.userAgent.match(/iPod/i))||(navigator.userAgent.match(/iPad/i))){$("body").removeClass("no-touch");$("#map_explorer ul li").click(function(){$(this).children("a").click();})}})
;var map=new Map();var map_el_show_hide_delay=400;function show_map_info(){$('#intro_opened').show();$('.intro_closed').fadeOut(map_el_show_hide_delay);return false;}
function hide_map_info(){$('#intro_opened').hide();$('.intro_closed').fadeIn(map_el_show_hide_delay);return false;}
$(function(){if(document.cookie.match('visited_map=1')){hide_map_info();}else{document.cookie='visited_map=1; expires=Thu, 1 Jan 2015 00:00:0 UTC; path=/';show_map_info();}
$('#map_infobox_link').live('click',function(){window.open(this.href);return false;})
map.show();$('#intro_opened .close, .show_map').click(hide_map_info);$('#show_info').click(show_map_info);google.maps.event.addListener(map.map,'click',hide_map_info);google.maps.event.addListener(map.map,'dragstart',hide_map_info);$('.video_start').click(function(){$('#intro_opened').hide();$('.intro_closed').fadeOut(map_el_show_hide_delay);$('<div id="video_popup"><iframe width="650" scrolling="no" height="403" src="video.plain" frameborder="0" style="overflow:visible"/></div>').dialog({draggable:false,resizable:false,width:660,height:423,modal:true,title:'',closeText:'',close:function(){$(this).dialog('destroy');$('.intro_closed').fadeIn(map_el_show_hide_delay);}});return false;});$('.ui-widget-overlay').live('click',function(){$('.ui-dialog-content').dialog('close');});});
