//jquery for moadal &
//google maps api js

var closeModal = function(hash)
{
    var $modalWindow = $(hash.w);
    
    $modalWindow.fadeOut('2000', function()
    {
        hash.o.remove();        
    });
}

var openModal = function(hash)
{
    var $modalWindow = $(hash.w);
    
    $modalWindow.fadeIn("def"); 
}

var map;    
function init() {     
    //uk
    var latlng = new google.maps.LatLng(54.977614, -3.924609 );

    var myOptions = {
        zoom: 5,            
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
                          
      map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);      
 }    
 
function placeMarker(latLng, title, infoContent) { 
    var image = "../images/ccw-lawyers-logo-map.gif";
                                                
    var marker = new google.maps.Marker({
        position: latLng,
        title: title,
        icon: image,
        map: map            
    });
    
    var infowindow = new google.maps.InfoWindow ({
        content: infoContent
    });
    
    google.maps.event.addListener(marker, 'click', function() {
        map.zoom = 14; 
        infowindow.open(map, marker);             
    });                                             
}

function centerMap(latLng) {
    map.setCenter(latLng);
    map.zoom = 14;
}

function toggleSize(event) {
    var normalWidth = 255;
    var normalHeight = 250;
    var largeHeight = 400;
    
    var $link = $(event.target);
    var $mapContainer = $("#map_container");
    var $mapCanvas = $("#map_canvas");
    
    if ($mapContainer.width() > normalWidth) {        
        // decrease map size
        $link.text("Larger Map");
        $mapContainer.width(normalWidth);
        $mapContainer.height(normalHeight);
        $mapCanvas.height(normalHeight - 20);        
    }
    else
    {
        //increase map size        
        $link.text("Smaller Map");
        $mapContainer.width("100%");
        $mapContainer.height(largeHeight);
        $mapCanvas.height(largeHeight - 20);                 
    } 
    
    google.maps.event.trigger(map, 'resize')           
}   
                               
$(function() {
    //set-up the map        
    init();
    
    //hook up the click event to the mapSizeToggle link                
    $("#mapSizeToggle").click(function(event) {
        toggleSize(event);
        event.preventDefault();
    });
    
    //initialise the dialog div for the jqModal popup
    $("#modalWindow").jqm({
        modal: false,
        onHide: closeModal,
        onShow: openModal
    }); 
    
    //hook up the click to display the jqModal popup     
    $("#showDialog").click(function(event) {
        $('#modalWindow').jqmShow();
        event.preventDefault();
    });
});