﻿// JScript File

var map = null;
var pinID = 1;
var theObj;
         
         function GetMap()
         {
            map = new VEMap('map');
            map.LoadMap(new VELatLong(39, -99.33), 2 ,'r' ,false, VEMapMode.Mode2D, true);
            setlocations();
            AddPin(theObj);
         }   
         
         function AddPin(theObj)
         {   
            var pin;
            var pinID = 1;
            var img;
            for (var x = 0; x < theObj.quakes.length; x++){
                var mag = theObj.quakes[x].mag;
                switch(true) {
                    case (mag < 5) && (mag > 2.4):
                        img='./../themes/default/dot1.gif';
                        break;
                    
                    default:
                        img='./../themes/default/dotred.gif';
                        break;
                    }
                
                    pin = new VEPushpin(
                    pinID, 
                    new VELatLong(theObj.quakes[x].lat, theObj.quakes[x].lng), 
                    img, 
                    '<div><b>Magnitued:'+theObj.quakes[x].mag+'<b><br>Location:'+theObj.quakes[x].title+'</div>', 
                    '<div><ul><li>Time:'+theObj.quakes[x].desc+'</li><li>Lat/Lng:'+theObj.quakes[x].lat+'/'+theObj.quakes[x].lng+'</li><li><a class="sudolink" onclick="centermap('+theObj.quakes[x].lat+','+theObj.quakes[x].lng+')"> Zoom to location</a></li></ul></div>'
                );
            map.AddPushpin(pin);
            pinID++;
            
            }
            
         }   
         
         function centermap(lat, lng)
         {
            map.SetCenterAndZoom(new VELatLong(lat, lng), 8);
         }
         
         function setlocations(){
            var jsontext = document.getElementById("hvquakes").value;
            theObj = jsontext.parseJSON();
         }
