var isW3C = (document.getElementById) ? true : false;
var isAll = (document.all) ? true : false;

// I know ... I know... browser sniffing sucks... but IE is making me pull out my hair by not being standard and being full of bugs
var isIEsix = false;
if ((navigator.appName == "Microsoft Internet Explorer") && (navigator.appVersion.match("MSIE 6") != null))
  isIEsix = true;

// I know ... I know... browser sniffing sucks... but Safari is also making me pull out my hair by not being standard and being full of bugs
var isSafari = false;
if (navigator.appVersion.match("Safari") != null)
  isSafari = true;

if (top.location.href != location.href)
  top.location.href = location.href; 


var printPageArray = new Array (
                                './etchings.html' ,
                                './monotype.html' ,
                                './silkscrn.html'
                               );

var rnumb = Math.floor(Math.random()*printPageArray.length);
printLink = printPageArray[rnumb];

var paintPageArray = new Array (
                                './oil.html' ,
                                './water.html'
                               );

var rnumb2 = Math.floor(Math.random()*paintPageArray.length);
paintLink = paintPageArray[rnumb2];

var jewleryPageArray = new Array (
                                './athena.html' ,
                                './gaea.html'
                               );

var rnumb3 = Math.floor(Math.random()*paintPageArray.length);
jewleryLink = jewleryPageArray[rnumb3];


function writeRandomLinkIcon(fade, theArray)
{
  var rnumb = Math.floor(Math.random()*theArray.length);
  document.write('<p><img src="' + theArray[rnumb] + '" title="Goto more of Eileen\'s Art" alt="See more" style="filter:alpha(opacity=50);-moz-opacity:0.5; opacity:0.5;"');
  if (fade == true)
    document.write(' id="fadeicon" onload="fadeIt(\'fadeicon\', 50, 1, 100, 10)"');
  document.write(' /></p>\n');
} // end randomArrayEntry


function getTargetElement(evt)
{
  var elementToGet
  if (evt.target)
    elementToGet = (evt.target.nodeType == 3) ? evt.target.parentNode : evt.target;
  else
    elementToGet = evt.srcElement;

  return elementToGet
} // end getTargetElement


function focusOnThis(theId)
{
  var thingToFocusOn = (isW3C) ? document.getElementById(theId) : ((isAll) ? document.all[theId] : null);
  if (thingToFocusOn != null)
    thingToFocusOn.focus();
} // focusOnThis()


function hide_it(picName)
{
  var showBigPic = (isW3C) ? document.getElementById("bigpicdiv") : ((isAll) ? document.all["bigpicdiv"] : null);
  if (showBigPic != null)
    showBigPic.style.visibility = "hidden";
  var divObj = (isW3C) ? document.getElementById("bigpicdiv") : ((isAll) ? document.all["bigpicdiv"] : null);
  if (divObj != null)
    divObj.innerHTML = '';

  focusOnThis(picName);
} // hide_it()


function processKeys(evt)
{
  evt = (evt) ? evt : ((window.event) ? window.event : "")
  if (evt)
  {
    var elem = getTargetElement(evt)
    if (elem)
    {
      while (elem.id == "")
        elem = elem.parentNode;

      var strIndex = elem.id.search(/__/);
      if (strIndex == -1)
      {
        if (evt.keyCode == 13)
        {
          show_it(elem.id);
          return false;
        }
      }
      else
      {
        strIndex = strIndex + 2;
        elem.id = elem.id.substring(strIndex);
        if (evt.keyCode == 13)
        {
          hide_it(elem.id);
          return false;
        }
      }
    }
  }
  return true;
} // end processKeys(evt)


