var waitingpin = -1;

// A function to create the marker and set up the event window
function createMarker(longitude, latitude, html, index) {	
	var baseIcon = new GIcon();
	baseIcon.shadow = "http://www.realbrighton.com/images/pngs/pin_shadow.png";
	baseIcon.iconSize = new GSize(28, 42);
	baseIcon.shadowSize = new GSize(46, 41);
	baseIcon.iconAnchor = new GPoint(14, 42);
	baseIcon.infoWindowAnchor = new GPoint(26,8);
	baseIcon.infoShadowAnchor = new GPoint(18, 25);
	var point = new GPoint( longitude , latitude );
	var icon = new GIcon(baseIcon);
	icon.image = "http://www.realbrighton.com/images/pngs/pin_f"+index+".png";
	var marker = new GMarker(point, icon);
    GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
	});
	gmarkers[i] = marker;
    htmls[i] = html;
    mylats[i] = latitude;
    mylongs[i] = longitude;
    return marker;
} // end function

function createTabbedMarker(longitude, latitude, index, htmltabs, labels) {
	var baseIcon = new GIcon();
	baseIcon.shadow = "http://www.realbrighton.com/images/pngs/pin_shadow.png";
	baseIcon.iconSize = new GSize(28, 42);
	baseIcon.shadowSize = new GSize(46, 41);
	baseIcon.iconAnchor = new GPoint(14, 42);
	baseIcon.infoWindowAnchor = new GPoint(26,8);
	baseIcon.infoShadowAnchor = new GPoint(18, 25);
	var point = new GPoint( longitude , latitude );
	var icon = new GIcon(baseIcon);
	icon.image = "http://www.realbrighton.com/images/pngs/pin_f"+index+".png";
	
	var marker = new GMarker(point, icon);
	
	if (htmltabs.length > 2) {
		htmltabs[0] = '<div style="width:'+htmltabs.length*88+'px">' + htmltabs[0] + '</div>';
	}
	var thistabs = [];
	for (var l=0; l<htmltabs.length; l++) {
		thistabs.push(new GInfoWindowTab(labels[l],htmltabs[l]));
	}
	
	GEvent.addListener(marker, "click", function() {
	  // adjust the width so that the info window is large enough for this many tabs
	  marker.openInfoWindowTabsHtml(thistabs);
	});	
	gmarkers[i] = marker;
    htmls[i] = htmltabs;
    tabs[i] = thistabs;
    mylats[i] = latitude;
    mylongs[i] = longitude;
	return marker;
  }

function createPlainMarker(longitude, latitude, html) {
	var point = new GPoint( longitude , latitude );
	var marker = new GMarker(point);

	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
	});

    return marker;
} // end function

// This function picks up the click and opens the corresponding info window
function myclick(i) {
	gmarkers[i].openInfoWindowHtml(htmls[i]);
}

// This function picks up the click and opens the corresponding info window
function mytabclick(i) {
	gmarkers[i].openInfoWindowTabsHtml(tabs[i]);
}

function mytogtabclick(i,mymap) {
	mytogglemap(mymap,'on');
	gmarkers[i].openInfoWindowTabsHtml(tabs[i]);
}

function mylisttabclick(i,mymap) {
	waitingpin = i;
	mytogglemap(mymap,'on');
	if (listingmapon == 2) {	
		gmarkers[i].openInfoWindowTabsHtml(tabs[i]);
		waitingpin = -1;
	} // end if 
}

function mytogglemap(map,swit) {	
	loadlistingmap();
	if (GBrowserIsCompatible() && swit == 'on') document.getElementById(map).style.display = 'block';
	else document.getElementById(map).style.display = 'none';
	return false;
}


