/*
Java script to run the map roll-overs and galleries
*/

function selectMap(id, mapSrc)
{
  var element = document.getElementById(id);
  if (element != null)
  {
    element.src = mapSrc;
  }
}

function MM_preloadImages()
{ //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    if (a=MM_preloadImages.arguments){
        var i,j=d.MM_p.length; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}}
}

bigImage_array = null;
/*
for the galleries. Set up one of these:
bigImage_array = [
	'assets/1_big.jpg',
	'assets/2_big.jpg',
	'assets/3_big.jpg',
	'assets/4_big.jpg'
];
*/

function preloadGallery ()
{
  if (bigImage_array != null)
  {
    var max = bigImage_array.length;
    for (var i = 1; i<max; ++i)
    { // assume that the first image is already showing in the gallery
      MM_preloadImages(bigImage_array[i]);
    }
  }
}

function setGalleryImage (index, width, height, alt)
{
	var element = document.getElementById("galleryBigImage");
    if (element)
    {
        element.src = bigImage_array[index];
        element.width = width;
        element.height = height;
        element.alt = alt;
        element.title = alt;
    }
}

// Empty Variables to hold the mouse position and the window size
var mousePos = null;
var winSize = null;
// Set events to catch mouse position and window size
document.onmousemove = mouseMove;
window.onresize = windowResize;
// The mouseMove and mouseCoords function track the mouse position for us
function mouseMove (ev) {
	ev = ev || window.event;
	mousePos = mouseCoords(ev);
}
function mouseCoords (ev)
{
	if(ev.pageX || ev.pageY){
		return {x:ev.pageX, y:ev.pageY};
	}
	return {
		x:ev.clientX+(document.body.scrollLeft - document.body.clientLeft),
		y:ev.clientY+(document.body.scrollTop  - document.body.clientTop)
	};
}
// The windowResize function keeps track of the window size for us
function windowResize ()
{
	winSize = {
		x:(document.body.clientWidth) ? document.body.clientWidth : window.innerWidth,
		y:(document.body.clientHeight) ? document.body.clientHeight : window.innerHeight
	}
}
// This function shows our tool-tips
function  showTip (placeName, otherDetails)
{
	moveTip();
	var upper = document.getElementById("tooltipUpper");
	var lower = document.getElementById("tooltipLower");
	upper.innerHTML = placeName;
	if (otherDetails != null) {
		lower.innerHTML = otherDetails;
		lower.style.display = "block";
	} else {
		lower.style.display = "none";
	}
	var tip = document.getElementById("tooltip");
	tip.style.display = "block";
}
// This function moves the tool-tips when our mouse moves
function moveTip ()
{
	var tip = document.getElementById("tooltip");
	var newTop = mousePos.y+25;
	var newLeft = mousePos.x+5;
	if (newTop<0) {
		newTop = mousePos.y + 20;
	}
	if (newLeft<0) {
		newLeft = 0;
	}
	if (mousePos.x+tip.clientWidth >= winSize.x - 5) {
		newLeft = winSize.x - (tip.clientWidth+5);
	}
	tip.style.top = newTop+"px";
	tip.style.left = newLeft+"px";
}
// This function hides the tool-tips
function hideTip ()
{
	var tip = document.getElementById("tooltip");
	tip.style.display = "none";
}
// This is what runs when the page loads to set everything up
window.onload = function ()
{
   windowResize();
   if (bigImage_array != null)
   {
       preloadGallery ()
   }
}

