// Globals
var m_isNav, m_isIE;
var MENU_BASE = 101;

// Format <name>~<width>~<clickFunction>
var m_MenuTitles = new Array( 
 'Home~65~OnHome()',
 "Calendar~85~OnCalender()",
 "About us~85~",
 "Audio~65~OnAudio()",
 "News~65~OnNews()",
 "Reviews~70~",
 "Prayer~65~OnPrayer()",
 "Comment~85~OnComment()", 
 "Bulletin~65~OnBulletin()", 
 "Gallery~65~OnGallery()", 
// "Forum~65~OnForum()", 
 "Links~65~OnLinks()"
 ,"Departments~65~"
 );
 
// Format <description>~<id>~<clickFunction>
var m_MenuItems = new Array( 
 "", 
 "", 
 "Our Beliefs~id~OnBelief()|Directions~id~OnDirections()", 
 "",
 "",
 "Sing For Haiti~id~OnReview01()|A Deeper Look~id~OnReview02()|Passing On The Baton~id~OnReview03()",
 "",
 "",
 "",
 "",
 ""
 , "Men's Ministeries~id~OnMens()"
// , "Youth~id~OnYouth()|Elders~id~OnElders()"
 );

//******************************************************************************
// Menu handling
//******************************************************************************
function OnMens()
{
    _contentDisplay( "mens.php", 400 );
}

function OnYouth()
{
    _contentDisplay( "youth.php", 400 );
}

function OnElders()
{
    _contentDisplay( "elders.php", 400 );
}

function OnSabbathSchool()
{
}

function OnHome()
{
    _contentDisplay( "index.php", 100 );
}

function OnLinks()
{
    _contentDisplay( "links.php",400 );
}

function OnBelief()
{
    _contentDisplay( "beliefs.php",400 );
}

function OnAudio()
{
    _contentDisplay( "audio.php",400 );
}

function OnPrayer()
{
    _contentDisplay( "prayer.php",400 );
}

function OnComment()
{
    _contentDisplay( "comment.php",400 );
}

function OnNews()
{
    _contentDisplay( "news.php",400 );
}

function OnCalender()
{
//var           win;
//
//  win = window.open( "docs/calender.pdf", "Calendar", "status=no,location=no,resizable=yes,scrollbars=yes" );
//  win.focus();
    
//    _contentDisplay( "docs/calender.pdf" );
    _contentDisplay( "calender.php", 400 );
}

function OnDepartments()
{
//var           win;
//
//  win = window.open( "docs/weekly.pdf", "Weekly Bulletin", "status=no,location=no,resizable=yes,scrollbars=yes" );
//  win.focus();

  _contentDisplay( "docs/weekly.pdf", 400 );

}

function OnBulletin()
{
//var           win;
//
//  win = window.open( "docs/weekly.pdf", "Weekly Bulletin", "status=no,location=no,resizable=yes,scrollbars=yes" );
//  win.focus();

  _contentDisplay( "docs/weekly.pdf", 400 );

}

function OnGallery()
{
//var           win;
//
//  win = window.open( "gallery/index.php", "Gallery", "status=no,location=no,resizable=yes,scrollbars=yes" );
//  win.focus();

  _contentDisplay( "gallery/index.php", 400 );

}


function OnForum()
{
var  comment;

    comment = "The comments, thoughts and topics found within the forums are not necessarily in agreement with the doctrines of the Seventh-day Adventist Church. ";
    comment += "They remain the thoughts and comments of the writer of each comment.";
    comment += "\n\n\nIf you understand and agree with the above statement, you may continue by pressing 'Ok'.\n\n";
    if ( confirm( comment ) )
    {
    var           win;

        win = window.open( "forum/index.php", "Forum", "status=no,location=no,resizable=yes,scrollbars=yes" );
        win.focus();
    }    
}

function OnWebmaster()
{
    sendMail( "webmaster@chiswicksda.co.uk", "" );
}

