
function ClassMarkers()
{
	this.TegelFormaatX = 0.8
	this.TegelFormaatY = 0.4
	this.Rectangle = new Array()
	this.Getoond = new Array()
	this.HtmlCode = new Array()
	this.Called = new Array()
	this.isClear = true
	this.Enabled = true 
	
	this.Initialize = function()
	{
	}
	
	this.SetEnabled = function(able)
	{
	    this.Enabled = able
	    if (this.Enabled == false)
	    {
			this.Clear()
	    }
	    else
	    {
	        this.Refresh()
	    }
	}
	
	this.Refresh = function()
	{  
	    if (!this.Enabled) return
		if (GoogleMap.getZoom() < 10)
		{
			this.Clear()
			return
		}
		
		
		var bounds = GoogleMap.getBounds()
		var southWest = bounds.getSouthWest()
		var northEast = bounds.getNorthEast()
		var xMin = southWest.lng()
		var xMax = northEast.lng()
		var yMax = northEast.lat()
		var yMin = southWest.lat()
		
		xMin = Math.floor(xMin / this.TegelFormaatX)
		xMax = Math.ceil(xMax / this.TegelFormaatX)
		yMin = Math.floor(yMin / this.TegelFormaatY)
		yMax = Math.ceil(yMax / this.TegelFormaatY)
		
		for(y=yMin; y<=yMax; y++)
		{
			for(x=xMin; x<=xMax; x++)
			{
				key = x + '_' + y
				if (!this.Getoond[key])
				{
					if (this.HtmlCode[key])
					{
						this.AddSquare(this.HtmlCode[key], x, y)
					}
					else
					{
					    if (!this.Called[key])
					    {
					        this.Called[key] = '1'
					        this.CallXmlHttp(x, y)
					    }
					}
				}
			}
		}
	}

	this.AddSquare = function(sHTML, x, y)
	{
		key = x + '_' + y
		this.Getoond[key] = true
		
		xMin = x * this.TegelFormaatX
		xMax = xMin + this.TegelFormaatX
		yMin = y * this.TegelFormaatY
		yMax = yMin + this.TegelFormaatY
		
		var rectBounds = new GLatLngBounds
		(
			new GLatLng(yMin, xMin),
			new GLatLng(yMax, xMax)
		
		)
		
	    sHTML = this.RemoveCurrentMarker(sHTML)

		GoogleMap.addOverlay(new ClassRectangle(rectBounds, sHTML))
		this.isClear = false
	}

	this.RemoveCurrentMarker = function(sHTML)
	{
		if (sHTML.indexOf('Hover(event,\'' + Settings.CurrentMarker) > -1)
		{
			images = sHTML.split('\n')
			for(i=0; i<images.length; i++)
			{
				if (images[i].indexOf('Hover(event,\'' + Settings.CurrentMarker) > -1)
				{
					images[i] = ''
					i = images.length
				}
			}
			sHTML = images.join('\n')
		}
		return sHTML
	}	
	
	this.Clear = function()
	{
		if (this.isClear) return
		GoogleMap.clearOverlays();
		if (window.detailMarker) GoogleMap.addOverlay(detailMarker);
		this.Getoond = new Array()
	}

	this.CallXmlHttp = function(x, y)
	{
		var XMLHTTP = false
		if ( window.ActiveXObject ) XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP")
		if ( window.XMLHttpRequest ) XMLHTTP = new XMLHttpRequest()

		XMLHTTP.onreadystatechange = function()
		{
			if (XMLHTTP.readyState == 4)
			{
				var sText = XMLHTTP.responseText
				XMLHTTP = null
				var key = x + '_' + y
				Markers.HtmlCode[key] = sText
				Markers.AddSquare(sText, x, y)
			}
		}
		pcx = x * this.TegelFormaatX
		pcy = y * this.TegelFormaatY
		
		URL = Settings.MarkerUrl + '?xVan=' + pcx + '&yVan=' + pcy + '&xTot=' + (pcx + this.TegelFormaatX) + '&yTot=' + (pcy + this.TegelFormaatY) + '&date=' + new Date()
		//prompt(1,URL)
		
		XMLHTTP.open("GET", URL, true)
		XMLHTTP.send(null)
		
	}
}


