$(function(){
    $('.slTbody tr:odd').addClass('even');
    $('.slTbody tr:even').addClass('odd');
});

//GMAP

//<![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 = getAddress();
        var lat = getLat();
        var lon = getLon();
        useShowAddress(map, address, lat, lon);
        map.setCenter(new GLatLng(35.737856, 139.654534), 16);
    }
});
$(window).unload(function() {
    GUnload();
});

var getAddress = function() {
    addressAry = new Array;
    for (i=1; i<11; i++) {
        if(document.getElementById('address_'+i)){
            var temp = document.getElementById('address_'+i).value;
            var tempAry = temp.split(" ");
            if(temp != '') addressAry.push(tempAry[0]);
        }
    }
    return addressAry;
}

var getLat = function() {
    latAry = new Array;
    for (i=1; i<11; i++) {
        if(document.getElementById('lat_'+i)){
            latAry.push(document.getElementById('lat_'+i).value);
        }
    }
    return latAry;
}

var getLon = function() {
    lonAry = new Array;
    for (i=1; i<11; i++) {
        if(document.getElementById('lon_'+i)){
            lonAry.push(document.getElementById('lon_'+i).value);
        }
    }
    return lonAry;
}

var useShowAddress = function(map, address, lat, lon) {
    for(i=0; i<address.length; i++) {
        if(address[i] != '') {
            var k = i+1;
            showAddress(k, map, address[i], lat[i], lon[i]);
        }
    }
}
var showAddress = function(k, map, address, lat, lon) {
    geocoder = new GClientGeocoder();
    if (geocoder) {
        geocoder.getLatLng(
        address,
        function(point) {
            if (point) {
                if (lat != "" && lon != "") {
                    point = new GLatLng(lon, lat);
                }
                var icon = new GIcon();
                icon.image = "./img/list_icon_"+k+".gif";
                //icon.shadow = "./img/icon3_2_2.png";
                icon.iconSize = new GSize(20, 20);
                //icon.shadowSize = new GSize(38, 26);
                icon.iconAnchor = new GPoint(10, 10);
                icon.infoWindowAnchor = new GPoint(10, 10);
                var marker = new GMarker(point, icon);
                map.addOverlay(marker);
                var href = document.getElementById('location_'+k).href;
                GEvent.addListener(marker, 'click', function() {
                    location.href = href;
                });
                $("#numClick_"+k).click(function(){
                    point = new String(point);
                    point = point.replace("(", "");
                    point = point.replace(")", "");
                    var pointAry = point.split(",");
                    var x = parseFloat(pointAry[0]);
                    var y = parseFloat(pointAry[1]);
                    map.panTo(new GLatLng(x, y), 16);
                    return false;
                });
            }else if (lat != "" && lon != "") {
                point = new GLatLng(lon, lat);
                var icon = new GIcon();
                icon.image = "./img/list_icon_"+k+".gif";
                //icon.shadow = "./img/icon3_2_2.png";
                icon.iconSize = new GSize(20, 20);
                //icon.shadowSize = new GSize(38, 26);
                icon.iconAnchor = new GPoint(10, 10);
                icon.infoWindowAnchor = new GPoint(10, 10);
                var marker = new GMarker(point, icon);
                map.addOverlay(marker);
                var href = document.getElementById('location_'+k).href;
                GEvent.addListener(marker, 'click', function() {
                    location.href = href;
                });
                $("#numClick_"+k).click(function(){
                    point = new String(point);
                    point = point.replace("(", "");
                    point = point.replace(")", "");
                    var pointAry = point.split(",");
                    var x = parseFloat(pointAry[0]);
                    var y = parseFloat(pointAry[1]);
                    map.panTo(new GLatLng(x, y), 16);
                    return false;
                });            	
            }else {
/*            	point = new GLatLng(35.737856,139.654534);
                var icon = new GIcon();
                icon.image = "./img/list_icon_"+k+".gif";
                //icon.shadow = "./img/icon3_2_2.png";
                icon.iconSize = new GSize(20, 20);
                //icon.shadowSize = new GSize(38, 26);
                icon.iconAnchor = new GPoint(10, 10);
                icon.infoWindowAnchor = new GPoint(10, 10);
                var marker = new GMarker(point, icon);
                map.addOverlay(marker);
                var href = document.getElementById('location_'+k).href;
                GEvent.addListener(marker, 'click', function() {
                    location.href = href;
                });
                $("#numClick_"+k).click(function(){
                    point = new String(point);
                    point = point.replace("(", "");
                    point = point.replace(")", "");
                    var pointAry = point.split(",");
                    var x = parseFloat(pointAry[0]);
                    var y = parseFloat(pointAry[1]);
                    map.panTo(new GLatLng(x, y), 16);
                    return false;
                }); 
 */           	
            }
        });
    }
}




//]]>
