//<![CDATA[

function gmload ()
{
	mode = 6;

	if (setUpSystem ())
	{
		picId = document.getElementById ("panpic");
		picInfo = document.getElementById ("picinfo");

		if (maxdestwidth < 10)	maxdestwidth = 530;
		mapId.style.width = maxdestwidth + "px";
		picId.style.width = maxdestwidth + "px";
		picW = maxdestwidth;
		picH = 200;

		addDestMarkers ();

		GEvent.addListener (map, "moveend", function ()
		{
			addDestMarkers ();
		});

		GEvent.addListener (map, "zoomend", function (oldlevel, newlevel)
		{
			level = newlevel;
			var	bounds = map.getBounds ();
			var	southWest = bounds.getSouthWest ();
			var	northEast = bounds.getNorthEast ();
			var	lngSpan = northEast.lng () - southWest.lng ();
			latWidth = northEast.lat () - southWest.lat ();
			map.setCenter (currentPt, level);
			drawAngle ();
		});

		stmm = setTimeout ("startupmm()", 3500);
		isLoaded = true;
	}
}

function doMarker (mk, mkmode)
{
	gotPic = 0;
	picInfo.innerHTML = "";
	picId.style.background = "#def";
	var	ref = mk.getAttribute ("ref");
	var	ttl = mk.getAttribute ("title");
	var gmdest = mk.getAttribute ("gmdest");
	var sdest = mk.getAttribute ("subdest");
	var	contrib = mk.getAttribute ("contrib");
	var	author = mk.getAttribute ("author");
	var	isponsor = mk.getAttribute ("imgsponsor");
	var	maptype = parseInt (mk.getAttribute ("maptype"));
	var	metakw = mk.getAttribute ("metakw");
	var	metadesc = mk.getAttribute ("metadesc");
	var address = mk.getAttribute ("addr");
	var travel = mk.getAttribute ("travel");

	if (metadesc != "")
	{
		document.getElementById ('metadesc').content = metadesc;
	}

	if (metakw != "")
	{
		document.getElementById ('metakw').content = metakw;
	}

	if (mkmode == 1)
	{
		map.setMapType (mapTypes [maptype]);
	}

	var anchor = "";

	if (isponsor != "")
	{
		anchor += "Sponsored by: " + isponsor; // + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	}

	anchor += '<a href="http://' + lhost + '/' + ref + '/' + gmdest + '/' + mk.getAttribute ("title2") +
		'" target="_blank"><img src="/images/link2.gif" ' + 'border="0" title="Direct link to this page" ' +
		'alt="Direct link to this page"/></a>';

	var ttlh = ttl;

	if (contrib != "")
	{
		ttlh += " (picture by <a href=\"/showprofile.php?ref=" + author + "\" target=\"_blank\">" + contrib + "</a>)";
	}

	var picInfoTtl = '<table width="100%" cellspacing="0" cellpadding="0"><tr><td align="left"><b>' +
		ttlh + '</b></td><td align="right">' + anchor + '</td></tr></table>';

	var descText;
	var uDesc = mk.getAttribute ("userdesc");
	var mDesc = mk.getAttribute ("mdesc");
	var imgtags = mk.getAttribute ("imgtags");

	if (uDesc != "")
	{
		descText = '<h4>Photographer Description of ' + ttl + '</h4>' + uDesc;

		if (mDesc != '')
		{
			descText += '<h4>' + ttl + ' - Further Information</h4>';
		}
	}
	else
	{
		descText = '<h4>' + ttl + '</h4>';
	}

	descText += mDesc;

	if (address != "" && address != null)
	{
		descText += "<br/><br/><b>Address:</b><br/>" + address;
	}

	if (travel != "" && travel != null)
	{
		descText += "<br/><br/><b>Travel Directions and Getting There:</b><br/>" + travel;
	}

	document.getElementById ("mapdesc").innerHTML = descText;
//	document.getElementById ("imgtags").innerHTML = imgtags;

	var spontxt = "" + mk.getAttribute ("sponsor");
	var spFld = document.getElementById ("sponsorinfo");

	if (doAds && spontxt.length > 2)
	{
		spontxt = spontxt.replace (/&#039;/g, "'");
		spFld.innerHTML = spontxt;
		var spos = "" + mk.getAttribute ("sponpos");
		var bgcol = "" + mk.getAttribute ("sponbgcol");
		var txtcol = "" + mk.getAttribute ("spontxtcol");
		var txtsz = "" + mk.getAttribute ("spontxtsz");
		var bheight = "" + mk.getAttribute ("sponheight");
		var bgimg = "" + mk.getAttribute ("sponimgbg");

		spFld.style.overflow = "auto";

		if (bheight > 0)
		{
			spFld.style.height = bheight + "px";
		}

		if (spos != "") spFld.style.textAlign = spos;

		if (bgimg != "")
		{
			spFld.style.background = "url(" + bgimg + ") repeat";
		}

		if (bgcol != "")
		{
			spFld.style.backgroundColor = bgcol;
			spFld.style.borderBottom = "2px white solid";
			spFld.style.padding = "3px";
			spFld.style.fontSize = "9pt";
		}

		if (txtcol != "")
		{
			spFld.style.color = txtcol;
		}

		if (parseInt (txtsz) > 0)
		{
			spFld.style.fontSize = txtsz;
		}
	}
	else
	{
		document.getElementById ("sponsorinfo").innerHTML = "";
		spFld.style.backgroundColor = "#fff";
		spFld.style.border = "0";
		spFld.style.padding = "0";
		spFld.style.fontSize = "1pt";
		spFld.style.height = "0";
	}

	var	panimg = "" + mk.getAttribute ("panpic");

	if (panimg != "")
	{
		picId.innerHTML = "";
		xPos = 0;

		imgWidth  = parseInt (mk.getAttribute ("imgw"));
		imgHeight = parseInt (mk.getAttribute ("imgh"));
		imgNorth  = parseInt (mk.getAttribute ("imgn"));
		imgOpen   = parseInt (mk.getAttribute ("imgo"));

		xPos = parseInt (-(imgOpen - (picW / 2)));

		if (xPos < -imgWidth)
		{
			xPos += imgWidth;
		}
		else
		if (xPos > 0)
		{
			xPos -= imgWidth;
		}

		// Centralise the picture vertically

		if (picH > 0 && imgHeight > 0)
			yPos = (picH - imgHeight) / 2;
		else
			yPos = 0;

		currentImg = panimg;
		panimg = panimg.replace (" ", "%20");
		picId.style.background = 'url("/images/gm/' + gmdest + '/' + panimg + '")';
		picId.style.backgroundPosition = "" + xPos + "px " + yPos + "px";
		picId.style.height = "200px";
		gotPic = 1;
	}
	else
	{
		picId.innerHTML = noPicMsg;
		picId.style.height = "20px";
	}

	picInfo.innerHTML = picInfoTtl;
	var gmdest1 = gmdest;

	if (gmdest.length > 0)
	{
		gmdest1 = gmdest1.replace (" ", "%20");
	}

	drawAngle ();
}

_testMode = 1;
/*
if (_testMode == 1)
{
	foundParent = true;
}
else
{
	for (i = 0; i < window.parent.frames.length; i++)
	{
		var f = window.parent.frames [i];

		if (f.name == "panearthtour")
		{
			foundparent = true;
//			ifw = parseInt (f.width);
//			ifh = parseInt (f.height);
//alert ("W=" + ifw + " H=" + ifh);
			break;
		}
	}
}
*/
//if (!foundparent)
//{
//	alert ("The IFrame bounding box must be called 'panearthtour' - panoramic images cannot be shown until this is fixed");
//}
//else
//if (ifw < 600 || ifh < 500)
//{
//	alert ("The IFrame bounding box must be at least 600 (width) x 500 (height) - panoramic images cannot be shown until this is fixed");
//}
//else
{
	picId = document.getElementById ("panpic");
	mapId = document.getElementById (mapName);
	picPos = findPos (picId);
	mapPos = findPos (mapId);
	picW = parseInt (picId.style.width);
	stmm = setTimeout ("startupmm()", 3500);
}

//]]>
