/*************************************************************************
 * Interstitial page logic
 * Jon Dunfee, November 2003
 * Copyright (c) 2003 Fusion Alliance
 */

// Initial attributes
var interstitialWinOpen = false;    // State of popup window, leave false
var interstitialWinWidth = 600;     // Default popup window width
var interstitialWinHeight = 300;    // Default popup window height

// Used in anchor tags
function sitepass(a,opt,page)
{
	
    if(interstitialWinOpen) interstitialWin.close();
    var LeftPosition=(screen.width)?(screen.width-interstitialWinWidth)/2:100;
    var TopPosition=(screen.height)?(screen.height-interstitialWinHeight)/2:100;
    var features = (opt)?opt:"width="+interstitialWinWidth+",height="+interstitialWinHeight+",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,left="+LeftPosition+",top="+TopPosition;
    var interstitial = (page)?page:"/interstitial/interstitial.html?redirect=" + escape(a.href) +"&target=" + a.target;
    interstitialWin = window.open(interstitial,"interstitial",features);
    interstitialWin.focus();
    interstitialWinOpen = true;
}

// Used in sub menu items
function menupass(loc,aff,opt,page)
{
    if(interstitialWinOpen) interstitialWin.close();
    var LeftPosition=(screen.width)?(screen.width-interstitialWinWidth)/2:100;
    var TopPosition=(screen.height)?(screen.height-interstitialWinHeight)/2:100;
    var features = (opt)?opt:"width="+interstitialWinWidth+",height="+interstitialWinHeight+",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,left="+LeftPosition+",top="+TopPosition;
    var interstitial = (page)?page:"/interstitial/interstitial.html?redirect=" + escape(loc) +"&target=" + ((aff)?"":"_blank");
    interstitialWin = window.open(interstitial,"interstitial",features);
    interstitialWin.focus();
    interstitialWinOpen = true;
}

// Simple Macromedia window popup
function MM_openBrWindow(theURL,winName,features)
{
    window.open(theURL,winName,features);
}


/*************************************************************************
 * Lilly.com navigation
 * by Jon Dunfee, November 2003
 * Copyright (c) 2003 Fusion Alliance
 *
 * modified mm_menu 20MAR2002 Version 6.0
 * Andy Finnell, March 2002
 * Copyright (c) 2000-2002 Macromedia, Inc.
 *
 * based on menu.js
 * by gary smith, July 1997
 * Copyright (c) 1997-1999 Netscape Communications Corp.
 *
 * Netscape grants you a royalty free license to use or modify this
 * software provided that this copyright notice appears on all copies.
 * This software is provided "AS IS," without a warranty of any kind.
 */

// Global Behaviour Attributes
var menuBaseRoot = "/"    // Local web server root
var menuIsLoaded = false;       // Sets to true when menu is loaded (leave false)

// Behavior Defaults
var menuRelative = false;       // Open relative to menu item; otherwise cascade
var menuSpeed = 1000;           // Set to 1000 when menuRelative is false
var menuXPos = 120;             // Left offset position of first sub menu
var menuYPos = -10;             // Top offset position of first sub menu
var globalMenuRelative = true;  // Open relative to menu item; otherwise cascade
var globalMenuSpeed = 500;      // Set to 1000 when menuRelative is false
var globalMenuXPos = 0;         // Left offset position of first sub menu
var globalMenuYPos = 10;        // Top offset position of first sub menu


// Function to create sub menus
function Menu(label, mw, sx, sy, srel, spd, cmi) 
{
    this.menuLayerClass = "menuLayers";
    this.menuClassTop = "menuItemsOffTop";
    this.menuClass = "menuItemsOff";
    this.menuClassBot = "menuItemsOffBot";
    this.menuClassOne = "menuItemsOffOne";
    this.menuHiliteClassTop = "menuItemsOnTop";
    this.menuHiliteClass = "menuItemsOn";
    this.menuHiliteClassBot = "menuItemsOnBot";
    this.menuHiliteClassOne = "menuItemsOnOne";
    
    // User Definable Variables
        this.label = " " + label;
        this.childMenuIcon = (cmi)?cmi:"images/navigation/arrows.gif";
    this.showActionInStatus = true;
        this.submenuRelativeToItem = (srel);
        this.hideOnMouseOut = true;
        this.hideTimeout = (spd)?spd:1000;

    // Object Defined Variables
    this.menuWidth = mw;
        this.submenuXOffset = sx;
        this.submenuYOffset = sy;
    
    // Object Initialization Variables
        this.items = new Array();
        this.actions = new Array();
    this.actionStatus = new Array();
        this.childMenus = new Array();
        this.addMenuItem = addMenuItem;
        this.writeMenus = writeMenus;
        this.showMenu = showMenu;
        this.onMenuItemOver = onMenuItemOver;
        this.onMenuItemAction = onMenuItemAction;
        this.hideMenu = hideMenu;
        this.hideChildMenu = hideChildMenu;
        if (!window.menus) window.menus = new Array();
        window.menus[this.label] = this;
        window.menus[window.menus.length] = this;
        if (!window.activeMenus) window.activeMenus = new Array();
}

