﻿    var expanded = false;
    
    function viewMap() {
        var div = document.getElementById("gMapDiv");
        div.style.border = "1px solid black";
        var fx = new Fx.Styles(div, {duration:200, wait:false});
        
        if (!expanded) {
          document.getElementById("map").style.display = 'block';
            fx.start({'height':300}).chain(function() {
                scrollWindow();
                this.start.delay(200, this, {'width': 498}).addEvent('onComplete', createMap.delay(1000));
            }); 
           
        } else {
            document.getElementById("map").style.display = 'none';
            fx.start({'height':0}).chain(function() {
                this.start.delay(0, this, {'width': 498});
            }); 
        }
        expanded = !expanded;
    }
    
    function scrollWindow() {
        window.scrollTo(0,900);
    }
    
    
    
    function createMap() {
                
               var map = new GMap2(document.getElementById("map"));
                    map.enableScrollWheelZoom();
                    map.enableContinuousZoom();
                    
                    //--add zoom controls
                    map.addControl(new GLargeMapControl());
                    
                    //--center map to latitude longditude of office
                    var latLng = new GLatLng("53.476681","-2.497329",  12)
                    map.setCenter(latLng,12);


                    //--create new placemark for the office
                    var address = "Bents Garden and Home Center <br/> Warrington Road<br/> Glazebury<br/> WA3 5NT<br/>";
                    var marker = createInfoMarker(latLng, address);
                    map.addOverlay(marker);

                    //--show the address bubble
                    marker.openInfoWindowHtml(address);
                    
                    document.getElementById("map").style.border='1px solid black';
                    document.getElementById("map").style.height='300px';
                    
                    
    }


    function findObjWithClientId(Id) {
        var ctrls = document.forms[0].elements;   
        for(var count = 0; count < ctrls.length ; count ++) {
            
            var index = ctrls[count].id.indexOf(Id);
        
            if(index != -1) {
            
                //if((ctrls[count].id.length - index) == Id.length) {
                    return ctrls[count];
                //}
            }
        }
        return null;
    }


    function getDirections() {
    
        var ctrl = findObjWithClientId("tbPostcode");
       
    
        var action = "http://maps.google.co.uk/maps?";
        action += "hl=en";
//        action += "&daddr=Leigh End, Warrington, WA3 (Bents Garden Centre ltd)";
action += "&daddr=WA3 5NT";
        action += "&saddr=" + ctrl.value;
        
        window.open(action,"Directions");
    }
    
    
        function createInfoMarker(point, address) {

            var marker = new GMarker(point);
            GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(address);} );

            return marker;
        }
    
  


 