/*


*/
var popWin = 0;
var photoMarkerArray = new Array();
var videoMarkerArray = new Array();

var photoIcon = new GIcon();
photoIcon.iconSize = new GSize(43,63);
photoIcon.iconAnchor = new GPoint(21,63);
photoIcon.image = "/tripplanner/i/mapImages/icons/photos.gif";

var videoIcon = new GIcon();
videoIcon.iconSize = new GSize(43,63);
videoIcon.iconAnchor = new GPoint(21,63);
videoIcon.image = "/tripplanner/i/mapImages/icons/video.gif";

var photoURL = "/userPhotos/";


function addPhotoToMap(src,latitude,longitude,title,pID)
{
	var marker = new GMarker(new GLatLng(latitude,longitude),{icon:photoIcon});

	marker.id = pID;
	marker.title = title;
	
	photoMarkerArray.push(marker);
	
	//when they click the marker, open the editForm
	GEvent.addListener(marker, "click",function()
	{
		var htmlText = '<div class="infoBox"><img src="'+photoURL+'thumbs/'+src+'"><br />'+title+'<br /><a href="javascript:popPhotoDetails('+pID+');">view details</a><br /><a href="http://northernforestcanoetrail.org/PlanaTrip-2/Photo-Submission-71">submit your photos</a></div>';
		map.openInfoWindowHtml(this.getPoint(),htmlText);
	});
	
	map.addOverlay(marker);
	marker.hide();
}

function popPhotoDetails(id)
{
	var top = 10;
	var left = top;
	var width = 770;
	var height = 475;
	if(popWin)
	{
		if(!popWin.closed) popWin.close();
	}
	
	popWin = open('http://northernforestcanoetrail.org/popPhoto.cfm?id='+id, 'popWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top);
}

function popVideoDetails(id)
{
	var top = 10;
	var left = top;
	var width = 550;
	var height = 450;
	if(popWin)
	{
		if(!popWin.closed) popWin.close();
	}
	
	popWin = open('http://northernforestcanoetrail.org/popVideo.cfm?vID='+id, 'popWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top);
}

/*
event handler for onclick service checkboxes, from within the control panel

*/
var photos = false;
var videos = false;

function togglePhotos()
{
	closeInfoWindows();
	if(!photos)//they are off, turn them on
	{
		for(var k = 0;k < photoMarkerArray.length;k++)
		{
			photoMarkerArray[k].show();
		}
		imageRollOpacity(document.getElementById('btPhotos'));
	}
	else
	{
		for(var k = 0;k < photoMarkerArray.length;k++)
		{
			photoMarkerArray[k].hide();
		}
		imageOutOpacity(document.getElementById('btPhotos'));
	}
	
	
	photos = !photos;
}

function toggleVideos()
{
	closeInfoWindows();
	if(!videos)//they are off, turn them on
	{
		for(var k = 0;k < videoMarkerArray.length;k++)
		{
			videoMarkerArray[k].show();
		}
		imageRollOpacity(document.getElementById('btVideos'));
	}
	else
	{
		for(var k = 0;k < videoMarkerArray.length;k++)
		{
			videoMarkerArray[k].hide();
		}
		imageOutOpacity(document.getElementById('btVideos'));
	}
	
	videos = !videos;
	
}

function addVideoToMap(embedScript,latitude,longitude,title,vID)
{
	var marker = new GMarker(new GLatLng(latitude,longitude),{icon:videoIcon});

	marker.id = vID;
	marker.title = title;
	
	videoMarkerArray.push(marker);
	
	var infoHTML = '<div class="infoBox">'+embedScript+'<p>'+title+'<br><a href="javascript:popVideoDetails('+vID+')">view details</a><br /><a href="http://northernforestcanoetrail.org/PlanaTrip-2/Video-Submission-72">submit your videos</a></div>';
	
	//when they click the marker, open the editForm
	GEvent.addListener(marker, "click",function()
	{
		//var htmlText = embedScript;
		map.openInfoWindowHtml(this.getPoint(),infoHTML);
	});
	
	map.addOverlay(marker);
	marker.hide();
}