// Function to create sub menu items
function addMenuItem(label, action, dojs, win, features)
{
        this.items[this.items.length] = label;    
    this.actionStatus[this.actionStatus.length] = (action)?action:"";
    if(dojs && action)
    {
        this.actions[this.actions.length] = action;
    }
    else if (win && action)
    {
        this.actions[this.actions.length] = "window.open('"+action+"','_blank'"+((features)?",'"+features+"'":"")+")";
    }
    else if(action)
    {
        this.actions[this.actions.length] = "top.location.href = '"+menuBaseRoot+""+action+"'";
    }
    else
    {
        this.actions[this.actions.length] = "";
    }
}

// Write all menus to page
function writeMenus(container)
{
    if (window.triedToWriteMenus) return;
    window.hideMenuWatch = null;
    document.writeln('<span id="menuContainer"></span>');
    container = findObj("menuContainer");
    if (!container) return;     
    window.triedToWriteMenus = true; 
    container.isContainer = true;
    container.menus = new Array();
    for (var i=0; i<window.menus.length; i++)
    {
        container.menus[i] = window.menus[i];
    }
    window.menus.length = 0;
    var countMenus = 0;
    var countItems = 0;
    var content = "";
    for (var i=0; i<container.menus.length; i++, countMenus++)
    {
        var menu = container.menus[i];
        content = '<div id="menuLayer' + countMenus + '" class="' + menu.menuLayerClass + '" onmouseout="mouseoutMenu();">\n';
        var x=i;
        for (var i=0; i<menu.items.length; i++)
        {
            var item = menu.items[i];
            var childMenu = false;
            if (item.label)
            {
                item = item.label;
                childMenu = true;
            }
            content += '<div id="menuItem' + countItems +'" style="width: ' + menu.menuWidth + 'px;"';
            if(i==0 && i==menu.items.length-1) content += ' class="' + menu.menuClassOne + '"';
            else if(i==0) content += ' class="' + menu.menuClassTop + '"';
            else if (i==menu.items.length-1) content += ' class="' + menu.menuClassBot + '"'; 
            else content += ' class="' + menu.menuClass + '"';
            content += ' onmouseover="onMenuItemOver(null,this);"';
            content += ' onclick="onMenuItemAction(null,this);">';
            if (childMenu) content += '<img src="'+menuBaseRoot+''+ menu.childMenuIcon +'" id="childAnchor' + countItems + '">';
//            content += 'menuItem' + countItems;
            content += item;
            content += '</div>\n';
            countItems++;  
        }
//        content += 'menuLayer' + countMenus + '</div>\n';
        content += '</div>\n';
        wl(content);
        i=x;
    }
    
//     prompt("",debugContent);

    if (!findObj("menuLayer0")) return;
    var menuCount = 0;
    for (var x=0; x<container.menus.length; x++)
    {
        var menuLayer = findObj("menuLayer" + x);
        container.menus[x].menuLayer = "menuLayer" + x;
        menuLayer.Menu = container.menus[x];
        menuLayer.Menu.container = "menuLayer" + x;
        var menu = container.menus[x];
        menu.menuItemLayers = new Array();
        for (var i=0; i<container.menus[x].items.length; i++)
        {
            var l = findObj("menuItem" + menuCount);
            l.menuAction = container.menus[x].actions[i];
            if(i==0 && i==container.menus[x].items.length-1)
            {
                l.menuClass = container.menus[x].menuClassOne;
                l.menuHiliteClass = container.menus[x].menuHiliteClassOne;
            }
            if(i==0)
            {
                l.menuClass = container.menus[x].menuClassTop;
                l.menuHiliteClass = container.menus[x].menuHiliteClassTop;
            }
            else if (i==container.menus[x].items.length-1)
            {
                l.menuClass = container.menus[x].menuClassBot;
                l.menuHiliteClass = container.menus[x].menuHiliteClassBot;
            }
            else
            {
                l.menuClass = container.menus[x].menuClass;
                l.menuHiliteClass = container.menus[x].menuHiliteClass;
            }
            l.actionStatus = container.menus[x].actionStatus[i];
            l.Menu = container.menus[x];
            l.Menu.menuItemLayers[l.Menu.menuItemLayers.length] = l;
            var childItem = findObj("childAnchor" + menuCount);
            if (childItem)
            {
                l.childMenu = container.menus[x].items[i].menuLayer;
                l.Menu.childMenus[l.Menu.childMenus.length] = l.childMenu;
            }
            menuCount++;
        }
    }        
    if (document.captureEvents) document.captureEvents(Event.MOUSEUP);
    if (document.addEventListener) document.addEventListener("mouseup", onMenuItemOver, false);
    document.onmouseup = mouseupMenu;
    window.wroteMenu = true;
    status = "";
}

