$(window).bind('load', function(){
    /**
     * @author ekeneijeoma
     */
    var places;
    var placeIndex
    var zoom = 11;
    
    loadMap();
	
    function loadMap(){
        google.load("maps", "2", {
            "callback": doMap
        });
    }
    
    function doMap(){
        if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map"));
            //		map.setMapType(G_SATELLITE_MAP);
            
            places = [{
                id: 1,
                name: "Los Angeles, CA",
                description: "Los Angeles, CA",
                position: new GLatLng(34.05329, -118.245009)
            }, {
                id: 3,
                name: "New York, NY",
                description: "New York, NY",
                position: new GLatLng(40.71455, -74.007124)
            }, {
                id: 5,
                name: "London, United Kingdom",
                description: "London, United Kingdom",
                position: new GLatLng(51.506325, -0.127144)
            }, {
                id: 7,
                name: "Amsterdam, The Netherlands",
                description: "Amsterdam, The Netherlands",
                position: new GLatLng(52.37312, 4.893195)
            }, {
                id: 9,
                name: "Milan MI, Italy",
                description: "Milan MI, Italy",
                position: new GLatLng(45.468945, 9.18103)
            }];
            
            placeIndex = 0;
            
            update(map);
            
            window.setTimeout(function(){
                update(map);
            }, 15000);
        }
    }
    
    function scroll(map){
        var position = map.getCenter();
        
        var newLong = position.lng() - 0.00025;
        
        if (newLong < -180) {
            newLong = 180;
        }
        
        position = new GLatLng(position.lat(), newLong);
        
        map.panTo(position);
        
        window.setTimeout(function(){
            scroll(map);
        }, 100);
    }
    
    function update(map){
        if (placeIndex < places.length - 1) {
            placeIndex++;
        }
        else {
            placeIndex = 0;
        }
        
        var place = places[placeIndex];
        
        map.setCenter(place.position, zoom);
        
        $("#name").html(place.name);
        document.title = "Where / " + place.name;
        
        scroll(map);
        
        window.setTimeout(function(){
            update(map);
        }, 15000);
    }
})
