///////    rollover.js    ///////
// Customize imgDir, pageIds, imgSuffix, and image file names

// imgDir: ralative URL of directory for images
// const imgDir="rg/";   IE 6.0 does not recognize const
var imgDir="rg/";   

// image and page file suffixes:
// const imgSuffix = ".gif", pageSuffix = ".html";
var imgSuffix = ".gif", pageSuffix = ".html";

// pageIds: an array of page ids
var pageIds= [ "authors", "chapters", "examples", "faq", "feedback", "handson", "main", "ordering", "updates", "resources", "projects", "preface", "toc", "sitemap" ];

// var dir set by page in subdirectory
var dir = "";

// Image file names
// image for mouseover
function overImg(pageid)
{   return imgDir + "o_" + pageid + imgSuffix;
}

// image for mouseout
function outImg(pageid)
{   return imgDir + "u_" + pageid + imgSuffix;
}

// mouseover image double as page identification
function selfImg(pageid)
{   return imgDir + "o_" + pageid + imgSuffix;
}
// No customization necessary beyound this line

function myPageName()
{  var str = document.URL;
   var re = /([^\/]+)\.[^\/\.]+$/;    // (main).html, (project).htm#milestone
   var found = str.match(re);
   if ( found ) return found[1];
   else return null;
}

var myid = myPageName();
var imgLoaded = false;

function loadImage(url)
{  if (document.images)
   {    rslt = new Image();
        rslt.src = url;
        return rslt;
   }
}

/* no image changing for current page */
/* handles mouseover and mousedown events */
function over(pageid)
{  if (document.images && imgLoaded == true)
   {  if ( pageid != myid )
      {  document.images[pageid].src = overImg(pageid);
         if ( document.images[myid] )
         {   document.images[myid].src = outImg(myid);
         }
      }
      else
      {  document.images[pageid].src = outImg(pageid);
      }

   }
}

function out(pageid)
{  if (document.images && imgLoaded == true)
   {  if ( pageid != myid )
      {  document.images[pageid].src = outImg(pageid);
         if ( document.images[myid] )
         {   document.images[myid].src = overImg(myid);
         }
      }
      else
      {  document.images[pageid].src = overImg(pageid);
      }
   }
}

/* go nowhere for current page */
function toPage(pageid)
{ if ( pageid == myid ) return;
  if ( pageid == "toc" || pageid == "preface" )
  {   window.location = pageid + ".pdf"; }
  else if ( pageid == "handson" && dir == "" )
  {      window.alert(
	    "Hands-on is protected.  For a password go to end of Main Page");
          window.location = pageid + "/" + pageid + ".html"; 
  }
  else if ( pageid == "handson" && dir == "../" )
  {   window.location = dir + pageid + "/" + pageid + pageSuffix;
  }
  else
  {   window.location = dir + pageid + pageSuffix;
  }
}

function preloadImages()
{   if (document.images)  
    {   for (var i=0; i < pageIds.length; i++)
        {   loadImage(overImg(pageIds[i]));
            loadImage(outImg(pageIds[i]));
            loadImage(selfImg(pageIds[i]));
	}
        imgLoaded = true;
    }
    if ( document.images[myid] )
    {   
        document.images[myid].src = selfImg(myid);
    }
}

/*
<td><a href="javascript:toPage('index');"
  onmouseover="over('home')" 
  onmouseout="out('home')"
  onclick="click('home')"
  ><img name="home" id="home" src=
        "graphics/homeout.gif" width="130" height="25" alt="home"
        style="border-style: none"></a></td>

onload="preloadImages()"
*/
