// this variable will collect the html which will eventually be placed in the loc
var loc_html = "";

// arrays to hold copies of the markers and html used by the loc
// because the function closure trick doesnt work there
var gmarkers = [];
var i = 0;
var lastlinkid;
var startZoom = 7;
var startLatitude = 14.0453982353;
var startLongitude = 47.4826987748; 
var deselectCurrent = function() {};

function mySetCenter(parLat, parLong) {
	centerLatitude = parLat;
	centerLongitude = parLong;
}

function createMarker(point,name, adresse, html) {
	/***
	var letteredIcon = new GIcon(baseIcon);
	letteredIcon.image = "images/location-pin.png";
	// Set up our GMarkerOptions object
	markerOptions = { icon:letteredIcon };
	var marker = new GMarker(point, markerOptions);
	***/

	var marker = new GMarker(point);
	var linkid = "link"+i;
	gmarkers[i] = marker;
	var listItem = document.createElement('li');
	var listItemLink = listItem.appendChild(document.createElement('a'));
	listItemLink.href = 'javascript:myClick(' + i + ')';
	listItemLink.innerHTML = name + '<span class="adresse">' + adresse + '</span>';

	var focusPoint = function() {
		deselectCurrent();
		listItem.className = 'current';
		deselectCurrent = function() { listItem.className = ''; }
		marker.openInfoWindowHtml(html);
		//map.panTo(point);
		return false;
	}

	GEvent.addListener(marker, 'click', focusPoint);
	listItemLink.onclick = focusPoint;

	document.getElementById('sidebar-list').appendChild(listItem);
	
	i++;
	return marker;
}

// This function picks up the click and opens the corresponding info window
function myClick(i) {
	GEvent.trigger(gmarkers[i], "click");
}

function windowHeight() {
	// Standard browsers (Mozilla, Safari, etc.)
	if (self.innerHeight)
		return self.innerHeight;
	// IE 6
	if (document.documentElement && document.documentElement.clientHeight)
		return document.documentElement.clientHeight;
	// IE 5
	if (document.body)
		return document.body.clientHeight;
	// Just in case.
	return 0;
}
function handleResize() {
	var height = windowHeight() - document.getElementById('toolbar').offsetHeight - 30;
	document.getElementById('map').style.height = height + 'px';
	document.getElementById('sidebar').style.height = height + 'px';
}

function changeBodyClass(from, to) {
     document.body.className = document.body.className.replace(from, to);
     return false;
}

