$(document).ready(function(){
    $('#map').click(function(){ 
        url = $(this).attr('rel');

        jQuery.facebox(function($){
            jQuery.get(url, function(data) { 
                jQuery.facebox(data);
                
                //getting the coordinates of the store
                coordinates = jQuery('#coors').text();
                coordinates = JSON.parse(coordinates);
                
                //getting the info related with the store
                address = jQuery('#marker_text').html();

                //Creating the map
                canvas = document.getElementById('canvas');
                var map = new GMap2(canvas);
                map.setCenter(new GLatLng(coordinates.lat,coordinates.lng), 16);
                map.setUIToDefault();
                
                //creating the point
                point = new GLatLng(coordinates.lat,coordinates.lng);
                marker = createMarker(point,address);
                map.addOverlay(marker); 
            });
        });
    });
});


/**
 * Create a google maps marker
 */
createMarker = function(point,html){
    var marker = new GMarker(point);
    
    GEvent.addListener(marker,"click",function(){
        marker.openInfoWindowHtml(html,{maxWidth:250});
    });
    
    return marker;
}