//<![CDATA[
var map = null;
$(window).load(function() {
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.addControl(new GScaleControl());
        var address = $("#address").html();
        var addressAry = address.split(" ");
        var addressForMap = addressAry[0];

        var lat = "";
        if(document.getElementById('lat')){
            var lat = document.getElementById('lat').value;
        }
        var lon = "";
        if(document.getElementById('lon')){
            var lon = document.getElementById('lon').value;
        }

        showAddress(map, addressForMap, lat, lon);
    }
});
$(window).unload(function() {
    GUnload();
});

var showAddress = function(map, address, lat, lon) {
    geocoder = new GClientGeocoder();
    if (geocoder) {
        geocoder.getLatLng(
        address,
        function(point) {
            if (point) {
                if (lat != "" && lon != "") {
                    point = new GLatLng(lon, lat);                    
                }
                map.setCenter(point, 17);
                
                var icon = new GIcon();
                icon.image = "./img/icon5.png";
                //icon.shadow = "./img/icon3_2_2.png";
                
                icon.iconSize = new GSize(30, 28);
                //icon.shadowSize = new GSize(38, 26);
                
                icon.iconAnchor = new GPoint(15, 28);
                
                icon.infoWindowAnchor = new GPoint(15, 10);
                
                var marker = new GMarker(point, icon);
                map.addOverlay(marker);
                var name = $("#name").html();
                marker.openInfoWindowHtml(name);               
        	} else if (lat != "" && lon != ""){
        		point = new GLatLng(lon, lat);
        		map.setCenter(point, 17);
        		var icon = new GIcon();
        		icon.image = "./img/icon5.png";
        		icon.iconSize = new GSize(30, 28);
        		icon.iconAnchor = new GPoint(15, 28);
        		icon.infoWindowAnchor = new GPoint(15, 10);
        		var marker = new GMarker(point, icon);
        		map.addOverlay(marker);
        		var name = $("#name").html();
        		marker.openInfoWindowHtml(name);
       	 
        	} else {
        	
            	map.setCenter(new GLatLng(35.737856, 139.654534), 17);
            	point = '';				
                 
            }
        });
    }
}




//]]>
