var meImgWidth = 200;
var meImgHeight = 200;
var meImgLocation = "images/";
var meImgExt = ".jpg";
var meImgHoverStr = "_hover";

// each id attribute of a me image as well as the image file itself should
// contain the same prefix name
var meImgObjs = { "humanMe": null, "softEngMe": null, 
	"academicMe": null, "yogiMe": null };

var meHoverImgObjs = new Array();

var yogaMap = null;
var zoomLevel = 4;

function initializeHome() 
{
	// preload images
    loadMeImages();

	// register handlers    
	for( var meName in meImgObjs )
	{
		if( document.getElementById(meName) )
		{
			document.getElementById(meName).onmouseover = meMouseOver;
			document.getElementById(meName).onmouseout = meMouseOut;
		}
	}
	

}

// preloads all "me" images into javascript image objects
function loadMeImages() 
{
	for( var meName in meImgObjs )
	{
		 meImgObjs[meName] = new Image(meImgWidth, meImgHeight);
		 meImgObjs[meName].src = meImgLocation + meName + meImgExt; 
		 
		 meHoverImgObjs[meName] = new Image(meImgWidth, meImgHeight);
		 meHoverImgObjs[meName].src = meImgLocation + meName + meImgHoverStr + meImgExt;  
	}	
}

function meMouseOver() 
{
	if (document.images)
   	{
      	this.src = meHoverImgObjs[this.id].src;
    }
}

function meMouseOut() 
{
   if (document.images)
    {
      	this.src = meImgObjs[this.id].src;
    }
}

function getMap()
{
	yogaMap = new VEMap('yogaMap');
	yogaMap.LoadMap();
	yogaMap.SetZoomLevel(zoomLevel);
	yogaMap.AttachEvent("onclick", getLatLong);
	placeStudios();
	//findStudios();
}

function getLatLong(e)
{
    var x = e.mapX;
	var y = e.mapY;
	var latlong = null;
	var pixel = new VEPixel(x, y);
	latlong = yogaMap.PixelToLatLong(pixel);
	Alert("latitude = " + latlong.Latitude + "; longitude = " + latlong.Longitude);
}

function findStudios()
{
	yogaMap.Find("The Providence Institute", "3400 E. Speedway, Tucson, AZ", 
				 null, null, 0, 1, true, true, true, true, null);
}

function placeStudios()
{
	providenceInst = new VEShape(VEShapeType.Pushpin, 
								 new VELatLong(32.236762220176786, 
											   -110.92021107673645));            
	providenceInst.SetTitle("<a href='http://www.providenceinstitute.com'>The Providence Institute</a>");
	providenceInst.SetDescription("Tucson, AZ <br/> Great intermediate-level hatha yoga class by Jim Lipson on Wednesday evenings.");
	providenceInst.SetCustomIcon("<img src='images/lotus.jpg' class='yogaStudio' />");
	yogaMap.AddShape(providenceInst);
}

function Alert(Text)
{
	document.getElementById("divMessage").innerText = Text;
}
