// Copyright (C) 2003-2006 AvantLogic Corporation: http://www.mapsalive.com
// FlashObject is (c) 2005 Geoff Stearns: http://blog.deconcept.com/flashobject
// and is released under the MIT License: http://www.opensource.org/licenses/mit-license.php

if (Array.prototype.push == null)
{ 
	Array.prototype.push = function(item) { this[this.length] = item; return this.length; }
}

if (typeof com == "undefined") var com = new Object();
if (typeof com.mapsalive == "undefined") com.mapsalive = new Object();

com.mapsalive.swfPath = isEditor ? "../Tour/" + appVersion + "/" : "";
com.mapsalive.init = false;
com.mapsalive.vid = 0;
com.mapsalive.tid = 1;
com.mapsalive.guid = (new Date()).getTime()+""+Math.floor((Math.random()*8999)+1000);
com.mapsalive.ie = ((navigator.appVersion.indexOf("MSIE") != -1) && (navigator.userAgent.search(/Opera/) == -1)) ? true : false;

com.mapsalive.FlashObject = function()
{
}

com.mapsalive.FlashObject.prototype.init = function(swf, id, mfn, pid)
{
   this.params = new Object();
   this.variables = new Object();
   this.attributes = new Array();
   this.setAttribute('id', id); 
   this.setAttribute('fsid', 'fs'+id); 
   this.setAttribute('mapFileName',mfn,'');
   this.addParam('bgcolor', '');
   this.addParam('quality', 'high');
   this.addParam("swliveconnect","true");
   this.addParam("wmode","transparent");
   this.addVariable("ie",com.mapsalive.ie);
   this.addVariable("swf", swf); 
   this.addVariable("guid",com.mapsalive.guid);
   this.addVariable("clipid",id);
   this.addVariable("pageid",pid);
   this.addVariable("defaultviewid",com.mapsalive.dvid);
   this.addVariable("viewid",com.mapsalive.vid);
   this.addVariable("themeid",com.mapsalive.tid);
   com.mapsalive.flashObject = this;
}

com.mapsalive.FlashObject.prototype.setAttribute = function(name, value, dvalue)
{
	this.attributes[name] = (value != null) ? value : dvalue;
}

com.mapsalive.FlashObject.prototype.getAttribute = function(name)
{
	return this.attributes[name];
}

com.mapsalive.FlashObject.prototype.getAttributes = function()
{
	return this.attributes;
}

com.mapsalive.FlashObject.prototype.addParam = function(name, value, dvalue)
{
	this.params[name] = (value != null) ? value : dvalue;
}

com.mapsalive.FlashObject.prototype.getParams = function()
{
	return this.params;
}

com.mapsalive.FlashObject.prototype.getParam = function(name)
{
	return this.params[name];
}

com.mapsalive.FlashObject.prototype.addVariable = function(name, value, dvalue)
{
	this.variables[name] = (value != null) ? value : dvalue;
}

com.mapsalive.FlashObject.prototype.getVariable = function(name)
{
	return this.variables[name];
}

com.mapsalive.FlashObject.prototype.getVariables = function()
{
	return this.variables;
}

com.mapsalive.FlashObject.prototype.getParamTags = function()
{
   var paramTags = ""; var key; var params = this.getParams();
   for(key in params) {
        paramTags += '<param name="' + key + '" value="' + params[key] + '" />';
    }
   return paramTags;
}

com.mapsalive.FlashObject.prototype.getVariablePairs = function()
{
	var variablePairs = new Array();
	var key;
	var variables = this.getVariables();
	for(key in variables){
		variablePairs.push(key +"="+ variables[key]);
	}
	return variablePairs;
}

