// based on code from http://centricle.com/

/* -----( PREV/NEXT IMGMAP )------------------------------- */

// {{{ window.onload = function()
window.onload = function()
{
   if(document.addEventListener)
   {
      theTriggers = document.getElementsByTagName("area");
      for(var i = 0; i < theTriggers.length; i++)
      {
         theTriggers[i].addEventListener("mouseover", hilightLink, false);
         theTriggers[i].addEventListener("mouseout", removeHilight, false);
      } // end for(var i = 0; i < theTriggers.length; i++)
   } // end if(document.addEventListener)

   // for slideshow navigation
   //document.onkeyup = keys;
} // end window.onload = function()


// }}}
// {{{ function map_alt_to_name(alt)
function map_alt_to_name(alt)
{
   switch(alt)
   {
      case 'Previous': return('prev_photo');
      case 'Up'      : return('up_link');
      case 'Next'    : return('next_photo');
      default        : return(false);
   } // end switch(alt)
} // end function map_alt_to_name(alt)


// }}}
// {{{ function hilightLink()
function hilightLink()
{
   if(this.getAttribute("href"))
   {
      var link_name = map_alt_to_name(this.getAttribute('alt'));
      if(!link_name) { return(false); }

      theLinks = document.getElementsByName(link_name);

      for(var i = 0; i < theLinks.length; i++)
      {
         //theLinks[i].className += " over";
         theLinks[i].style.textDecoration = "underline";
      } // end for(var i = 0; i < theLinks.length; i++)
   } // end if(this.getAttribute("href"))
} // end function hilightLink()


// }}}
// {{{ function removeHilight()
function removeHilight()
{
   var link_name = map_alt_to_name(this.getAttribute('alt'));
   if(!link_name) { return(false); }

   theLinks = document.getElementsByName(link_name);

   for(var i = 0; i < theLinks.length; i++)
   {
      //theLinks[i].className = theLinks[i].className.replace(" over", "");
      theLinks[i].style.textDecoration = "none";
   } // end for(var i = 0; i < theLinks.length; i++)
} // end function removeHilight()


// }}}



/* -----( KEY NAVIGATION )--------------------------- */

// "keys" code adapted from MozPoint (http://mozpoint.mozdev.org/)
// {{{ function keys(key)
function keys(key)
{
   if(!key)
   {
      key = event;
      key.which = key.keyCode;
   } // end if(!key)

   switch(key.which)
   {
      //case 32: // spacebar
      case 39: // rightkey
         if(key.ctrlKey || key.altKey || key.metaKey) { break; }
         next_links = document.getElementsByName("next_photo");
         if(next_links.length == 0) { break; }
         location.href = next_links[0].href;
         break;
      case 37: // leftkey
         if(key.ctrlKey || key.altKey || key.metaKey) { break; }
         prev_links = document.getElementsByName("prev_photo");
         if(prev_links.length == 0) { break; }
         location.href = prev_links[0].href;
         break;
   } // end switch(key.which)
} // end function keys(key)


// }}}
