// JavaScript Document

function showHide(el,show){
	var obj = document.getElementById(el);
	if (obj) {
		if (show) {
			/* obj.style.display = ''; */
			obj.style.visibility = "visible";
			obj.style.height = 'auto';
		} else {
			/* obj.style.display = 'none'; */
			obj.style.visibility = "hidden";
			obj.style.height = '0px';
		}
	}
}


var GoogleMap = {
  lng: 10.015283,
  lat: 53.578025,
  zoom: 4,
  surroundzoom: 11,
  element: 'user-mgdeposearch-pi1-gMap',
  linkdiv: 'user-mgdeposearch-pi1-gMap-link',
  linkaround: 'user-mgdeposearch-pi1-gMap-linkaround',
  parent_el: 'user-mgdeposearch-pi1-googlemap',
  map:null,
  overlays:new Array(),
  
  makeMap: function() {
    if (GBrowserIsCompatible()) {
		if (!document.getElementById(this.element)) {
			this.create_div(this.element);
		}
		if (document.getElementById(this.element)) {
			if (!this.map) {
				this.map = new GMap(document.getElementById(this.element));
				this.map.addControl(new GLargeMapControl());
				this.map.addControl(new GMapTypeControl());
			}
			
			this.map.centerAndZoom(new GPoint(this.lng, this.lat), this.zoom); 
			this.map.savePosition()
			
			this.setPoint();
			
			document.getElementById(this.parent_el).style.visibility = "visible";
		}
	}
  },
  
  setPoint: function() {
	  	this.map.clearOverlays();
		for (var i=0; i<this.overlays.length;i++) {
			this.map.addOverlay(this.overlays[i]);
		}
  },
  
  surroundZoom: function() {
	  	this.map.setZoom(this.surroundzoom);
  },
  
  setOverlayData: function(lat,lng,gicon,thtml) {
	var t_icon =  new GIcon();
	/* t_icon.image = "typo3conf/ext/user_mgdeposearch/res/gicon_" + gicon + ".png";
	t_icon.shadow = "typo3conf/ext/user_mgdeposearch/res/shadow.png";
	t_icon.iconSize = new GSize(19, 34);
	t_icon.shadowSize = new GSize(37, 34);
	t_icon.iconAnchor = new GPoint(9, 34);
	t_icon.infoWindowAnchor = new GPoint(9, 2);
	t_icon.infoShadowAnchor = new GPoint(18, 25); */
	
	t_icon.image = "http://" + window.location.hostname + "/typo3conf/ext/user_mgdeposearch/res/icon_" + gicon + ".png";
	t_icon.shadow = "http://" + window.location.hostname + "/typo3conf/ext/user_mgdeposearch/res/icon_shadow.png";
	t_icon.iconSize = new GSize(23, 61);
	t_icon.shadowSize = new GSize(65, 65);
	t_icon.iconAnchor = new GPoint(23, 61);
	t_icon.infoWindowAnchor = new GPoint(10, 5);
	t_icon.infoShadowAnchor = new GPoint(10, 5);
	
	var point = new GLatLng(lat,lng);
	var markerOptions = { icon:t_icon };
  	var marker = new GMarker(point, markerOptions);

  	GEvent.addListener(marker, "click", function() {
    	marker.openInfoWindowHtml(thtml);
  	});
	this.overlays.push(marker);
  },
  
  setOverlayDataHome: function(lat,lng,gicon,thtml) {
	var t_icon =  new GIcon();
	t_icon.image = "http://" + window.location.hostname + "/typo3conf/ext/user_mgdeposearch/res/icon_home.png";
	t_icon.shadow = "http://" + window.location.hostname + "/typo3conf/ext/user_mgdeposearch/res/icon_home_shadow.png";
	t_icon.iconSize = new GSize(41, 62);
	t_icon.shadowSize = new GSize(41, 62);
	t_icon.iconAnchor = new GPoint(2, 62);
	t_icon.infoWindowAnchor = new GPoint(10, 5);
	t_icon.infoShadowAnchor = new GPoint(10, 5);
	
	var point = new GLatLng(lat,lng);
	var markerOptions = { icon:t_icon };
  var marker = new GMarker(point, markerOptions);
  if (thtml!='') {
    GEvent.addListener(marker, "click", function() {
    	marker.openInfoWindowHtml(thtml);
    });
  }
	this.overlays.push(marker);
  },
  
  setAroundLink: function(ahref,aOnClick,aTitle) {
	if (!document.getElementById(this.linkdiv)) {
		this.create_div(this.linkdiv);
	}
	if (!document.getElementById(this.linkaround)) {
		var p = document.getElementById(this.linkdiv);
		var ne = document.createElement("a");
		ne.setAttribute("id",this.linkaround);
		ne.setAttribute("href",ahref);
		ne.onclick=new Function(aOnClick); 
		ne.className = 'more';
		ne.innerHTML=aTitle;
		p.appendChild(ne);
	} else {
		var ne = document.getElementById(this.linkaround);
		ne.setAttribute("href",ahref);
		ne.onclick=null; 
		ne.onclick=new Function(aOnClick); 
		ne.innerHTML=aTitle;
	}
  },
  
  clearOverlayData: function() {
	  this.overlays.length = 0
  },
  
  create_div: function(div) {
	  if (document.getElementById(this.parent_el)) {
		var p = document.getElementById(this.parent_el);
		var ne = document.createElement("div");
		ne.setAttribute("id",div);
		p.appendChild(ne);
	  }
  },
  
  setLng: function(lng) {
	  this.lng = lng;
  },

  setLat: function(lat) {
	  this.lat = lat;
  },
  
  setZoom: function(zoom) {
	  this.zoom = zoom;
  }
}

