function onLoad()
{
    centerIconTable_old();  // front page only, old version
    layoutHome();           // new version

    if ( typeof loadPage === 'function' )
        loadPage();         // custom defined for blog pages
}

function onResize()
{
    centerIconTable_old();  // front page only, old version
    layoutHome();           // new version
}


// Layout the home page, depending on browser size:
// If 900 pixels or more pixels wide, centre table,
// otherwise make table narrower.
function layoutHome()
{
    var hp = $("home_content");
    if ( ! hp )         // i.e., not home page
        return;

    // Get browser window dimensions
    var w = window.innerWidth; 
    if ( ! w ) 
        w = document.body.clientWidth;  // IE hack
    var h = window.innerHeight; 
    if ( ! h ) 
        h = document.documentElement.clientHeight;  // IE hack

    // Adjust table width and position (use left margin to position table)
    if ( w >= 900 ) {
        hp.style.width = 900;
        hp.style.left = Math.floor((w - 900) / 2);
    }
    else {
        hp.style.width = w;
        hp.style.left = 0;
    }

    // Adjust vertical position to center table
    hp.style.top = Math.floor((h - hp.clientHeight) / 2);
    if ( hp.style.top < 80 )
        hp.style.top = 80;

    // Set footer position
    var f = $("footer");
    f.style.position = "fixed";
    f.style.display = "block";
    f.style.width = "100%";
    f.style.top = h - 15;
    //#alert(f.style.top);
    f.style.left = 0;
}


// Toggle square icon on home page between light/dark versions, when
// mousing over/out any part of the box. Arguments are name of page,
// and 1/0 state.
function toggleBox(pg, oz)
{
    var box = $(pg);
    var i = box.style.backgroundImage;
    if ( oz )
        i = i.replace("0.png", "1.png");
    else
        i = i.replace("1.png", "0.png");
    box.style.backgroundImage = i;
}


// Old version for new page, used for clickable image, rather than background
// image in cell (NOT USED ANY MORE)
function toggle2(evt)
{
    if ( ! evt )
        evt = event; // IE hack
    var i = evt.target;
    if ( ! i )
        i = evt.srcElement; // IE hack

    var sfx = evt.type == "mouseover" ? "1.png" : "0.png";
    i.src = i.src.substr(0, i.src.length - 5) + sfx;
}


// Click home page box, goes to page
function clickBox(pg)
{
    window.location = pg;
}


// Center the home page icon table in window
// OLD VERSION
function centerIconTable_old()
{
    var ictab = $("iconTable");
    if ( ! ictab )
        return;

    // Center horizontally in window
    var tabWidth = parseInt(ictab.style.width);
    var iw = window.innerWidth; 
    if ( ! iw ) 
        iw = document.body.clientWidth;  // IE hack
    var lMarg = Math.floor((iw - tabWidth) / 2) - 5;
    if ( lMarg > 0 )
        ictab.style.marginLeft = lMarg + "px";

    // Center vertically
    var contentHeight = 500; // banner plus table
    var ih = window.innerHeight; 
    if ( ! ih ) 
        ih = document.documentElement.clientHeight;  // IE hack
    var tMarg = Math.floor((ih - contentHeight) / 2) - 15;
    if ( tMarg > 0 )
        ictab.style.marginTop = tMarg + "px";
}


// Hover over menu item, creating drop-down if applicable
// STILL USED??? Yes
function menuHover(item, over)
{
    var mitem = $(item);
    if ( over == 1 ) {  // use evt.type
        mitem.style.className = "menuHover";
        mitem.style.background = "#888";
    }
    else {
        mitem.style.className = "menuNormal";
        mitem.style.background = "#ccc";
    }

    /*if ( item == "products" && over ) {
        var pm = $("prod_menu");
        pm.style.visibility = "visible";
        pm.style.position = "absolute";
        pm.style.top = "66px";
        pm.style.left = "54px";
        pm.style.height = "80px";
        pm.style.width = "100px";
    }
    else {
        var pm = $("prod_menu");
        pm.style.visibility = "hidden";
    }*/
}


function $(id)
{
    return document.getElementById(id);
}



