        var map, wms, vectors;

        function init(){
            var lon = 65;
            var lat = 15;
            var zoom = 3;
            var symbol = new Geometry('circle', 20, 1312978855);

            var context = {
                getSize: function(feature) {
                    return 20 + Math.round(symbol.getSize(feature.attributes["population"]) * Math.pow(2,map.getZoom()-1));
                },
                getChartURL: function(feature) {
                    var values = feature.attributes["pop_0_14"] + ',' + feature.attributes["pop_15_59"] + ',' + feature.attributes["pop_60_above"];
                    var size = 20 + Math.round(symbol.getSize(feature.attributes["population"]) * Math.pow(2,map.getZoom()-1));
                    var charturl = 'http://chart.apis.google.com/chart?cht=p&chd=t:' + values + '&chs=' + size + 'x' + size + '&chf=bg,s,ffffff00';
                    return charturl;
                }
            };

            var template = {
                fillOpacity: 1.0,
                externalGraphic: "${getChartURL}",
                graphicWidth: "${getSize}",
                graphicHeight: "${getSize}",
                strokeWidth: 0
            };

            var style = new OpenLayers.Style(template, {context: context});
		    var styleMap = new OpenLayers.StyleMap({'default': style, 'select': {fillOpacity: 0.7}});

            var options = {
                numZoomLevels: 7,
                controls: []  // Remove all controls
            };

            map = new OpenLayers.Map( 'olmap', options );

            wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
                                            "http://labs.metacarta.com/wms/vmap0?",
                                            {layers: 'basic'},
                                            {isBaseLayer: true} );

            vectors = new OpenLayers.Layer.GML( "Internet Users", "../data/json/population_2005_chart.json",
                                                { format: OpenLayers.Format.GeoJSON,
                                                  styleMap: styleMap,
                                                  isBaseLayer: false,
                                                  projection: new OpenLayers.Projection("EPSG:4326")} );

            map.addLayers([wms, vectors]);
            map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);


            map.addControl(new OpenLayers.Control.LayerSwitcher());
            map.addControl(new OpenLayers.Control.MouseDefaults());
            map.addControl(new OpenLayers.Control.PanZoomBar());

            var options = {
               hover: true,
               onSelect: serialize
            };

            var select = new OpenLayers.Control.SelectFeature(vectors, options);
            map.addControl(select);
            select.activate();
        }

        function serialize() {
            var Msg = "<strong>" + vectors.selectedFeatures[0].attributes["name"] + "</strong><br/>";
            Msg    += "Population: " + vectors.selectedFeatures[0].attributes["population"] + "<br/>";
            Msg    += "0-14 years: " + vectors.selectedFeatures[0].attributes["pop_0_14"] + "%<br/>";
            Msg    += "15-59 years: " + vectors.selectedFeatures[0].attributes["pop_15_59"] + "%<br/>";
            Msg    += "60 and over: " + vectors.selectedFeatures[0].attributes["pop_60_above"] + "%<br/>";
            document.getElementById("info").innerHTML = Msg;
        }

		function Geometry(symbol, maxSize, maxValue){
		    this.symbol = symbol;
		    this.maxSize = maxSize;
		    this.maxValue = maxValue;
		
		    this.getSize = function(value){
		        switch(this.symbol) {
		            case 'circle': // Returns radius of the circle
		            case 'square': // Returns length of a side
		                return Math.sqrt(value/this.maxValue)*this.maxSize;
		            case 'bar': // Returns height of the bar
		                return (value/this.maxValue)*this.maxSize;
		            case 'sphere': // Returns radius of the sphere
		            case 'cube': // Returns length of a side
		                return Math.pow(value/this.maxValue, 1/3)*this.maxSize;
		        }
		    }
		}		
		