// Invoke rollover state of sub menu item and open child menu if parent of one
function onMenuItemOver(e, l) {
     crowMenu();
     l = l || this;
     var a = window.ActiveMenuItem;
     if (l.style && l.Menu)
     {
        if (a) 
        {
            a.className = a.menuClass;
                }
        if(l.Menu.showActionInStatus) window.status = l.actionStatus;
                l.zIndex = l.zIndex + 1;
        l.className = l.menuHiliteClass;
        window.ActiveMenuItem = l;
                l.Menu.hideChildMenu(l);
        } else return;
        window.ActiveMenuItem = l;
}

// Capture mouse click on menu items
function onMenuItemAction(e, l) {
        l = window.ActiveMenuItem;
        if (!l) return;
        hideActiveMenus();
//    alert(l.Menu.menuLayer);
    if (l.menuAction) eval("" + l.menuAction);
        window.ActiveMenuItem = 0;
}

// Reset the menu close time out
function crowMenu() {
        if (hideMenuWatch) clearTimeout(hideMenuWatch);
        hideMenuWatch = null;
        DHFlag = false;
}

// Initiate menu close time out
function watchMenu() {
    if(menuIsLoaded) {
        if(window.ActiveMenu) {
                menuStart = new Date();
                DHFlag = true;
                hideMenuWatch = setTimeout("menuHideAlt()", window.ActiveMenu.Menu.hideTimeout);
        }
    }
}

// Alternate menu close logic
function menuHideAlt() {
        if (!DHFlag || !window.ActiveMenu) return;
        var elapsed = new Date() - menuStart;
        var timeout = window.ActiveMenu.Menu.hideTimeout;
        if (elapsed < timeout) {
                hideMenuWatch = setTimeout("menuHideAlt()", timeout+100-elapsed);
                return;
        }
    if(window.ActiveMenu.father) window.ActiveMenu.father.className = window.ActiveMenu.fatherOffClass;
        DHFlag = false;
        hideActiveMenus();
        window.ActiveMenuItem = 0;
}

// Open child sub menu
var menuParentState = false;        // Who activated the menu, leave false
function showMenu(father, menu, x, y, child, imgname, onclass, offclass)
{
    if(menuIsLoaded)
    {
        if(menuParentState) menuParentState.className = menuParentState.offClass;
        if(father)
        {
            menuParentState = father;
            menuParentState.onClass = (onclass)?onclass:false;
            menuParentState.offClass = (offclass)?offclass:false;
        }
        if(!menu)
        {
            hideActiveMenus();
            return;
        }
        if (!window.wroteMenu) return;
        crowMenu();
        if (menu)
        {
            father.className = onclass;
                var obj = findObj(imgname) || document.images[imgname] || document.links[imgname] || document.anchors[imgname];
                x = getObjX(x, obj);
                y = getObjY(y, obj);
        }
        if (findObj("menuItem0"))
        {
                var l = findObj(menu.menuLayer);
                hideActiveMenus();
                window.ActiveMenu = l;
            l.father = father;
            l.fatherOffClass = (offclass)?offclass:false;
            l.fatherOnClass = (onclass)?onclass:false;
                var s = l.style;
                if (x != "relative")
            {
                        s.pixelLeft = x || (window.pageX + document.body.scrollLeft) || 0;
                        s.left = s.pixelLeft + 'px';
                }
                if (y != "relative")
            {
                        s.pixelTop = y || (window.pageY + document.body.scrollTop) || 0;
                        s.top = s.pixelTop + 'px';
                }
            s.zIndex = s.zIndex + 1;
                s.visibility = "inherit";
        }
        if (menu) window.activeMenus[window.activeMenus.length] = l;
        crowMenu();
    }
}

// Capture mouse over sub item event
function onMenuItemDown(e, l)
{
        var a = window.ActiveMenuItem;
}

// Browser sniffer
function getExplorerVersion()
{
    var ieVers = parseFloat(navigator.appVersion);
    if( navigator.appName != 'Microsoft Internet Explorer' ) return ieVers;
    var tempVers = navigator.appVersion;
    var i = tempVers.indexOf( 'MSIE ' );
    if( i >= 0 )
    {
        tempVers = tempVers.substring( i+5 );
        ieVers = parseFloat( tempVers ); 
    }
    return ieVers;
}

