var IEBrowser = navigator.appVersion.split("MSIE");
var IEVersion = parseFloat(IEBrowser[1]);


function CustomMapTypeControl() {
}
CustomMapTypeControl.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.
CustomMapTypeControl.prototype.initialize = function(map) {
  var container = document.createElement("div");

  var mapaTipus = document.createElement("div");
  this.setButtonStyle_(mapaTipus,"img/mapa2.png","mt");
  container.appendChild(mapaTipus);
  GEvent.addDomListener(mapaTipus, "click", function() {
    map.setMapType(G_MAP_TYPE);
  });

  var satTipus = document.createElement("div");
  this.setButtonStyle_(satTipus,"img/satellit2.png","st");
  container.appendChild(satTipus);
  GEvent.addDomListener(satTipus, "click", function() {
    map.setMapType(G_SATELLITE_TYPE);
  });

  var hybTipus = document.createElement("div");
  this.setButtonStyle_(hybTipus,"img/hibrid2.png","ht");
  container.appendChild(hybTipus);
  GEvent.addDomListener(hybTipus, "click", function() {
    map.setMapType(G_HYBRID_TYPE);
  });  

  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.
CustomMapTypeControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 7));
}

/*
// Sets the proper CSS for the given button element.
CustomMapTypeControl.prototype.setButtonStyle_ = function(button) {
  button.setAttribute("style","float:left");
  button.style.styleFloat = "left";
  button.style.textDecoration = "underline";
  button.style.color = "#0000cc";
  button.style.backgroundColor = "white";
  button.style.font = "small Arial";
  button.style.border = "1px solid black";
  button.style.padding = "2px";
  button.style.marginLeft = "3px";
  button.style.textAlign = "center";
  button.style.width = "6em";
  button.style.cursor = "pointer";
}
*/
CustomMapTypeControl.prototype.setButtonStyle_ = function(button,imgfile,id) {
	button.setAttribute("style","float:left");
	button.style.styleFloat = "left";

	var image = document.createElement("img");
	if (!IEVersion || (IEVersion && IEVersion >= 7)) image.src = imgfile;
	else {
		image.src = "img/blank.gif";
		image.style.filter = "filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+imgfile+"')";
	}
	image.id = id;
	button.appendChild(image);
	button.style.cursor = "pointer";
	button.style.color = "white";
	button.style.font = "small Arial";
	button.style.padding = "2px";
	button.style.marginBottom = "3px";
	button.style.textAlign = "center";
}





function CustomMapZoomControl() {
}
CustomMapZoomControl.prototype = new GControl();

CustomMapZoomControl.prototype.initialize = function(map) {
  var container = document.createElement("div");

  var zoomInDiv = document.createElement("div");
  this.setButtonStyle_(zoomInDiv,"img/lupa_plus2.png","zi");
  container.appendChild(zoomInDiv);
  GEvent.addDomListener(zoomInDiv, "click", function() {
    map.zoomIn();
  });

  var zoomOutDiv = document.createElement("div");
  this.setButtonStyle_(zoomOutDiv,"img/lupa_minus2.png","zo");
  container.appendChild(zoomOutDiv);
  GEvent.addDomListener(zoomOutDiv, "click", function() {
    map.zoomOut();
  });

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

CustomMapZoomControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 15));
}

CustomMapZoomControl.prototype.setButtonStyle_ = function(button,imgfile,id) {
	var image = document.createElement("img");
	if (!IEVersion || (IEVersion && IEVersion >= 7)) image.src = imgfile;
	else {
		image.src = "img/blank.gif";
		image.style.filter = "filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+imgfile+"')";
	}
	image.id = id;
	button.appendChild(image);
	button.style.cursor = "pointer";
	button.style.color = "white";
	button.style.font = "small Arial";
	button.style.padding = "0px";
	button.style.margin = "0px";
	button.style.textAlign = "center";
}