function OnPastor()
{
    sendMail( "pastor@chiswicksda.co.uk", "" );
}

function OnHistory()
{
}

function OnReview01()
{
    _contentDisplay( "review01.php",400 );
}

function OnReview02()
{
    _contentDisplay( "review02.php",400 );
}

function OnReview03()
{
    _contentDisplay( "review03.php",400 );
}

function OnDirections()
{
    _contentDisplay( "directions.php",400 );
}

function OnMinistriesFamilyLife()
{
    _contentDisplay( "MinistriesFamilyLife.php", 1500 );
}

function OnMinistriesPastoral()
{
    _contentDisplay( "MinistriesPastoral.php", 700 );
}

//******************************************************************************
// Menu processing
//******************************************************************************
function _contentDisplay( str, iSize )
{
//    document.URL = str;
    parent.location = str;
//  HidePopupMenu();
}

function HidePopupMenu()
{
    control = document.getElementById( "idMenuDropdown" );
    control.innerHTML = "";
}

function HiLiteMenuItem( i )
{
//    event.srcElement.style.color = ( i == 1 ? "yellow" : "white" );
}

function OnMenuDropdown( iMenu, iY )
{
var     menuItemArray, menuEntryArray;
var     strHTML = "";
var     d;
var     control;

    // Get the menu options avaliable
    strHTML = '';   

    // Parse the details 
    menuItemArray = m_MenuItems[ iMenu ].split( "|" );
    iItemCount = 0;
    for ( var i in menuItemArray )
    {
        menuEntryArray = menuItemArray[ i ].split( "~" );

        if ( strHTML.length > 0 )
            strHTML += "<BR>";
//        strHTML += '<B class="menuitems" style="cursor:pointer;" id="idMenuItem' + menuEntryArray[ 1 ] + '" ';
        strHTML += '<B class="menuitems" style="cursor:pointer;" id="idMenuItem' + i + '" ';
        strHTML += 'onMouseEnter="HiLiteMenuItem( 1 )" ';
        strHTML += 'onMouseLeave="HiLiteMenuItem( 0 )" ';
        strHTML += 'onMouseDown="' + menuEntryArray[ 2 ] + ';" ';
        strHTML += '>' + menuEntryArray[ 0 ];
        strHTML += '</B>\n';
        
        iItemCount++;
    }
    if ( strHTML.length > 0 )
        strHTML = '<div class="menuPopup">' + strHTML + '</div>';

    control = document.getElementById( "idMenuDropdown" );
    if ( document.all )
        control.style.left = event.x + 3;
    else
    {
        // Code for Netscape
        iX = 0;
        for( var i = 0; i < iMenu; i++ )
        {
            titlesArray = m_MenuTitles[ i ].split( "~" ); 
            iX += parseInt( titlesArray[ 1 ] );
        }
        control.style.left = iX + 3;
//        control.style.top = iY;

        control.style.height = ( iItemCount * 15 );
    }
    control.style.top = iY;
    
    control.innerHTML = strHTML;
}


// private
function loadMenu() 
{
var             titlesArray;
var             iSize = 2;

    // Split the m_MenuTitles into parts    
    strHTML = "";
    for ( var i in m_MenuTitles )
    {
        titlesArray = new Array();
        titlesArray = m_MenuTitles[ i ].split( "~" ); 

        // Draw the menu item
        strHTML += '<div id="idMenu' + i.toString() + '"';
        strHTML += ' class="MenuItem"';
        strHTML += ' style="cursor:pointer;position:absolute; left:'+ iSize + 'px;" ';
        strHTML += ' onMouseEnter="HiLiteMenuItem( 1 )" ';
        strHTML += ' onMouseLeave="HiLiteMenuItem( 0 )" ';
        if ( titlesArray[ 2 ].length == 0 )
            strHTML += ' onMouseOver="OnMenuDropdown(' + i.toString() + ', ' + ( MENU_BASE + 19 ) + ' )"';
        else
            strHTML += ' onMouseOver="HidePopupMenu()" onMouseDown="' + titlesArray[ 2 ] + '"';
        strHTML += "><B>";
        strHTML += titlesArray[ 0 ];    
        strHTML += "</B></div>\n";  
        iSize += parseInt( titlesArray[ 1 ] ); 
    }

    control = document.getElementById( "idBlankmenu" );
    control.innerHTML = strHTML;
}

