  //<![CDATA[

var map;
var map_type;

function gmapload(n,$zoom_t,$map_t,$hybrid_t,$satellite_t,$data_lang) {

    if (GBrowserIsCompatible()) {
 
 		//Create the map and enable some functionalities
	    map = new GMap2(document.getElementById("gmap"));
		//Zooming
		map_control = new GLargeMapControl();
		if (arguments[0]) {
			map_control.getDefaultPosition = function() {
				return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10, 120));
		//	  var leftpos = document.getElementById("wrapper").offsetLeft;
		//	  return new GControlPosition(null, new GSize(leftpos, 120));
			}				
		}

		//Mini map
		mini_map = new GOverviewMapControl();
		mini_map.getDefaultPosition = function() {
		  return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(0, -4));
		}

		/*
		//Map view eg map: terrain	
		map_type = new GMapTypeControl();
		
		if (arguments[0]) {
			map_type.getDefaultPosition = function() {
			return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(10, 80));
			//  var leftpos = document.getElementById("wrapper").offsetLeft+10;
			//  return new GControlPosition(null, new GSize(leftpos, 90));
			}				
		}					
		*/
		
		
		/**** custom map type control ****/
		
		function mapType() {
    }
    mapType.prototype = new GMapTypeControl();

    // Creates a one DIV for each of the buttons and places them in a container
    // DIV which is returned as our control element. We add the control to
    // to the map container and return the element for the map class to
    // position properly.
    mapType.prototype.initialize = function(map) {
      var container = document.createElement("div");

     
      var mapDiv = document.createElement("div");
      this.setButtonStyle_(mapDiv);
      container.appendChild(mapDiv);
      mapDiv.appendChild(document.createTextNode($map_t));
      GEvent.addDomListener(mapDiv, "click", function() {
        map.setMapType(G_NORMAL_MAP);
      });

      var hybirdDiv = document.createElement("div");
      this.setButtonStyle_(hybirdDiv);
      container.appendChild(hybirdDiv);
      hybirdDiv.appendChild(document.createTextNode($hybrid_t));
      GEvent.addDomListener(hybirdDiv, "click", function() {
        map.setMapType(G_HYBRID_MAP);
      });
      
      var satellitedDiv = document.createElement("div");
      this.setButtonStyle_(satellitedDiv);
      container.appendChild(satellitedDiv);
      satellitedDiv.appendChild(document.createTextNode($satellite_t));
      GEvent.addDomListener(satellitedDiv, "click", function() {
        map.setMapType(G_SATELLITE_MAP);
      });

      map.getContainer().appendChild(container);
      return container;
    }

    // By default, the control will appear in the top left corner of the
    // map with 7 pixels of padding.
    mapType.prototype.getDefaultPosition = function() {
      return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 7));
    }

    // Sets the proper CSS for the given button element.
    mapType.prototype.setButtonStyle_ = function(button) {
      /*button.style.textDecoration = "underline";*/
      button.style.color = "#FFFFFF";
      button.style.backgroundColor = "#000000";
      button.style.font = "11px helvetica";
      button.style.border = "1px solid black";
     button.style.marginRight = "2px";
      button.style.paddingLeft = "6px";
      button.style.paddingRight = "6px";
      button.style.textAlign = "center";
      button.style.width = "30px";
      button.style.cursor = "pointer";
      button.style.display = "inline";
      button.style.fontWeight="bold";
    }
    
    
		/**** end custom map type control ****/
	
	
	
	/**** custom zoom ****/
			// A TextualZoomControl is a GControl that displays textual "Zoom In"
    // and "Zoom Out" buttons (as opposed to the iconic buttons used in
    // Google Maps).
    function TextualZoomControl() {
    }
    TextualZoomControl.prototype = new GControl();

    // Creates a one DIV for each of the buttons and places them in a container
    // DIV which is returned as our control element. We add the control to
    // to the map container and return the element for the map class to
    // position properly.
    TextualZoomControl.prototype.initialize = function(map) {
      var container = document.createElement("div");


			var zoomTxtDiv = document.createElement("div");
			zoomTxtDiv.setAttribute("style", "font-size:11px;font-family:helvetica;");
      this.setTxtStyle_(zoomTxtDiv);
      container.appendChild(zoomTxtDiv);
      zoomTxtDiv.appendChild(document.createTextNode($zoom_t));
      
      
      
      var zoomInDiv = document.createElement("div");
      this.setButtonStyle_(zoomInDiv);
      container.appendChild(zoomInDiv);
      zoomInDiv.appendChild(document.createTextNode("+"));
      GEvent.addDomListener(zoomInDiv, "click", function() {
        map.zoomIn();
      });

      var zoomOutDiv = document.createElement("div");
      this.setButtonStyle_(zoomOutDiv);
      container.appendChild(zoomOutDiv);
      zoomOutDiv.appendChild(document.createTextNode("-"));
      GEvent.addDomListener(zoomOutDiv, "click", function() {
        map.zoomOut();
      });

      map.getContainer().appendChild(container);
      return container;
    }

    // By default, the control will appear in the top left corner of the
    // map with 7 pixels of padding.
    TextualZoomControl.prototype.getDefaultPosition = function() {
      return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(9, 30));
    }

    // Sets the proper CSS for the given button element.
    TextualZoomControl.prototype.setButtonStyle_ = function(button) {
      /*button.style.textDecoration = "underline";*/
      button.style.color = "#FFFFFF";
      button.style.backgroundColor = "#000000";
      button.style.font = "14px helvetica";
      /*button.style.borderTop = "1px solid black";*/
      
      button.style.paddingLeft = "3px";
      button.style.paddingRight = "3px";
      button.style.textAlign = "center";
      button.style.cursor = "pointer";
      button.style.display = "inline";
      button.style.fontWeight="bold";
      button.style.verticalAlign="middle";
    }
    
    TextualZoomControl.prototype.setTxtStyle_ = function(button) {
			button.style.color = "#FFFFFF";
      button.style.backgroundColor = "#000000";
      /*button.style.font = "11px helvetica";*/
      button.style.border = "1px solid black";
    	/*button.style.paddingTop = "2px";
    	button.style.paddingBottom = "3px"*/
      button.style.paddingRight = "5px";
      button.style.paddingLeft = "5px";
      button.style.textAlign = "center";
      button.style.width = "30px";
      button.style.cursor = "pointer";
      button.style.display = "inline";
      button.style.fontWeight="bold";
			button.style.Height="48px";
		}
    /*
    function initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(37.441944, -122.141944), 13);
        map.addControl(new TextualZoomControl());
      }
    }
	*/
	/****  end custom zoon ****/
	
	
		//Adding map controls
		//map.addControl(mini_map);
		//map.addControl(map_type);
		//map.addControl(map_control);
		map.addControl(new TextualZoomControl());
		map.addControl(new mapType());
		map.setCenter(new GLatLng(20.13893,14.163606), 2);	
		map.setMapType(map.getMapTypes()[1]);
		map.enableScrollWheelZoom();
		
		//Show geocoods fo the current center of the map
        GEvent.addListener(map, "moveend", function() {var center = map.getCenter();});	

	    showLocations($data_lang);		
	}
}
	