function processMouse(evt)
{
  evt = (evt) ? evt : ((window.event) ? window.event : "")
  if (evt)
  {
    var elem = getTargetElement(evt)
    if (elem)
    {
      while (elem.id == "")
        elem = elem.parentNode;

      var strIndex = elem.id.search(/__/);
      if (strIndex == -1)
      {
        if ((evt.button == 1) || (evt.button == 0))
        {
          show_it(elem.id);
          return false;
        }
        else if ((evt.button == 2) || (evt.button == 3))
        {
          window.status='Please do not copy these images - they are copyrighted and not public domain';
          windowStatus = window.status;
        }
      }
      else
      {
        strIndex = strIndex + 2;
        elem.id = elem.id.substring(strIndex);
        if ((evt.button == 1) || (evt.button == 0))
        {
          hide_it(elem.id);
          return false;
        }
        else if ((evt.button == 2) || (evt.button == 3))
        {
          window.status='Please do not copy these images - they are copyrighted and not public domain';
          windowStatus = window.status;
          return false;
        }
      }
    }
  }
  return true;
} // end processMouse(evt)


var windowStatus = "";
function processMouseoverPic(evt)
{
  evt = (evt) ? evt : ((window.event) ? window.event : "")
  if (evt)
  {
    var elem = getTargetElement(evt)
    if (elem)
    {
      while (elem.id == "")
        elem = elem.parentNode;

      windowStatus = window.status;
      var strIndex = elem.id.search(/__/);
      if (strIndex == -1)
      {
        var n=0;
        while ((imagePageAll[n] != elem.id) && (n < imagePageAll.length))
          n++;

        if (n < imagePageAll.length)
          window.status = "Show a larger version of " + imageTextAll[n] + ".";
        else
          window.status = "Show a larger version of this picture.";
      }
      else
        window.status = "Go back to the thumbnails.";
    }
  }
  return true;
} // end processMouseoverPic(evt)


function processMouseoutPic(evt)
{
  evt = (evt) ? evt : ((window.event) ? window.event : "")
  if (evt)
  {
    var elem = getTargetElement(evt)
    if (elem)
    {
      window.status = windowStatus;
      windowStatus = "";
    }
  }
  return true;
} // end processMouseoutPic(evt)


var itemsPerPage = 18;
function showPage(page)
{
  var min = (page == "all") ? 1 : (((page - 1) * itemsPerPage) + 1);
  var max = (page == "all") ? numItemsOnPage : (Math.min((page * itemsPerPage), numItemsOnPage));
  var artElement;
  for (i=1;numItemsOnPage >= i; i++)
  {
    artElement = (isW3C) ? document.getElementById("work_".concat(i)) : ((isAll) ? document.all["work_".concat(i)] : null);
    if (artElement != null)
    {
      if ((i >= min) && (max >= i))
        artElement.style.display = "block";
      else
        artElement.style.display = "none";
    }
  }

  var pageBlockItem;
  for (i=1;numPages >= i; i++)
  {
    pageBlockItem = (isW3C) ? document.getElementById("pickpage".concat(i)) : ((isAll) ? document.all["pickpage".concat(i)] : null);
    if (pageBlockItem != null)
    {
      if (i != page)
        pageBlockItem.className = "greyhot nounder";
      else
        pageBlockItem.className = "hot nounder";
    }
  }

  pageBlockItem = (isW3C) ? document.getElementById("pickpageall") : ((isAll) ? document.all["pickpageall"] : null);
  if (pageBlockItem != null)
  {
    if (page != "all")
      pageBlockItem.className = "greyhot nounder";
    else
      pageBlockItem.className = "hot nounder";
  }
} // end showPage()


function showPageChoices()
{
  if ((numItemsOnPage > itemsPerPage) && (isSafari == false))
  {
    pageBlock = (isW3C) ? document.getElementById("pagechoice") : ((isAll) ? document.all["pagechoice"] : null);
    if (pageBlock != null)
    {
      for (i=1; i <= numPages; i++)
        pageBlock.innerHTML += '<a tabindex="99" id="pickpage' + i + '" class="greyhot nounder" href="javascript://" onkeypress=\'showPage("' + i + '");\' onmousedown=\'showPage("' + i + '");\'>Page ' + i + '</a> | '

      pageBlock.innerHTML += '<a id="pickpageall" class="hot nounder" tabindex="99" href="javascript://" onkeypress=\'showPage("all");\' onmousedown=\'showPage("all");\'>Show All</a>';
      pageBlock.style.display = "block";
    }
  }
}  // end showPageChoices
