﻿/*********************************************************************************
* This file has javascript functions that must be available to all the pages
**********************************************************************************/

// This array is the list of pages that are available in the main menu of the site
// simply give the menu item a name and a page to go to and the pageLoad function
// that is called on every load event for the page will create the menu
var gMenuItems = new Array(
    new menuItem("Home", "index.htm"),
    new menuItem("About", "about.htm"),
    new menuItem("New", "WhatsNew.htm"),
    new menuItem("Articles", "articles/physindex.htm"),
    new menuItem("Galleries", "galleries_index.htm"),
    new menuItem("Links", "links.htm"),
    new menuItem("Why Learn Physics?", "whyphysics.htm"),
    new menuItem("Contributing", "contribu.htm"),
    new menuItem("Free Education", "edumenu.htm"),
    new menuItem("Lounge", "Lounge.htm")
);

// This is a single item in the main menu
function menuItem(caption, url) {
    this.Caption = caption;
    this.Url = url;
}

// This function should be called on every page's page load event to build the
// common page features, such as the menu, contact button and gutter information
function pageLoad(dist) {
    buildMenu(dist);
    buildContact();
    buildGutter();
}

// Build the contact row (here you may wish to add a shopping cart button)
function buildContact() {

    var contactLink = document.getElementById("contactLine").
        appendChild(document.createElement("A"));
    contactLink.href = "http://www.chongonation.com/Products.htm";
    contactLink.className = "contactArea";

    contactLink.appendChild(document.createTextNode("BOOKS FOR SALE (Product List)"));
}

// Build the gutter area
function buildGutter() {

    var gutterArea = document.getElementById("gutterArea");
    var p1 = gutterArea.appendChild(document.createElement("P"));
    p1.appendChild(document.createTextNode("Copyright(c) C. Tucker (Chongo) all rights reserved"));
            
    var p2 = gutterArea.appendChild(document.createElement("P"));
    p2.appendChild(document.createTextNode("Photographs courtesy of Bernardo "
        + "Ribadeneyra, Ammon McNeely, Silvia Vidal, Heinz Zak, Dean Fidelman, "
        + "Constante Limcolioc, Joe Smith, Michael Hedgepeth, Chongo, and others. "));
}

// Build the main menu
function buildMenu(dist) {

    var menuDiv = document.getElementById("menuDiv");

    for (var i = 0; i < gMenuItems.length; i++) {
        var item = gMenuItems[i];
        
        createMenuItem(item, menuDiv, dist);

        if (i < gMenuItems.length - 1) {
            createSpacerItem(menuDiv);
        }
    }
}

// Create a single menu item
function createMenuItem(item, menuDiv, dist) {

    var anchorTag = menuDiv.appendChild(document.createElement("A"));
    anchorTag.className = "menuItem";
    anchorTag.href = createUrl(dist, item.Url);

    anchorTag.appendChild(document.createTextNode(item.Caption));
}

// Create a space item between menu items
function createSpacerItem(menuDiv) {
    var b = menuDiv.appendChild(document.createElement("B"));
    b.appendChild(document.createTextNode(" | "));
}

// Create a URL (pad it appropriately)
function createUrl(dist, url) {
    var ret = "";
    for (var i = 0; i < dist; i++) {
        ret += "../"
    }
    return ret + url;
}

