// img size from zoom level 0 and up to 19

var a_zoom_image = [ 1,3,5,7,9,11,13,15,17,19,21,23,24,25,27,29,31,33,35,35,35,35,35,];
//var a_zoom_image = [ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,19,19,19,19,];



function to_parm(p1) {
	alert("to_parm")
	window.open("/content/show_parameter.asp","Detail","menubar=yes,screenX=10 screenY=30 left=10 top=30 HEIGHT=650,WIDTH=850,status=no,toolbar=no,directories=no,scrollbars=yes,location=no,resizable=yes");

}
function MarkerLight(latlng, opts) {
	this.latlng = latlng;

	if (!opts) opts = {};

	this.n_code 			= opts.n_code;
	this.name   			= opts.name;
	this.parameters_p021 	= opts.parameters_p021;
//	this.type				= opts.type;
	this.clicked_ 			= 0;
}


MarkerLight.prototype = new GOverlay();


MarkerLight.prototype.initialize = function(map) {
	var me = this;
	var n_zoom = map.getZoom()


	var div = document.createElement("div");

	div.style.position = "absolute";
	div.style.paddingLeft = "0px";
	div.style.cursor = 'pointer';


	var img = document.createElement("img");

	img.src = '/grfx/gis/station_'+this.active_in_last_update+'.png'

  	img.style.width = a_zoom_image[n_zoom] + "px";
	img.style.height = a_zoom_image[n_zoom] + "px";

	div.appendChild(img);


///////////////////////////////////////////////
// dom listener voor knooppunten
///////////////////////////////////////////////

	GEvent.addDomListener(div, "mouseover", function(event) {
	  show_tool_tip(me);
	});

	GEvent.addDomListener(div,"mouseout", function() {
		tooltip.style.visibility="hidden"
	});

	GEvent.addDomListener(div, "click", function(event) {

		show_info_window(me);
	});


	map.getPane(G_MAP_MARKER_PANE).appendChild(div);

	this.map_ = map;
	this.div_ = div;


};

function show_info_window(marker) {

	tooltip.style.visibility="hidden"

	var c_html = '';
	var c_temp = '';
	var c_gif = '';
	c_html += '<b class=ttl>Station name: </b><br />'+marker.name;
	c_html += '<br /><br />'

	if (marker.parameters_p021 != undefined) {
		c_html += '<b class=ttl>Parameters active:</b><br />'
		var parms = marker.parameters_p021.split(',');
		for(var i=0;i<parms.length;i++){

			c_temp = '';
			c_gif	= ""
			switch (parms[i]) {
				case 'ASLV':
					c_temp = 'Sea level';
					c_gif = 'aslv';
					break;
				case 'EWSB':
					c_temp = 'Wave height & winds';
					c_gif = 'wvst';
					break;
				case 'PSAL':
					c_temp = 'Sea surface salinity';
					c_gif = 'psal';
					break;
				case 'RFVL':
					c_temp = 'Currents';
					c_gif = 'rfvl';
					break;
				case 'TEMP':
					c_temp = 'Sea surface temperature';
					c_gif = 'temp';
					break;
			}

			var c_url = "Javascript:lightbox_show('SEPRISE&nbsp;-&nbsp;European&nbsp;real-time&nbsp;data&nbsp;service','/content/station_detail.asp?menu=0000000_"+marker.n_code+"_"+parms[i]+"')"
			c_html += "<img src='/grfx/" + c_gif + ".gif' width='16' height='16' alt='' border='0' /> <a href="+c_url + ">"+c_temp+"</a>";
			c_html += '<br>'
		}
	}

    map.openInfoWindowHtml(marker.getPoint(),c_html);

}

function show_tool_tip(marker) {

	tooltip.innerHTML = "Station name: "+marker.name;

	var point = map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(),map.getZoom());
	var offset = map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
	var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x ,- offset.y + point.y ));

	pos.apply(tooltip);

	tooltip.style.visibility="visible";
}

MarkerLight.prototype.remove = function() {
  this.div_.parentNode.removeChild(this.div_);
};

MarkerLight.prototype.copy = function() {
  var opts = {};
  opts.color = this.color_;
  opts.height = this.height_;
  opts.width = this.width_;
  opts.image = this.image_;
  opts.imageOver = this.image_;
  return new MarkerLight(this.latlng, opts);
};


MarkerLight.prototype.redraw = function(force) {

  if (!force) return;

	var divPixel = this.map_.fromLatLngToDivPixel(this.latlng);
	var n_zoom = this.map_.getZoom()

	this.div_.style.width = a_zoom_image[n_zoom] + "px";
	this.div_.style.left = (divPixel.x)- (a_zoom_image[n_zoom]/2) + "px"
	this.div_.style.height = a_zoom_image[n_zoom] + "px";
	this.div_.style.top = (divPixel.y) - (a_zoom_image[n_zoom]/2) + "px";
};

MarkerLight.prototype.getZIndex = function(m) {
  return GOverlay.getZIndex(marker.getPoint().lat())-m.clicked*10000;
}

MarkerLight.prototype.getPoint = function() {
  return this.latlng;
};

MarkerLight.prototype.setStyle = function(style) {
  for (s in style) {
    this.div_.style[s] = style[s];
  }
};

MarkerLight.prototype.setImage = function(image) {
  this.div_.style.background = 'url("' + image + '")';
}