// private
// Check to see  which version of browser
function getBrowserInfo()
{
    m_isNav = false;
    m_isIE = false;
    if ( parseInt( navigator.appVersion ) >= 4 )
        m_isNav = true;
    else
        m_isIE = true;
}


// private
//******************************************************************************
// Clock display
//******************************************************************************
function sendMail( email, subject )
{
var             anchorPoint;

    anchorPoint = document.createElement( "A" );
    anchorPoint.href = "mailto:" + email + "?subject=" + subject;
    document.body.appendChild( anchorPoint );
    anchorPoint.click();
}

// private
//******************************************************************************
// Clock display
//******************************************************************************
function showClock() 
{
var t;

   t = new Date();
   control = document.getElementById( "idTimeSlot" );
   if( control )
      control.innerHTML = t.toLocaleString();
      
   window.setTimeout( "showClock()", 1000 );
}


// private
//******************************************************************************
//******************************************************************************
function createControls( nBack )
{
var             obj, objTable;

    // Top banner
    objTable = document.createElement( "DIV" );
    objTable.innerHTML = '<table onMouseDown="OnHome()" onMouseOver="HidePopupMenu();" cellspacing="0px" cellpadding="0px" border="0px" width="100%" style="position:absolute; top:0px; height:80px;">'
      + '<tr class="TopBanner">'
      + '<td align="left"><img style="cursor:pointer;" src="' + ( nBack == 1 ? '../' : '' ) + 'images/TopStrip.jpg" / WIDTH="407" HEIGHT="100"></td>'
//      + '<td class="headCenter" id="headCenter" width="100%" style="background-Color:#FFFFFF;" />'
      + '<td class="headCenter" id="headCenter" width="100%" />'
      + '<td align="right" valign="center"><img style="cursor:pointer;" src="' + ( nBack == 1 ? '../' : '' ) + 'images/thelogo.jpg" width="160" height="100" /></td>'
      + '</tr></table>';
    objTable.style.position = "absolute";
    objTable.style.left = 0;
    objTable.style.top = 0;
    objTable.style.width = "100%";
    objTable.style.posHeight = 80;
    document.body.appendChild( objTable );

    // Provides the backdrop for the blank menu - makes it a thicker line
    obj = document.createElement( "DIV" );
    obj.innerHTML = '<table width="100%" class="NTop" style="position:absolute; top:' + MENU_BASE + 'px;">'
      + '<tr border="0px" align="right"><td id="idTimeSlot" align="right" class="NTop2" border="0px"></td></tr></table>'
    obj.style.left = 0;
    obj.style.top = 0;
    obj.style.width = "100%";
    obj.style.position = "absolute";
    document.body.appendChild( obj );

    // Space for menu bar
    obj = document.createElement( "DIV" );
    obj.style.position = "absolute";
    obj.style.left = 0;
    obj.style.top = MENU_BASE + 4;
    obj.style.width = "100%";
    obj.id = "idBlankmenu";
    obj.className = "NMenu";
    document.body.appendChild( obj );

    // Popup to display menu contents
//    obj = document.createElement( "DIV" );
    obj = document.createElement( "LAYER" );
    obj.style.position = "absolute";
    obj.id = "idMenuDropdown";
    obj.className = "NMenu";
    document.body.appendChild( obj );
}

//******************************************************************************
// OnLoad handler
//******************************************************************************
function OnLoad( nBack )
{
    createControls( 0 );

    showClock();

    getBrowserInfo();

    // Load the menu options
    loadMenu();
}


