/****************************************************************
 *                                                              *
 * Keating Magee                                                *
 * http://www.keatingmagee.com/                                 *
 *                                                              *
 * Script Name: scripts.js                                      *
 * Script Version: 1.0                                          *
 * Script Info: Basic Config/Load Scripts                       *
 *                                                              *
 ****************************************************************/

// Function to preload images.

function preLoad() {
    capabilitiesoff = new Image();
    capabilitiesoff.src = "/img/nav/capabilities_off.gif";
    casestudiesoff = new Image();
    casestudiesoff.src = "/img/nav/casestudies_off.gif";
    connectoff = new Image();
    connectoff.src = "/img/nav/connect_off.gif";
    consumeroff = new Image();
    consumeroff.src = "/img/nav/consumer_off.gif";
    newsoff = new Image();
    newsoff.src = "/img/nav/news_off.gif";
    recessionoff = new Image();
    recessionoff.src = "/img/nav/recession_off.gif";

    capabilitieson = new Image();
    capabilitieson.src = "/img/nav/capabilities_on.gif";
    casestudieson = new Image();
    casestudieson.src = "/img/nav/casestudies_on.gif";
    connecton = new Image();
    connecton.src = "/img/nav/connect_on.gif";
    consumeron = new Image();
    consumeron.src = "/img/nav/consumer_on.gif";
    newson = new Image();
    newson.src = "/img/nav/news_on.gif";
    recessionon = new Image();
    recessionon.src = "/img/nav/recession_on.gif";
}

// Function to create dynamic pop up window, currently set to center window on screen.

function newWindow(url, name, wid, hgt, scr, res, stat, loc, mnu, tool, x, y) {
    if (screen) {
        widthOfScreen = screen.width;
        heightOfScreen = screen.height;
    }
    if ((x == null) || (y == null)) {
        midX = widthOfScreen / 2;
        midY = heightOfScreen / 2;
        midWid = wid / 2;
        midHgt = hgt / 2;
        x = midX - midWid;
        y = midY - midHgt;
    }
    windowOpts = "width=" + wid + ",height=" + hgt + ",scrollbars=" + scr + ",resizable=" + res + ",status=" + stat + ",location=" + loc + ",menubar=" + mnu + ",toolbar=" + tool + ",left=" + x + ",top=" + y;
    popUpWindow = window.open(url, name, windowOpts);
}

// Function to dynamically write out the flash code to work around the IE flash "white box" issue.

function flashMovie(name, width, height) {
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '" id="' + name + '" align="middle">');
    document.write('    <param name="allowScriptAccess" value="sameDomain" />');
    document.write('    <param name="movie" value="/swf/' + name + '.swf" />');
    document.write('    <param name="quality" value="high" />');
    document.write('    <param name="bgcolor" value="#ffffff" />');
    document.write('    <embed src="/swf/' + name + '.swf" quality="high" bgcolor="#ffffff" width="' + width + '" height="' + height + '" name="' + name + '" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('    </embed>');
    document.write('</object>');
}

// Function to adjust the page height

function adjustPage() {
    var content = document.getElementById('content');

    // Browser detect, determine width and height, and compensate for the scroll bar if there is one
    if (navigator.appName.indexOf("Microsoft") != -1) {
        winHeight = document.documentElement.offsetHeight;
    } else {
        winHeight = window.innerHeight;
    }

    if (content.clientHeight < winHeight) {
        content.style.minHeight = winHeight + 'px';
    }
}

// Window resize event listener.
if (navigator.appName.indexOf("Microsoft") != -1) {
    window.attachEvent("onresize", adjustPage);
} else {
    window.addEventListener("resize", adjustPage, true);
}


window.onload = adjustPage;