// Capture after mouse click to close menus
function mouseupMenu(e)
{
        hideMenu(true, e);
        hideActiveMenus();
        return true;
}

// Execute mouse out event to hide menu or change item state
function mouseoutMenu()
{
        hideMenu(false, false);
        return true;
}

// Hide selected sub menu
function hideMenu(mouseup, e)
{
        var a = window.ActiveMenuItem;
    if (window.ActiveMenu && findObj("menuItem0"))
    {
                if(a)
        {
            a.className = a.menuClass;
                }
        }
        if (!mouseup && window.ActiveMenu)
    {
                if (window.ActiveMenu.Menu)
        {
                        if (window.ActiveMenu.Menu.hideOnMouseOut) watchMenu();
                        return(true);
                }
        }
        return(true);
}

// Hide parent's children menus
function hideChildMenu(hcmLayer)
{
    crowMenu();
    var l = hcmLayer;
    for (var i=0; i < l.Menu.childMenus.length; i++)
    {
        var theLayer = l.Menu.childMenus[i];
        theLayer = findObj(theLayer);
        theLayer.style.visibility = "hidden";
        theLayer.Menu.hideChildMenu(theLayer);
    }
    if (l.childMenu)
    {
        var childMenu = l.childMenu;
        if (findObj("menuItem0"))
        {
            childMenu = findObj(l.childMenu);
            var menuLayer = findObj(l.Menu.menuLayer);
            var s = childMenu.style;
            s.zIndex = menuLayer.style.zIndex+1;
            var x = getObjX(0,menuLayer);
            var y = getObjY(0,(l.Menu.submenuRelativeToItem)?window.ActiveMenuItem:menuLayer);
                if (x != "relative")
            {
                        s.pixelLeft = (x || (window.pageX + document.body.scrollLeft) || 0) + l.Menu.submenuXOffset + l.Menu.menuWidth;
                        s.left = s.pixelLeft + 'px';
                }
                if (y != "relative")
            {
                        s.pixelTop = (y || (window.pageY + document.body.scrollTop) || 0) + l.Menu.submenuYOffset;
                        s.top = s.pixelTop + 'px';
                }
            s.visibility = "inherit";
        } else return;
        window.activeMenus[window.activeMenus.length] = childMenu;
    }
}

// Hide all active menus
function hideActiveMenus()
{
    window.status = "";
        if (!window.activeMenus) return;
        for (var i=0; i < window.activeMenus.length; i++)
    {
                if (!activeMenus[i]) continue;
                if (activeMenus[i].visibility && activeMenus[i].Menu)
        {
                        activeMenus[i].visibility = "hidden";
                        activeMenus[i].Menu.container.visibility = "hidden";
                } else if (activeMenus[i].style) {
                        var s = activeMenus[i].style;
                        s.visibility = "hidden";
                }
        }
        if (window.ActiveMenuItem) hideMenu(false, false);
        window.activeMenus.length = 0;
}

// Allow menu system to be accessed after menu has generated
function menuLoadedNow()
{
    menuIsLoaded = true;
}

document.onload = menuLoadedNow();

// Find object in page
function findObj(item)
{
        if(document.all) return(document.all[item]);
        if(document.getElementById) return(document.getElementById(item));
    if(document.images[item]) return document.images[item];
    if(document.links[item]) return document.links[item];
        return(false);
}

// Determine left position to show sub/child menu
function getObjX (x, img) { 
        if (!document.layers) {
                var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
                var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
                var par = img;
                var lastOffset = 0;
                while(par){
                        if( par.leftMargin && ! onWindows ) x += parseInt(par.leftMargin);
                        if( (par.offsetLeft != lastOffset) && par.offsetLeft ) x += parseInt(par.offsetLeft);
                        if( par.offsetLeft != 0 ) lastOffset = par.offsetLeft;
                        par = macIE45 ? par.parentElement : par.offsetParent;
                }
        } else if (img.x) x += img.x;
        return x;
}

// Determine top position to show sub/child menu
function getObjY (y, img) {
        if(!document.layers) {
                var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
                var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
                var par = img;
                var lastOffset = 0;
                while(par){
                        if( par.topMargin && !onWindows ) y += parseInt(par.topMargin);
                        if( (par.offsetTop != lastOffset) && par.offsetTop ) y += parseInt(par.offsetTop);
                        if( par.offsetTop != 0 ) lastOffset = par.offsetTop;
                        par = macIE45 ? par.parentElement : par.offsetParent;
                }               
        } else if (img.y >= 0) y += img.y;
        return y;
}

// Simplified Document.Write
function w(theText)
{
    window.document.open("text/html");
    window.document.write(theText);
    window.document.close();
}

function wl(theText)
{
    window.document.open("text/html");
    window.document.writeln(theText);
    window.document.close();
}