com.mapsalive.FlashObject.prototype.getHTML = function()
{
	var movie = this.getAttribute('movie');
	var id = this.getAttribute('id');
	var fsid = this.getAttribute('fsid');
	var mapFileName = this.getAttribute('mapFileName');
	var pageid = this.getVariable('pageid');
	var themeid = this.getVariable('themeid');
	var dimensions = com.mapsalive.ss;
	var stageW = dimensions[0];
	var stageH = dimensions[1] + (isEditor ? 24 : 0);
    var flashHTML = "";
    var playerVersion = com.mapsalive.getPlayerVersion();
    if (playerVersion.major < 7)
    {
		if (!isEditor)
		{
		    document.getElementById('map').style.backgroundImage = "url("+mapFileName+")";
 		    var msg = document.getElementById('flashMsg');
 		    msg.style.visibility = "visible";
		}
		else
		{
		    flashHTML += this.flashPlayerMissingMessage();
		}
	}
    else if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) // netscape plugin architecture
    {
        flashHTML += '<embed type="application/x-shockwave-flash" src="'+ movie +'"';
		flashHTML += ' width="'+ stageW +'" height="'+ stageH +'"';
		flashHTML += ' id="'+ fsid + '" name="'+ fsid +'"';
		var params = this.getParams();
        for(var key in params){ flashHTML += ' '+ key +'="'+ params[key] +'"'; }
		pairs = this.getVariablePairs().join("&");
        if (pairs.length > 0){ flashHTML += ' flashvars="'+ pairs +'"'; }
        flashHTML += '></embed>';
    } 
    else // PC IE
    {
	 	flashHTML += '<script type="text/vbscript" language="VBScript">';
	 	flashHTML += 'Sub ' + fsid + '_FSCommand(ByVal command, ByVal args)';
	 	flashHTML += 'call ' + id + '.fs(command, args)';
	 	flashHTML += 'end sub';
	 	flashHTML += '</script>';
		flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'; 
		flashHTML += ' width="'+ stageW +'" height="'+ stageH +'"';
		flashHTML += ' id="'+ fsid +'">';
		flashHTML += '<param name="movie" value="' + movie + '" />';
		var tags = this.getParamTags();
		if(tags.length > 0){ flashHTML += tags; }
		var pairs = this.getVariablePairs().join("&");
		if(pairs.length > 0){ flashHTML += '<param name="flashvars" value="'+ pairs +'" />'; }
		flashHTML += '</object>';
    }
    return flashHTML;
}

com.mapsalive.FlashObject.prototype.write = function(elementId)
{
	if (elementId)
		document.getElementById(elementId).innerHTML = this.getHTML();
	else
		document.write(this.getHTML());
}

com.mapsalive.FlashObject.prototype.flashPlayerMissingMessage = function()
{
    var msg = "";
    var flashImgSrc;
    var msgText = "";
    flashImgSrc = "../Runtime/get_flash_player.gif";
    msgText += "You need Flash 7 or above to edit this map.";
    msgText += "  Click to install now.";
    msg += "<style type='text/css'>";
    msg += ".flashMsg {background-color:#fffaad;border:1px solid #000055;color:#000055;font-size:11px;padding:4px;text-align:left;width:220px;}";
    msg += ".flashImg {padding:12px 0px 12px; 0px;text-align:center;}";
    msg += "</style>";
    msg += "<div class='flashMsg'>";
    msg += msgText;
    msg += "<div class='flashImg'>";
    msg += "<a href='http://macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' target='_blank'>";
    msg += "<img src='";
    msg += flashImgSrc;
    msg += "' border='0' alt='Get the latest Adobe Flash Player' />";
    msg += "</a></div>After you have installed Flash, close the Adobe window and refresh this page to view the map.</div>";
	return msg;
}

com.mapsalive.FlashObject.prototype.goToPage = function(url)
{
	if (url == null)
		return;
	var pathname = location.pathname;
	var pathsegs = pathname.split('/');
	var pathend = pathsegs[pathsegs.length- 1];
	if (pathend == url)
		return;
	location = url;
}

com.mapsalive.FlashObject.prototype.linkToUrl = function(url)
{
	if (url == null)
		return;
	var popup = url.substring(0,1) == "1";
	url = url.substring(1);
	if (popup)
	{
		var wnd = window.open(url, "_blank");
		if (wnd == null)
		{
			if (confirm("A popup blocker prevented the following page from being opened in a new window:\n\n" + url + "\n\nPress OK to open the page in the current window."))
				location = url;
		}
	}
	else
		location = url;
}

com.mapsalive.FlashObject.prototype.markerCoordsChanged = function(coords)
{
	document.getElementById(markerThumbsId).value = coords;
	maChangeDetected();
}

com.mapsalive.FlashObject.prototype.markerSelected = function (id)
{
	if (isEditor)
		maOnMarkerThumbSelected(id);
}

com.mapsalive.FlashObject.prototype.markerDeselected = function (id)
{
}

