// *******************************************************************************************************************************
//
// EGGOOGLE MAPS LIBRARY
// v1.0
// by iKnowHow.gr							Developed by : George Egglezos
//
// Revision History
// Version 1.0 (21/8/08) - Initial development
//
// USAGE INSTRUCTIONS
// 1. After including Google Maps original script path (the one with the key), include google_maps.js to your page:  <script src="google_maps.js" type="text/javascript"></script>
// 2. Call the functions ;)
//     
//  USAGE EXAMPLES
// <script  type="text/javascript">
//  (450, 600, G_SATELLITE_MAP, 'large');
//  gmAddPoint (38.0034, 23.88, "I'm a pin with an opened info window", 1);
//
//
//
//
//
// *******************************************************************************************************************************


//<![CDATA[

var gMap;
var gMapType;
var gMapControl;
var gOverviewControl;
var gaIcons 				= [];
var gaPoints 				= [];
var gaOpenInfoWindow 		= [];
var gaInfoWindowMaxWidth 	= [];
var gaContent = [];
var i = 0;

	
function createMarker(j) {

	var marker = new GMarker(gaPoints[j], gaIcons[j]);

	GEvent.addListener(marker, "click", function() {
		//marker.openInfoWindowHtml(gaContent[j], {maxWidth:gaInfoWindowMaxWidth});
		marker.openExtInfoWindow(
              gMap,
              "extInfoWindow_coolBlues",
              "<div>" + gaContent[j] + "</div>",
              {beakOffset: 1}
            ); 

	});

return marker;
}
		
		
		
		
		
// gmAddPoint: Adds an icon with info window onto the map
// 
// Parameters:
//		alt -> altitude
//		lon -> longitude
//		content -> HTML code
//		info_win_open -> 1: info window appears immediately after loading, 0: info window appears onMouseOver
//		icon_url -> URL path to icon, FOR INFO ON ICONS CHECK http://econym.googlepages.com/geicons.htm
//		icon_shadow_url -> URL path to icon shadow

function gmAddPoint (alt, lon, content, info_win_open, max_info_win_width, icon_url, icon_shadow_url) {

	// default values
	content 			= typeof(content) != 'undefined' ? content : '';
	info_win_open 		= typeof(info_win_open) != 'undefined' ? info_win_open : 0;
	max_info_win_width 	= typeof(max_info_win_width) != 'undefined' ? max_info_win_width : 250;
	icon_url 			= typeof(icon_url) != 'undefined' ? icon_url : "http://maps.google.com/mapfiles/kml/pal2/icon20.png";
	icon_shadow_url 	= typeof(icon_shadow_url) != 'undefined' ? icon_shadow_url : "http://maps.google.com/mapfiles/kml/pal2/icon20s.png";

	var baseIcon 				= new GIcon();
	baseIcon.iconSize 			= new GSize(25,26);
	//baseIcon.shadowSize 		= new GSize(56,32);
	baseIcon.iconAnchor 		= new GPoint(16,32);
	baseIcon.infoWindowAnchor 	= new GPoint(16,0);
	gaIcons[i] 					= new GIcon(baseIcon, icon_url, null, null);
	gaPoints[i] 				= new GLatLng(alt, lon);
	gaContent[i] 				= content;
	gaOpenInfoWindow[i] 		= info_win_open;
	gaInfoWindowMaxWidth[i] 	= max_info_win_width;
	i++;

}
		
		
// gmDrawMap: draws the map and sets map properties
// 
// Parameters:
//		w -> width
//		h -> height
//		mapType -> possible values: G_NORMAL_MAP, G_HYBRID_MAP, G_SATELLITE_MAP
//		mapControl -> possible values: 'small', 'large'
//		overviewControl -> 1: yes, 0: no
function gmDrawMap(w, h, mapType, mapControl, overviewControl) {

	gMapType 			= typeof(mapType) != 'undefined' ? mapType : G_NORMAL_MAP;
	gMapControl			= typeof(mapControl) != 'undefined' ? mapControl : 'small';
	gOverviewControl 	= typeof(overviewControl) != 'undefined' ? overviewControl : 1;
	
	document.write ("<div id='map' style='width: " + w + ";height:" + h + "'></div>");
}
	
	
// gmInitialize: Called after page loading. It does the drawing job...
// 
function gmInitialize() {

	if (GBrowserIsCompatible()) {

		if (!document.getElementById("map"))
			return;
			
		gMap = new GMap2(document.getElementById("map"));

		if (gMapControl != 'small')
			gMap.addControl(new GLargeMapControl());
		else	
			gMap.addControl(new GSmallMapControl());
			
		if (gOverviewControl != 0)	
			gMap.addControl(new GOverviewMapControl());


		gMap.setCenter(new GLatLng(0, 0), 0);
		var bounds = new GLatLngBounds();

		for (j=0; j<i; j++){
			bounds.extend(gaPoints[j]);
			var temp = createMarker(j);
	
			gMap.addOverlay(temp);
	
			if (gaOpenInfoWindow[j] != 0)
				temp.openInfoWindowHtml(gaContent[j], {maxWidth:gaInfoWindowMaxWidth[j]});
		}
	
		gMap.setZoom(7);
		var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2 ;
		var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2 ;
		gMap.setCenter(new GLatLng(clat,clng));

		gMap.setMapType(gMapType);		
	}
}
    //]]>
