var showAssets = false;
var pictures = [];
var enlargeDiv = document.getElementById("enlargeDiv");
var closeDiv = document.getElementById("closeDiv");

function enlargePic(src,picId) {
    var container = map.getContainer();
    enlargeDiv.style.visibility = "visible";
	closeDiv.style.visibility = "visible";
	
	enlargeDiv.style.height = container.style.height;
	//enlargeDiv.style.width = container.style.width;
  	var height = container.style.height;
   	enlargeDiv.innerHTML = '<table height=100% width=100% cellspacing=0 cellpadding=0><tr><td valign=center align=center style="text-align:center; vertical-align:middle"><img src="'+src+'" class="img'+height+'h img'+container.style.width+'w" style="max-height:'+height+';max-width:'+container.style.width+';"></td></tr></table>';
      

	document.getElementById("background-div").style.display = "block";
     
   }
   
function hidePicture() {
  	enlargeDiv.style.visibility = "hidden";
	closeDiv.style.visibility = "hidden";
	
	document.getElementById("background-div").style.display = "none";
}

function addPicture(title, lat, lon, thumb, full, doEnlarge) {
	var addToSlideshow = true;
	var pt = new GLatLng(lat,lon);
	var marker = new GMarker(pt, {icon:pictureIcon, zIndexProcess: function() { return 1;}});
	

	if(doEnlarge) {
		GEvent.addListener(marker, "click", function() {
			enlargePic(full);
		});
	}
         
	GEvent.addListener(marker, "mouseover", function() {
		showThumbnailDiv(pt,thumb,map);
	});
	GEvent.addListener(marker, "mouseout", function() {
		removeDivOnMap(map, picDiv);
	});
	
	pictures.push({"marker":marker,"title":title, "thumb":thumb, "full":full});

	map.addOverlay(marker);
	pictureMarkers.push(marker);
	if(addToSlideshow) {
	//	slideshowMap.addOverlay(marker);
	}
	
	return marker;
}

function showAssetPreview(marker, title) {
	
}

function addWaypoint(title, lat, lon, iconName) {
	var pt = new GLatLng(lat,lon);
	var marker = new GMarker(pt, {icon:getIconByName(iconName)});
	
	GEvent.addListener(marker, "mouseover", function() {
         showAssetPreview(marker, title);
    });

	GEvent.addListener(marker, "mouseout", function() {
         removeDivOnMap();
    });


	map.addOverlay(marker);
	waypointMarkers.push(marker);
	return marker;
}


function showImage(index) {
	
	resizeImage(document.getElementById("slideshowPic"+index), 294);
	
	if(pictures[index] && currentView != "map") showThumbnailDiv(pictures[index]['marker'].getPoint(),pictures[index]['thumb'],map);
	
	
}



// resizes img so that the smallest dimension is minDim
function resizeImage(img,minDim) {
	if(img == null) return;
	
	if(img.width > img.height) {
		// set max-height
		img.style.maxHeight = minDim + "px";
	} else {
		// set max-width
		img.style.maxWidth = minDim + "px";
	}
}