com.mapsalive.FlashObject.prototype.viewChanged = function (id,x,y,w,h)
{
    var vid = parseInt(id);
    if (vid == 0)
		return;
 	var isPopup = document.getElementById(com.mapsalive.uaIs('safari') ? 'maPopupSafari' : 'maPopup');
	if ((!isPopup || popupLocationFixed) && vid == com.mapsalive.vid && com.mapsalive.init)
		return;
	com.mapsalive.init = true;   
    com.mapsalive.vid = vid;
    com.mapsalive.setViewTextAndImages(x,y,w,h);
}

com.mapsalive.FlashObject.prototype.markerMouseOut = function ()
{
	var p = document.getElementById(com.mapsalive.uaIs('safari') ? 'maPopupSafari' : 'maPopup'); 
	if (p && (!popupLocationFixed || com.mapsalive.uaIs('safari')))
	{
	    com.mapsalive.hidePopup();
	    var e = document.getElementById("image1");
	    if (e)
			e.src = "0023_" + appVersion + ".gif";
	}
}

com.mapsalive.FlashObject.prototype.fs = function (command, argstring)
{
	var args = argstring.split('\2');
	switch(command)
	{
		case "markerCoordsChanged":
			this.markerCoordsChanged(args[0]);
		  break;
		case "markerSelected":
			this.markerSelected(args[0]);
		  break;
		case "markerDeselected":
			this.markerDeselected(args[0]);
		  break;
		case "viewChanged":
			this.viewChanged(args[0],args[1],args[2],args[3],args[4]);
		  break;
		case "markerMouseOut":
			this.markerMouseOut();
		  break;
		case "js":
			var js = args[0];
			try
			{
				com.mapsalive.hideTooltip();
				eval(js);
			}
			catch(error)
			{
				js = js.substring(11, js.length - 8);
				alert('An error occurred executing:\n\n' +  js + '\n\n' + error.message);
			}
		  break;
	}
}

com.mapsalive.FlashObject.prototype.invokeGateway = function(method,args)
{
	var viewerId = this.getAttribute("id");
	var gatewayTagId = viewerId + "Gateway";
	var newGatewayTag = document.createElement("div");
	newGatewayTag.innerHTML =
		"<embed style='position:absolute' src='" +
		com.mapsalive.swfPath +
		"0002_" +
		appVersion +
		".swf' id='" +
		gatewayTagId +
		"' FlashVars='movie=" +
		viewerId +
		com.mapsalive.guid +
		"&method=" +
		method +
		"&args=" +
		args.join(',') +
		"' width='1' height='1' wmode='transparent' type='application/x-shockwave-flash'></embed>";
	var parentTagId;
	if (viewerId == "mapViewer")
		parentTagId = "layout";
	else if (viewerId == "mapEditor")
		parentTagId = "GatewayParent";
	else
	{
		alert("Unknown viewer Id " + viewerId);
		return;
	}
	var previousGatewayTag = document.getElementById(gatewayTagId);
	var parent = document.getElementById(parentTagId);
	if (previousGatewayTag)
		parent.replaceChild(newGatewayTag.firstChild, previousGatewayTag);
	else
		parent.insertBefore(newGatewayTag.firstChild, parent.firstChild);
}

