<?xml version="1.0" encoding="UTF-8" ?>
<Module>
    <ModulePrefs title="State Example" height="450">
        <Require feature="wave" />
    </ModulePrefs>
    <Content type="html">
        <![CDATA[ 
<html>
        <head>
            <script src="http://www.google.com/jsapi?key=ABQIAAAAnY6iVf-0s2DlcUBrbJaDjBQcvMhaH8yE-xViFhdYMM21CTq_ThSUqMi8lEi8vGyRSKZ7DzzhU2qXJA" type="text/javascript"></script>

            <script>
                google.load("maps", "2");
                google.load("jquery", "1.3");
            </script>
	    <script type="text/javascript">
	    var map;
	    var geocoder;
	    var marker;
	    $(function(){
	    map = new GMap2(document.getElementById("map_canvas"));
	    map.setUIToDefault();
	    map.disableScrollWheelZoom();
	    geocoder = new GClientGeocoder();
	    map.getInfoWindow();

	    marker = new GMarker(new GLatLng(0,0));
	    map.addOverlay(marker);
	    map.setCenter(marker.getLatLng(),13);

	    $('input[name=submit]').bind('click', function(){
	    address = $('input[name=address]').val();
	    wave.getState().submitDelta({
	    'address':address
	    });
	    return false;
	    });
	    });

	    function reload(){
	    address = wave.getState().get('address');
	    geocoder.getLatLng(address, function(latlng){
	    if(!latlng){
	    alert("Cannot determine the address");
	    }else{
	    marker.setLatLng(latlng);
	    map.setCenter(latlng, 13);
	    console.log(latlng);
	    }
	    })
	    console.log(address);
	    }
/*
	    function waveGadget(){
	    this.callback = "";
	    this.setStateCallback = function (callback){
	    this.callback = callback;
	    };
	    this.isInWaveContainer=function(){
	    return true;
	    };
	    this.getState=function(){
	    return this;
	    };
	    this.submitDelta=function(data){
	    //this.callback(data);
	    reload(data);
	    }
	    }

	    function initWave(){
	    if(wave && wave.isInWaveContainer()){
	    wave.setStateCallback(reload);
	    }
	    }
	    initWave();
	    var wave = new waveGadget();*/
	    function init() {
	          if (wave && wave.isInWaveContainer()) {
		          wave.setStateCallback(reload);
		     }
		}
	       gadgets.util.registerOnLoadHandler(init);
	    </script>
            
        </head>
        <body>
        <div id="map_canvas" style="height: 350px; width:500px"></div>
        <input type="text" name="address" />
        <input type="submit" name="submit" value="submit" />
</body>
</html>
        ]]>
    </Content>
</Module>      