var markers = new Array();
var htmls = new Array();
var arr_points = new Array();
var arr_pointsonly = new Array();

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;		
		} while (obj = obj.offsetParent);				
		return [curleft,curtop];
	}
}

function findPoses(obj) {
	var curleft = curtop = 0;
	curleft = obj.offsetParent.offsetLeft + obj.offsetParent.offsetParent.offsetLeft;
	curtop = obj.offsetParent.offsetTop + obj.offsetParent.offsetParent.offsetTop;
	return [curleft,curtop];
}

var gmarkers = [];
var wid_arr = [];
function showLocations($data_lang){
	var i = 0;
	
	//Create the market points
    function createTabbedMarker(point,html,labels, wid) {
		
		
		var icon = new GIcon(G_DEFAULT_ICON, "/global/shca_gmap_marker.png");
		icon.shadow = null;
		icon.iconSize = new GSize(10,10);
		icon.iconAnchor = new GPoint(5,5);
		
		//icon.image = "/vnz/img/winemapicon.png";
		/**/
		var marker = new GMarker(point, icon);

		GEvent.addListener(marker, "click", function() {
			var tabs = [];
			
			for (var i=0; i<htmls.length; i++) {
				tabs.push(new GInfoWindowTab(labels,html));			
			}
			var opts = {pixelOffset: new GSize(0,100)};
		
			var pointpx = map.fromLatLngToContainerPixel(point);
			var newc = map.fromContainerPixelToLatLng(new GPoint(pointpx.x,pointpx.y-100));	
			//map.openInfoWindowTabsHtml(point,tabs,{suppressMapPan:true});
			//map.openInfoWindowHtml(htmls[i]);
			marker.openInfoWindowHtml(html);
			map.panTo(newc);
			
		
	    });
	    
	    //markers[markers.length] = map;
	    
	    htmls[wid] = html;
	   
		return marker;/**/
		
	}

	// Read the data from example.xml
	var request = GXmlHttp.create();
   	request.open("GET", $data_lang, true);
	//request.open("GET", "/locations_data/", true);
	//alert ($data_lang);
    request.onreadystatechange = function() {
      if (request.readyState == 4) {
        var xmlDoc = GXml.parse(request.responseText);
        // obtain the array of markers and loop through it
        var markers = xmlDoc.documentElement.getElementsByTagName("marker");
				//alert("marker " + markers.length);
        for (var i = 0; i < markers.length; i++) {
          // obtain the attribues of each marker
          var lat = parseFloat(markers[i].getAttribute("lat"));
          var lng = parseFloat(markers[i].getAttribute("lng"));
          var point = new GLatLng(lat,lng);
          var label = markers[i].getAttribute("label");
		  		var wid = parseInt(markers[i].getElementsByTagName("location")[0].getAttribute("id"));
          var locationpanel = markers[i].getElementsByTagName("location")[0].firstChild.nodeValue;
          // create the marker
          var marker = createTabbedMarker(point, locationpanel,"Location", wid);
          
         
          map.addOverlay(marker);
           
          
		  gmarkers[wid] = marker;
		  
        }

		//if (initWinery) GEvent.trigger(gmarkers[initWinery],"click");
      }
    }
    request.send(null);
}	

var x = 5 ;
var y = 1 ;

var i = 0;
var anime = true;
	
function startClock(){ 
	x = x-y;
	setTimeout("startClock()", 1000);
	if(x==0 && anime==true){ 	
		
		gmarkers[wid_arr[i]].openInfoWindowHtml(htmls[i]);
		
		//map.panTo(new GLatLng(arr_points[x+1]['latitude'], arr_points[x+1]['longitude']));
		 //arr_pointsonly[i+1]); //new GLatLng(latitude, longitude)); 		
					
		x=5; 
		i++;
	}
} 

//startClock();

function openDescWindow(id){ 
		//alert(gmarkers.count);
		
		map.setZoom(14);
		//map.panTo('center');
		gmarkers[id].openInfoWindowHtml(htmls[id]);
		//map.panTo(new GLatLng(arr_points[x+1]['latitude'], arr_points[x+1]['longitude']));
		 //arr_pointsonly[i+1]); //new GLatLng(latitude, longitude)); 		
		
} 

function stopAnimation(){
	anime = false; 
}

//]]>