com.mapsalive.getPlayerVersion = function()
{
	var playerVersion = new com.mapsalive.PlayerVersion([0,0,0]);
	if (navigator.plugins && navigator.mimeTypes.length)
	{
		var plugin = navigator.plugins["Shockwave Flash"];
		if (plugin && plugin.description)
		{
			playerVersion = new com.mapsalive.PlayerVersion(plugin.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}
	else
	{
		// do minor version lookup in IE, but avoid fp6 crashing issues
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		try
		{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}
		catch(e)
		{
			try
			{
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				playerVersion = new com.mapsalive.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // throws if player version < 6.0.47
			}
			catch(e)
			{
				if (playerVersion.major == 6)
				{
					return playerVersion;
				}
			}
			try
			{
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			}
			catch(e)
			{}
		}
		if (axo != null)
		{
			playerVersion = new com.mapsalive.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return playerVersion;
}

com.mapsalive.PlayerVersion = function(arrVersion)
{
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}

com.mapsalive.selectMarkerAndShowView = function(id)
{
    if (typeof mapViewer == "undefined")
    {
		com.mapsalive.vid = id;
		com.mapsalive.setViewTextAndImages(0,0,0,0);
    }
    else
    {
		mapViewer.selectMarkerAndShowView(id);
    }
}

com.mapsalive.setViewTextAndImages = function(x,y,w,h)
{
	var isPopup = document.getElementById(com.mapsalive.uaIs('safari') ? 'maPopupSafari' : 'maPopup');
	if (isPopup && typeof popupInitialized == "undefined" && (!popupLocationFixed || com.mapsalive.uaIs('safari')))
	{
		// Ignore initial call from movie so that popup does not appear when page loads.
		popupInitialized = true;
		return;
	}
	    
    for (var i in com.mapsalive.txe)
    {
	    var textId = com.mapsalive.txe[i];
	    var utx = unescape(com.mapsalive.tp[com.mapsalive.tpi[textId + '_' + com.mapsalive.vid + '_' + com.mapsalive.tid]]);
	    if (isPopup && com.mapsalive.uaIs('safari'))
			textId += "Safari";
        var e = document.getElementById(textId);
	    if (e != null && e.innerHTML != utx)
 		    e.innerHTML=utx;
    }
    
	var id = "image1";
	var data = com.mapsalive.ip[com.mapsalive.ipi[id + '_' + com.mapsalive.vid + '_' + com.mapsalive.tid]].split(',');
	var src = data[0];
	var iw = data[1];
	var ih = data[2];
		
	if (isPopup && com.mapsalive.uaIs('safari')) 
	    id = "image1Safari";
	    
	var e = document.getElementById(id);
	if (e != null && e.innerHTML != src)
	{
        // A Safari bug prevents images from resizing when dynamically setting the src unless both the 
        // width and height of the new image are different from the current image.  To get around this we will
        // first set the src to a 1px transparent gif before setting the new src.
        if (navigator.userAgent.toLowerCase().indexOf("safari") != -1)
            e.src="0021_" + appVersion + ".gif";
        // Set the image src    
		e.src=src;
	}
	
	// If this page has a dropdown list, keep the selected item in the list in sync with the selected view.
	var dropdownList = document.getElementById('slideDropdown');
	if (dropdownList)
	{
	    for (var option = 0; dropdownList.options.length; option++)
	    {
	        if (dropdownList.options[option].value == com.mapsalive.vid)
	        {
	            dropdownList.options[option].selected = true;
	            dropdownList.selectedIndex = dropdownList[option].index;
	            break;
	        }
	    } 
	}
	// If this page is showing slide names in the left menu, deselect the currently selected slide name 
	// and select the slide name corresponding to the the selected view.
	var slideNamesInMenu = document.getElementById('slideNamesInMenu');
	if (slideNamesInMenu)
	{
	    var newSelectedSlideName = document.getElementById(com.mapsalive.vid);
	    if (newSelectedSlideName)
	    {
	        var oldSelectedSlideName = document.getElementById(selectedSlideName);
	        if (oldSelectedSlideName) 
	            oldSelectedSlideName.className = '';
	        newSelectedSlideName.className = "currentSlide";
	        selectedSlideName = com.mapsalive.vid; // save the new selected slide for next time
	    }
	}
	
	if (isPopup) 
	{
	    var adjustedPopupWidth = popupWidth;
	    var adjustedPopupHeight = popupHeight;
	    var s = isPopup.style;
	    var layoutType = "H";
	    
	    var borderWidth = popupBorderWidth;
	    var popWidth = popupWidth;
	    var popHeight = popupHeight;
	    
	    if (navigator.userAgent.toLowerCase().indexOf("safari") != -1)
	    {
	        borderWidth = 0;
	        popWidth = popupWidthSafari;
	        popHeight = popupHeightSafari;
	        adjustedPopupWidth = popupWidthSafari;
	        adjustedPopupHeight = popupHeightSafari;
	    }
//	    alert("width = " + popWidth + ", height = " + popHeight + ", borderWidth = " + borderWidth);
	    	    
	    switch(popupLayout)
	    {
		    // Image only layout displays the image at its actual size
		    case "HII":
		        if (e != null)
		        {
	                adjustedPopupWidth = parseInt(iw) + parseInt(borderWidth * 2) + parseInt(layoutMarginLeft) + parseInt(layoutMarginRight);
	                adjustedPopupHeight = parseInt(ih) + parseInt(borderWidth * 2) + parseInt(layoutMarginTop) + parseInt(layoutMarginBottom);
		        }
		        layoutType = "I";
		        break;
		    // Horizontal layouts - adjust the height of the popup to remove any white space below the image
		    case "HIITT":
		    case "HTTII":
		        var imageHeightDifference = imageAreaHeight - ih;
		        adjustedPopupHeight = popHeight - imageHeightDifference;
		        layoutType = "H";
		        break;
		    // Vertical layouts - adjust the width of the popup to remove any white space between image and text
		    case "VIITT":
		    case "VTTII":
		        var imageWidthDifference = imageAreaWidth - iw;
		        adjustedPopupWidth = popWidth - imageWidthDifference;
		        layoutType = "V";
		        break;
		}

//        alert("adjWidth = " + adjustedPopupWidth + ", adjHeight = " + adjustedPopupHeight);
        if (!popupLocationFixed)
        {
            // Dynamically set the popup location based on its size and the marker position
	        var l = popupLocation(x, y, w, h, adjustedPopupWidth, adjustedPopupHeight, borderWidth);
		    // Set the position of the popup
		    s.left = l.x + 'px';
		    s.top = l.y + 'px';  
	    }
	    // Now set the popup visble;
	    s.visibility = "visible";
	    
	    // Set the width and height of the popup and set the image width and height to its actual size
        s.width = adjustedPopupWidth + 'px';
        s.height = adjustedPopupHeight + 'px';
        var imageContainer = document.getElementById("imagecontainer");
        if (imageContainer)
        { 
            if (layoutType == "H")
                imageContainer.style.height = ih + 'px';
            if (layoutType == "V")
                imageContainer.style.width = iw + 'px';
        }
	}
}

function popupLocation(x,y,w,h,adjWidth,adjHeight,borderWidth)
{
	var markerOffset = 10;
	var markerOffsetx = Math.round(w/2) + markerOffset;
	var markerOffsety = Math.round(h/2) + markerOffset;
	
	// Allow space for the border to fit within tour page because Firefox does not take into
	// account the border widths when positioning an element.
	var borderAllowance = borderWidth * 2;  
	
	// Get map offset from top left corner of tour
	var map = document.getElementById('map');
    var pt = mapOffset(map);
    
	// If this popup has no marker, display the slide near the map's upper left corner.   
    if (parseInt(x) < 0)
		x = 16;
	if (parseInt(y) < 0)
		y = 16;
    
	// Add the map offset to the marker position relative to the map to get the location of the 
	// center of the marker relative to the tour page.
	var markerLeft = parseInt(pt.x) + parseInt(x);
	var markerTop = parseInt(pt.y) + parseInt(y);
	
	// Calculate the space available on each side of the marker position within the tour page.
	var spaceLeft = markerLeft - borderAllowance - markerOffsetx;
	var spaceTop = markerTop - borderAllowance - markerOffsety;
	var spaceRight = tourWidth - markerLeft - borderAllowance - markerOffsetx;
	var spaceBelow = tourHeight - markerTop;
	var spaceBottom = tourHeight - markerTop - borderAllowance - markerOffsety;
	
	var l = new Object;
	
	// First, see if popup will fit to the right of the marker
	if (spaceRight > adjWidth) {
	    if (spaceBelow >= adjHeight) {
            // popup will fit in place
	        l.x = markerLeft + markerOffsetx;
	        l.y = markerTop; 
	        return l;
	    } 
	    else if (tourHeight > adjHeight) {
            // popup will fit if we move it up
	        l.x = markerLeft + markerOffsetx;
	        l.y = tourHeight - adjHeight;
	        return l;
	    }
	}
	// See if the popup will fit to left of marker
	if (spaceLeft > adjWidth) {
        if (spaceBelow >= adjHeight) {
	        // popup will fit in place on the left
	        l.x = markerLeft - adjWidth - markerOffsetx;
	        l.y = markerTop;
	        return l;
	    }
	    else if (tourHeight > adjHeight) {
	        // popup will fit to the left if we move it up
	        l.x = markerLeft - adjWidth - markerOffsetx;
	        l.y = tourHeight - adjHeight;
	        return l;
	    }
	}
	// See if the popup will fit below the marker
	if ((spaceBottom > adjHeight) && (tourWidth > adjWidth)) {
		l.x = tourWidth - adjWidth;
	    l.y = markerTop + markerOffsety;
	    return l;
	}
	// See if the popup will fit above the marker
	if ((spaceTop > adjHeight) && (tourWidth > adjWidth)) {
		l.x = tourWidth - adjWidth;
	    l.y = spaceTop - adjHeight;
	    return l;
    }
    // Popup does not fit in tour; move it below marker and to the left
    l.x = tourWidth - adjWidth;
    l.y = markerTop + markerOffsety;
    return l;
}

function mapOffset(e)
{
	var left = 0;
	var top = 0;
	while (e && (e.id != "tourpage"))
	{
		left += e.offsetLeft;
		top += e.offsetTop;
		e = e.offsetParent;
	}
	var pt = new Object();
	pt.x = left;
	pt.y = top;
	return pt;
}

com.mapsalive.uaIs = function(ua) 
{
    return navigator.userAgent.toLowerCase().indexOf(ua) != -1;
}

com.mapsalive.startLoad = function(dvid,dtid)
{	
	com.mapsalive.dvid = dvid.toString();
	com.mapsalive.vid = dvid;
	com.mapsalive.tid = dtid;
}

com.mapsalive.MapViewer = function(swf, id, mfn, pid){
	this.init(swf, id, mfn, pid);
	this.setAttribute('movie', com.mapsalive.swfPath + "0001_" + appVersion + ".swf");
	this.addVariable("mappath", "");
}

com.mapsalive.MapViewer.prototype = com.mapsalive.FlashObject.prototype;

com.mapsalive.MapViewer.prototype.selectMarkerAndShowView = function (markerid) {
	this.invokeGateway("selectMarkerAndShowView",[markerid]);
}

com.mapsalive.MapEditor = function(swf, id){
	this.init(swf, id, "", 0);
	this.setAttribute('movie', com.mapsalive.swfPath + "0000_" + appVersion + ".swf");
}

com.mapsalive.MapEditor.prototype = com.mapsalive.FlashObject.prototype;

com.mapsalive.MapEditor.prototype.selectMarker = function (markerid)
{
	this.invokeGateway("selectMarker",[markerid]);
}

com.mapsalive.markerLocation = function(tag, x, y)
{
	var left = 0;
	var top = 0;
	var e = document.getElementById('fs' + tag);
	while (e && (e.id != "tourpage"))
	{
		left += e.offsetLeft;
		top += e.offsetTop;
		e = e.offsetParent;
	}
	var l = new Object();
	l.x = left + x;
	l.y = top + y;
	return l;
}

com.mapsalive.showPopup = function(tag, x, y, w, title, args)
{
	w = w + 'px';
	var arg = args.split('~');
	var img = arg.length > 1 ? arg[0] : args;
	var content = arg.length > 1 ? arg[1] : '';
	var e = document.getElementById('maPopup');
	if (!e)	{alert(1); return false;}
	var s = e.style;
	if (!s) {alert(2); return false;}
	s.width = w;
	var l = com.mapsalive.markerLocation(tag, x, y);
	if (!com.mapsalive.popupMoved)
	{
		s.left = l.x + 'px';
		s.top = l.y + 'px';
	}
	e = document.getElementById('maPopupBody');
	if (!e || !e.style)	{alert(7); return false;}
	e.style.width = w;
	e = document.getElementById('maPopupTitle');
	if (!e) {alert(3); return false;}
	e.innerHTML = title;
	e = document.getElementById('text2');
	if (!e) {alert(4); return false;}
	e.innerHTML = content;
	e = document.getElementById('maPopupImage');
	if (!e) {alert(6); return false;}
	e.src = img;
	s.visibility = "visible";
	return true;
}

com.mapsalive.hidePopup = function()
{
	if (!popupLocationFixed || com.mapsalive.uaIs('safari'))
	{
	    var e = document.getElementById(com.mapsalive.uaIs('safari') ? 'maPopupSafari' : 'maPopup');
	    var s = e ? e.style : null;
	    if (!s)
		    return;
	    s.visibility= "hidden";
	}
}

com.mapsalive.showTooltip = function(tag, x, y, text)
{
    if (text.length == 0)
		return;
    var e = document.getElementById('maTooltip');
    if (!e)	return;
    var s = e.style;
    if (!s) return;
    var l = com.mapsalive.markerLocation(tag, x, y);
    l.x += 10;
    s.left = l.x + 'px';
    s.top = l.y + 'px';
    var t = document.getElementById('maTooltipText');
    if (!t) return;
    t.innerHTML = text;
    s.visibility = "visible";
}

com.mapsalive.hideTooltip = function()
{
	var e = document.getElementById('maTooltip');
	var s = e ? e.style : null;
	if (!s) return;
	s.visibility= "hidden";
}
