﻿function myGuid()
{
var result, i, j;
result = '';
for(j=0; j<32; j++)
{
if( j == 8 || j == 12|| j == 16|| j == 20)
result = result + '';
i = Math.floor(Math.random()*16).toString(16).toUpperCase();
result = result + i;
}

return result
}
        var icon = new GIcon();
         icon.image = "marker.png";
        icon.iconAnchor = new GPoint(16, 30);
        icon.iconSize = new GSize(16,30);
        icon.infoWindowAnchor = new GPoint(16, 0); 
        function getIcon(){
            
                      
            return icon;
        }

function thunder_map() {
    this.map;
    this.geocoder;
    
    this.createCanvas = function(instance, h, w,zoomed,latitude,longitude){
        var instance = myGuid();
        document.write("<div id='" + instance + "' style='width: " + w + "px; height: " + h + "px'></div>");
        this.map = new GMap2(document.getElementById(instance));    
        this.geocoder = new GClientGeocoder();
        this.map.setCenter(new GLatLng(latitude,longitude), zoomed);
        //this.map.addControl(new GSmallMapControl());
        
        
//        if(document.getElementById(instance)){
//            var rights_stuff = document.getElementById(instance).getElementsByTagName("span")[0]
//            rights_stuff.style.color = "#000000";
//            rights_stuff.style.fontSize = "8px";
//        }
    }
        
    this.addPointer = function(address, lnk, title, message){
        if (this.geocoder){
            var map2 = this.map;
            this.geocoder.getLatLng(address, function (point){
                //map2.setCenter(point, 13);
                var marker = new GMarker(point);

                map2.addOverlay(marker);  
				var m = '';
				m += '<strong>' + title + '</strong><br/>';
				m += address + '<br/><br/>';
				
				if (message != '') m += message + '<br/>';
				m += '<a href="' + lnk + '" target="_blank">View</a> this center<br/>';
				
				
//                GEvent.addListener(marker, 'click', function(){ 
//                marker.openInfoWindowHtml(m); 
//                });
                //marker.openInfoWindowHtml(m);
            });
        }
    }      
}



function thunder_bigmap() {
    this.map;
    this.geocoder;
    
    this.createCanvas = function(instance, h, w,zoomed,latitude,longitude){
        var instance = myGuid();
        document.write("<div id='" + instance + "' style='width: " + w + "px; height: " + h + "px'></div>");
        this.map = new GMap2(document.getElementById(instance));    
        this.geocoder = new GClientGeocoder();
        this.map.setCenter(new GLatLng(latitude,longitude), zoomed);
        //this.map.addControl(new GSmallMapControl());
        
          this.map.addControl(new GMapTypeControl());
          this.map.addControl(new GLargeMapControl());
//        if(document.getElementById(instance)){
//            var rights_stuff = document.getElementById(instance).getElementsByTagName("span")[0]
//            rights_stuff.style.color = "#000000";
//            rights_stuff.style.fontSize = "8px";
//        }
    }
  
  
    
    this.addPointer = function(address, lnk, title, message){
        if (this.geocoder){
            var map2 = this.map;
            this.geocoder.getLatLng(address, function (point){
                //map2.setCenter(point, 13);
                var marker = new GMarker(point, {icon: getIcon()});

                map2.addOverlay(marker);  
				//var m = '';
//				m += '<strong>' + title + '</strong><br/>';
//				m += address + '<br/><br/>';
//				
//				if (message != '') m += message + '<br/>';
//				m += '<a href="' + lnk + '" target="_blank">View</a> this center<br/>';
//				
				
//                GEvent.addListener(marker, 'click', function(){ 
//                marker.openInfoWindowHtml(m); 
//                });
                //marker.openInfoWindowHtml(m);
            });
        }
    }      
}



function thunder_check() {
    this.map;
    this.geocoder;
    
    this.checkAddress = function(address, fcn){
            this.geocoder = new GClientGeocoder();
            this.geocoder.getLocations(address, fcn);
    }
        
    this.addPointer = function(address, lnk, title, message){
        if (this.geocoder){
            var map2 = this.map;
            this.geocoder.getLatLng(address, function (point){
                map2.setCenter(point, 13);
                map2.addControl(new GLargeMapControl());
                var marker = new GMarker(point);

                map2.addOverlay(marker);  

				var m = '';
				m += '<strong>' + title + '</strong><br/>';
				m += address + '<br/><br/>';
				
				m += message + '<br/>';
				
				//'http://www.google.com/maps?saddr=' + address;
                GEvent.addListener(marker, 'click', function(){ 
                marker.openInfoWindowHtml(m);
                });
                marker.openInfoWindowHtml(m);
            });
        }
    }      
}