function trim(value) {
  value = value.replace(/^\s+/,''); 
  value = value.replace(/\s+$/,'');
  return value;
}

function initCustomMarker(marker) {
	var oMarker = new Object()
	oMarker.title = marker.getAttribute("title")
	oMarker.page_id = marker.getAttribute("page_id")
	oMarker.lat = marker.getAttribute("lat")
	oMarker.lng = marker.getAttribute("lng")
	oMarker.coord = new GLatLng(parseFloat(oMarker.lat), parseFloat(oMarker.lng))
	oMarker.html = '<table cellpadding="4" cellspacing="0" border="0"><tr><td class="infoBoxTitle" style="white-space: nowrap"><a href="view.cfm?page_id=' + oMarker.page_id + '">' + oMarker.title + '</a></td></tr></table>'
	return oMarker
}

function showCustomMarkers() {
	// clear existing overlays
	gMap.clearOverlays()
	// add markers to map
	if (aMarkers.length > 0) {
		for (var i = 0; i < aMarkers.length; i++) {
			gMap.addOverlay( new customMarker(aMarkers[i]) )
		}
	}
}

function getCustomMarker(name) {
	// find the requested marker
	var oMarker = new Object()
	for (var i = 0; i < aMarkers.length; i++) {
		if (aMarkers[i].name == name) {
			oMarker = aMarkers[i]
			break
		}
	}
	// return the marker
	return oMarker
}

/* CustomMarkers Class */

function customMarker(oMarker) {
	this.oMarker = oMarker
}

customMarker.prototype = new GOverlay()

customMarker.prototype.initialize = function(map) 
{
	var div = document.createElement("div")
	div.style.position = "absolute"
	div.oMarker = this.oMarker
	
	// set extention for image used
	var imgExtention = (browserDetect.isWinIE && !(browserDetect.isWinIE7 || browserDetect.isWinIEVista)) ? 'gif' : 'png'
	
	var sText = '<table cellpadding="0" cellspacing="0" border="0" onmouseover="if(typeof(infoBoxTimeoutID)==\'number\'){clearTimeout(infoBoxTimeoutID)}"><tr><td>'
	sText += '<img src="' + _gfxfolder_maps + 'markers/blue.' + imgExtention + '"/>'
	sText += '</td></tr></table>'
	
	// add contents to container
	div.innerHTML = sText
	
	// attach events
	GEvent.addDomListener(div, "mouseover", function() { if (typeof(openInfoBox) == 'function') openInfoBox(this.oMarker); })
	GEvent.addDomListener(div, "mouseout", function() { if (typeof(closeInfoBox) == 'function' && infoBoxTimeoutID) infoBoxTimeoutID = setTimeout("closeInfoBox()", 500); })
	
	this.map_ = map	
	this.div_ = div
	
	// add container to map
	map.getPane(G_MAP_MARKER_PANE).appendChild(this.div_)
}

customMarker.prototype.remove = function() 
{
	this.div_.parentNode.removeChild(this.div_)
	this.div_ = null
}

customMarker.prototype.copy = function() 
{
	return new customMarker(this.oMarker)
}

customMarker.prototype.redraw = function(force)
{
	if (!force) return
	
	var bounds = gMap.getBounds()
	var c = this.map_.fromLatLngToDivPixel(this.oMarker.coord)
	
	//alert('left: ' + c.x + '\ntop: ' + c.y + '\nthis.div_.offsetWidth: ' + this.div_.offsetWidth + '\nthis.div_.offsetHeight: ' + this.div_.offsetHeight)
	
	//this.div_.style.border = "1px solid red"
	this.div_.style.left = (c.x - 3) + "px"
	this.div_.style.top = ((c.y + 3) - this.div_.offsetHeight) + "px"
	
	//alert('left: ' + this.div_.style.left + '\ntop: ' + this.div_.style.top)
}

/* End CustomMarker Class */
