// JavaScript Document
function Overlay(map, buttonId, properties) {
	this.visible = false;
	this.map = map;
	this.buttonId = buttonId;
	if (properties == null) {
		this.properties = {};
	} else {
    	this.properties = properties;
	}
	//this.icon = icon;
	this.overlays = new Array();
}
Overlay.prototype.show = function()
{
	if(!this.visible)
	{
	this.loadOverlays();
	var element = document.getElementById(this.buttonId);
	element.style.backgroundColor='#ffff00';
	this.visible = true;
	}
}
Overlay.prototype.hide = function()
{
	//add display code here
	if(this.visible)
	{
	for (var i = 0; i < this.overlays.length; i++) {
	        this.map.removeOverlay(this.overlays[i]);
	    }
	this.overlays = new Array();
	var element = document.getElementById(this.buttonId);
	element.style.backgroundColor='#cccccc';
	this.visible = false;
	}
}
Overlay.prototype.toggle = function()
{
	if (this.visible) 
	{
		this.hide();	
	}
	else
	{
		this.show();
	}
}
Overlay.prototype.addGGeoXML = function(URL)
{
	this.addOverlay(new GGeoXml(URL));	
	//gml = new GeoXml("gml", this.map, URL);
	//gml.parse();

}

Overlay.prototype.addOverlay = function(overlay)
{
	this.map.addOverlay(overlay);
	this.overlays[this.overlays.length] = overlay;
}

Overlay.prototype.addMarker = function (latitude, longitude, title, theHTML, theID, specificIcon)
{
		var theIcon = '';
		var addLightbox = this.addLightbox;
		var LatLong = new GLatLng(latitude,longitude);
		if (specificIcon !='') {theIcon = eval(specificIcon);}
		else if (this.properties.icon !='' || this.properties.icon !='undefined') {theIcon = this.properties.icon;}
		var marker = new GMarker(LatLong, theIcon);
		var tooltip = new Tooltip(marker,title,1);
		marker.tooltip = tooltip;
		this.map.addOverlay(tooltip);
		$("#message").appendTo(this.map.getPane(G_MAP_FLOAT_SHADOW_PANE));
		GEvent.addListener(marker,'mouseover',function(){
			this.tooltip.show();
		});
		GEvent.addListener(marker,'mouseout',function(){
			this.tooltip.hide();
		});
		GEvent.addListener(marker,"click",function()
			{
				$("#message").hide();
				//map.openInfoWindow(LatLong, (theHTML));
				var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng()); 
				$("#message").empty();
				var HTMLoutput = $("#message").append(theHTML);
				$('#message').corner("round 8px");
				addLightbox('#message a.lightbox');
				HTMLoutput
				.fadeIn()
				.css({ top:markerOffset.y, left:markerOffset.x }); 
				
				map.panTo(marker.getLatLng());
				
			}
		);
		this.addOverlay(marker);
}


Overlay.prototype.addLightbox = function (theID) {
	$(theID).lightBox({fixedNavigation:false,
	overlayBgColor: '#FFF',
	overlayOpacity: 0.6,
	imageLoading: '/js/images/lightbox-ico-loading.gif',
	imageBtnClose: '/js/images/lightbox-btn-close.gif',
	containerResizeSpeed: 350
	});
}

Overlay.prototype.loadOverlays = function()
{
	alert('override this method');
}

