﻿/******************************************************************************
* Filename:    pageFunctions.js                                               *
* Description: This Javascript creates the rollover images associated with    *
*              the "page functions" tools at the bottom of some pages.        *
* Authors:     Michael A. Smith and Dan Crane                                 *
* Modified:    2006-11-21                                                     *
******************************************************************************/
/** Gets called from init() */
function setupPageFunctions() {
  generatePrintPageFunction();
  fixBookmarkPageFunction();
} // end setupPageFunctions()
/** The page functions image should change onmouseover */
function eventOnMouseOver() {
  this.style.cursor = "pointer";
  this.style.color  = "#F11A29";
  var image = this.getElementsByTagName("img")[0];

  // determine red image filename
  var imagePath = image.src;
  var j = imagePath.lastIndexOf(".");
  var newImagePath = imagePath.substring(0, j);
  newImagePath += "_red";
  newImagePath += imagePath.substring(j, imagePath.length);

  image.src = newImagePath;
}

function eventOnMouseOut(){
  this.style.cursor = "auto";
  this.style.color  = "black";
  var image = this.getElementsByTagName("img")[0];
  image.src = image.src.replace("_red", "");
}

function rolloverImages() {

  if (!document.getElementById) return;

  var root = document.getElementById("pagefunctions");
  if (!root) return;

  var anchors = root.getElementsByTagName("a");
  if (!anchors) return;

  for (var i = 0; i < anchors.length; i++) {
    var anchor = anchors[i];

    // Add image restore behavior
    anchor.onmouseout = eventOnMouseOut;

    // add swap image behavior
    anchor.onmouseover = eventOnMouseOver;

  } // end for loop
} // end rolloverImages()

function fixBookmarkPageFunction() {

  var liBookmarkPage = document.getElementById("liBookmarkPage");
  if (!liBookmarkPage) return false;
  var  aBookmarkPage = liBookmarkPage.getElementsByTagName("a")[0];

  if (!window.external) return false;
  aBookmarkPage.onclick = function () {
    var url = window.location.href;
    var title = document.title;

    window.external.AddFavorite(url, title);
    return false;
  }
  // This should not happen:
  return true;
}

function generatePrintPageFunction() {
  var  liPrintPage = document.getElementById("liPrintPage");
  if (!liPrintPage) return false;
  var imgPrintPage = document.createElement("img");
  var txtPrintPage = document.createTextNode(" print page");

  imgPrintPage.src    = "/images/ext/page_functions/printpage.gif";
  imgPrintPage.alt    = "print this page";
  imgPrintPage.width  = 12;
  imgPrintPage.height = 10;

  liPrintPage.appendChild(imgPrintPage);
  liPrintPage.appendChild(txtPrintPage);

  //events
  liPrintPage.onclick = function() {window.print();}
  liPrintPage.onmouseover = eventOnMouseOver;
  liPrintPage.onmouseout = eventOnMouseOut;
  liPrintPage.title = "print this page";

  return true;
}