function w(s) {document.writeln(s)}

function nh( name, html, highlight )
{
    if ( highlight || gCategory == name )
    {
        if ( name == 'Home' )
        {
            w('<td width=80 height=22 align=left><span class="nav2"><a href="' + html + '">&nbsp;' + name + '</a></span></td>')
        }
        else
        {
            w('<td width=80 height=22 align=center><span class="nav2"><a href="' + html + '">&nbsp;' + name + '</a></span></td>')
        }
    }
    else
    {
        if ( name == 'Home' )
        {
            w('<td width=80 height=22 align=left><a href="' + html + '">&nbsp;' + name + '</a></td>')
        }
        else
        {
            w('<td width=80 height=22 align=center><a href="' + html + '">&nbsp;' + name + '</a></td>')
        }
    }
}

function nv( name, html, highlight )
{
    w('<tr valign=middle align=left>')
    if ( highlight || gMenuItem == name || gSubCategory == name )
    {
       w('<td width=125 height=25><span class="nav2"><a href="' + html + '">&nbsp;' + name + '</a></span></td>')
    }
    else
    {
       w('<td width=125 height=25><a href="' + html + '">&nbsp;' + name + '</a></td>')
    }
    w('</tr>')
    w('<tr valign=middle align=left>')
}

function nv2( parent, name, html, highlight )
{
    if ( gSubCategory == parent || gMenuItem == parent )
    {
        w('<tr valign=middle align=left>')
        if ( highlight || gMenuItem == name )
        {
           w('<td width=125 height=17><span class="nav2"><a href="' + html + '">&nbsp;&nbsp;&nbsp;' + name + '</a></span></td>')
        }
        else
        {
           w('<td width=125 height=17><a href="' + html + '">&nbsp;&nbsp;&nbsp;' + name + '</a></td>')
        }
        w('</tr>')
        w('<tr valign=middle align=left>')
    }
}

function header( mainArea, category, subCategory, title, menuItem, draft, pictures )
{
    gMainArea = mainArea
    gCategory = category
    gSubCategory = subCategory
    gTitle = title
    gMenuItem = menuItem

    if ( draft == 'Yes' )
    {
        if ( pictures == 'Yes' )
        {
            w('<body onLoad="preloadImages()" background="./draft.gif" text="#000000" link="#0000ff" vlink="#800080" topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>')
        }
        else
        {
            w('<body background="./draft.gif" text="#000000" link="#0000ff" vlink="#800080" topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>')
        }
    }
    else
    {
        if ( pictures == 'Yes' )
        {
            w('<body onLoad="preloadImages()" bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>')
        }
        else
        {
            w('<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>')
        }
    }
    w('<table border=0 cellspacing=0 cellpadding=0 width=840 summary=banner>')
    w('<tr valign=top align=left>')
    w('<td height=100 width=150 bgcolor="#01558F"><img id="banner1" src="./sharkcorner.jpg" alt="fish" border=0></td>')
    if ( mainArea == 'Home' )
    {
        w('<td height=100 width=542 bgcolor="#01558F" align=center valign=middle><span class="banner">ATJ\'s Diving Site</span></td>')
    }
    else
    {
        w('<td height=100 width=540 bgcolor="#01558F" align=center valign=middle><span class="banner">' + mainArea + '</span></td>')
    }
    w('<td height=100 width=150 bgcolor="#01558F">&nbsp;</td>')
    w('</tr>')
    w('</table>')
    w('<div class="nav">')
    w('<table border=0 cellspacing=0 cellpadding=0 width=842 summary=navigator>')
    w('<tr valign=top align=left>')
    w('<td height=22 width=800>')
    w('<table id="navigationbar2" border=0 cellspacing=0 cellpadding=0 width=800 summary=navigator>')
    w('<tr valign=middle align=left>')

    switch (mainArea)
    {
        case 'Home':
            nh( 'Home',  './default.html' )
            nh( 'News',  './news.html' )
            nh( 'Dive Log',   './dives.html' )
            nh( 'About Me', './aboutme.html')
            nh( 'Site Info', './site_info.html')
            break;
        case 'Dive Log':
            nh( 'Home',  './default.html' )
            nh( 'News',  './news.html' )
            nh( 'Dive Log',   './dives.html', true )
            nh( 'About Me', './aboutme.html')
            nh( 'Site Info', './site_info.html')
            break;
        case 'News':
            nh( 'Home',  './default.html' )
            nh( 'News',  './news.html', true )
            nh( 'Dive Log',   './dives.html' )
            nh( 'About Me', './aboutme.html')
            nh( 'Site Info', './site_info.html')
            break;
        case 'About Me':
            nh( 'Home',  './default.html' )
            nh( 'News',  './news.html' )
            nh( 'Dive Log',   './dives.html' )
            nh( 'About Me', './aboutme.html', true)
            nh( 'Site Info', './site_info.html')
            break;
        case 'Site Info':
            nh( 'Home',  './default.html' )
            nh( 'News',  './news.html' )
            nh( 'Dive Log',   './dives.html' )
            nh( 'About Me', './aboutme.html')
            nh( 'Site Info', './site_info.html', true)
            break;
    }

    w('</tr>')
    w('</table>')
    w('</td>')
    w('</tr>')
    w('</table>')
    w('</div>')
    w('<table cellpadding=0 cellspacing=0 border=0 width=800 summary=navigator>')
    w('<tr valign=top align=left>')
    w('<td>')
    w('<div class="nav">')
    if ( mainArea == 'Home' )
    {
        w('<table border=0 cellspacing=0 cellpadding=0 width=10 summary=navigator>')
    }
    else
    {
        w('<table border=0 cellspacing=0 cellpadding=0 width=127 summary=navigator>')
    }
    w('<tr valign=top align=left>')
    w('<td height=3></td>')
    w('</tr>')
    w('<tr valign=top align=left>')
    w('<td height=150 width=127>')
    if ( mainArea == 'Home' )
    {
        w('<table id="verticalnavigationbar1" border=0 cellspacing=1 cellpadding=0 width=10 summary=navigator>')
    }
    else
    {
        w('<table id="verticalnavigationbar1" border=0 cellspacing=1 cellpadding=0 width=127 summary=navigator>')
    }
    switch (mainArea)
    {
        case 'About':
            nv( 'Photography', './myphotography.html' )
            break;
        case 'Dive Log':
            nv( 'By Date', './dives.html' )
            nv( 'By Camera/Lens', './divesbycameraandlens.html' )
            nv( 'By Location', './divesbylocation.html' )
            break;

        case 'News':
            nv( 'D300 Ikelite Housing', './d300ikelite.html' )
            nv( 'Undersea 2008', './undersea20080816.html' )
            nv( 'News Archive', './newsarchive.html')
            nv2( 'News Archive', 'D70 Ikelite Housing', './D70ikelite.html' )
            nv2( 'News Archive', 'Ikelite Housing', './4500ikelite.html' )
            nv2( 'News Archive', 'Undersea 2002', './undersea20020914.html' )
            nv2( 'News Archive', 'Undersea 2003', './undersea20030830.html' )
            nv2( 'News Archive', 'Undersea 2005', './undersea20050910.html' )
            nv2( 'News Archive', 'Undersea 2006', './undersea20060819.html' )
            nv2( 'News Archive', 'Undersea 2007', './undersea20070526.html' )


            break;
    }
//    if ( mainArea != 'Home' )
//    {

//    w('<tr valign=middle align=left>')
//    w('<td width=80 height=22 align=left><br>')
//    w('<form action=./donate.html method="post">')
//    w('<input type=image src=https://www.paypal.com/en_US/i/btn/x-click-but04.gif border=0 name=submit>')
//    w('<img alt="" border="0" src="https://www.paypal.com/en_AU/i/scr/pixel.gif" width="1" height="1">')
//    w('</form>')
//    w('</td>')
//    w('</tr>')
//    }

    w('</table>')
    w('</td>')
    w('</tr>')
    w('</table>')
    w('</div>')
    w('</td>')
    w('<td>')
    if ( mainArea == 'Home' )
    {
        w('<table border=0 cellspacing=0 cellpadding=0 width=780 summary=content>')
    }
    else
    {
        w('<table border=0 cellspacing=0 cellpadding=0 width=703 summary=content>')
    }

    w('<tr valign=top align=left>')
    w('<td height=3></td>')
    w('</tr>')
    w('<tr valign=top align=left>')
    w('<td height=366 width=673><div id="externalhtml1color">')
    if ( mainArea == 'Home' )
    {
        w('<table width=780 summary=content>')
    }
    else
    {
        w('<table width=703 summary=content>')
//        w('<br>' + mainArea + '->' + category + '->' + subCategory + '->' + menuItem + '<br><br>' )
    }
    w('<tr align=left valign=top>')
    w('<td>')
    if ( mainArea != 'Tanks' )
    {
       w('<span class="head"><p align=center><b>' + title + '</b></p></span>')
    }
//	Print #nFile%,   "<TABLE ID=""Page Heading"" BORDER=0 CELLSPACING=3 CELLPADDING=1 WIDTH=" & nTableWidth% & ">"
//	Print #nFile%, "    <TR>"
//	Print #nFile%,   "<TD WIDTH=""40%""><P><FONT SIZE=""-1"" FACE=""Arial,Helvetica,Univers,Zurich BT"">"  & "</FONT></TD>"
//	Print #nFile%,   "<TD WIDTH=""30%""><P><B><FONT SIZE=""+1"" FACE=""Arial,Helvetica,Univers,Zurich BT"">BOOKS</FONT></TD>"
//	Print #nFile%,   "<TD WIDTH=""30%""><P><FONT SIZE=""-1"" FACE=""Arial,Helvetica,Univers,Zurich BT"">"  & "</FONT></TD>"
//	Print #nFile%, "</TR>"
//	Print #nFile%, "</TABLE>"

}

function footer( )
{
    w('</td>')
    w('</tr>')
    w('</table>')
    w('</div></td>')
    w('</tr>')
    w('</table>')
//    w('<form action=./donate.html method="post">')
//    w('<input type=image src=https://www.paypal.com/en_US/i/btn/x-click-but04.gif border=0 name=submit>')
//    w('<img alt="" border="0" src="https://www.paypal.com/en_AU/i/scr/pixel.gif" width="1" height="1">')
//    w('</form>')
//    w('<a href=./donate.html><img src=https://www.paypal.com/en_US/i/btn/x-click-but04.gif></a>')
    w('<table border=0 cellspacing=0 cellpadding=0 summary=navigator>')
    w('<tr valign=top align=left>')
    w('<td nowrap>')
    w('<p>[<a href="./default.html">Home</a>]&nbsp;[<a href="./news.html">News</a>]&nbsp;[<a href="./dives.html">Dive Log</a>]&nbsp;[<a href="./aboutme.html">About Me</a>]&nbsp;[<a href="./site_info.html">Site Info</a>]</p>')
    w('</td>')
    w('</tr>')
    w('</table>')
    w('</td>')
    w('</tr>')
    w('</table>')
    w('<table border=0 cellspacing=0 cellpadding=0 width=744 summary=formatting>')
    w('<tr valign=top align=left>')
    w('<td width=744 height=8><img src="./clearpixel.gif" alt="space" width=744 height=1 border=0></td>')
    w('</tr>')
    w('<tr valign=top align=left>')
    w('<td width=744>')
    w('<p align=center><font size="-1" face="arial,helvetica,univers,zurich bt,sans-serif">&#169; Copyright 1999-2012, ATJ</font></p>')
    w('</td>')
    w('</tr>')
    w('</table>')
    w('</body>')

}

function writeDuration( start, end )
{

    startDate = new Date( start )
    if ( end == '' )
    {
        endDate = new Date()
    }
    else
    {
        endDate = new Date( end )
    }

    years = 0
    months = 0
    days = 0

    years = endDate.getFullYear() - startDate.getFullYear()
    months = endDate.getMonth() - startDate.getMonth()
    days = endDate.getDate() - startDate.getDate()

    if (days < 0 )
    {
        monthLength = 30

        switch ( endDate.getMonth() )
        {
            case 0:
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
                monthLength = 31
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                monthLength = 30
                break;
            case 2:
                endYear = endDate.getFullYear();
                if ( (endYear % 4) == 0 )
                {
                    monthLength = 29
                }
                else
                {
                    monthLength = 28
                }
                break;
        }
        days = days + monthLength;
        months = months - 1;
    }

    if (months < 0 )
    {
        months = months + 12
        years = years - 1
    }

    if (years > 0 )
    {
        if (years == 1 )
        {
            document.write( years + ' year ' );
        }
        else
        {
            document.write( years + ' years ' );
        }
    }

    if (months > 0 )
    {
        if (months == 1 )
        {
            document.write( months + ' month ' );
        }
        else
        {
            document.write( months + ' months ' );
        }
    }

    if (days > 0 )
    {
        if (days == 1 )
        {
            document.write( days + ' day ' );
        }
        else
        {
            document.write( days + ' days ' );
        }
    }

}
function preloadImages()
{
   for (var i=0; i <= picture.length; i++)
   {
       image[i] = new Image;
       image[i].src = picture[i];
   }
}
function firstPicture()
{
   picNumber = numberofPics
   document.myPicture.src = image[picNumber-1].src;
   element = document.getElementById("caption");
   element.innerHTML = caption[picNumber-1];
}
function previousPicture()
{
   if(picNumber < numberofPics)
   {
     picNumber++
   }
   else
   {
     picNumber = 1;
   }
   document.myPicture.src = image[picNumber-1].src;
   element = document.getElementById("caption");
   element.innerHTML = caption[picNumber-1];
}
function previousPictureNoLoop()
{
   if(picNumber < numberofPics)
   {
     picNumber++
     document.myPicture.src = image[picNumber-1].src;
     element = document.getElementById("caption");
     element.innerHTML = caption[picNumber-1];
   }
}
function nextPicture()
{
   if(picNumber > 1)
   {
     picNumber--
   }
   else
   {
     picNumber = numberofPics;
   }
   document.myPicture.src=image[picNumber-1].src
   element = document.getElementById("caption");
   element.innerHTML = caption[picNumber-1];
}
function nextPictureNoLoop()
{
   if(picNumber > 1)
   {
     picNumber--
     document.myPicture.src=image[picNumber-1].src
     element = document.getElementById("caption");
     element.innerHTML = caption[picNumber-1];
   }
}
function LastPicture()
{
   picNumber = 1
   document.myPicture.src = image[picNumber-1].src;
   element = document.getElementById("caption");
   element.innerHTML = caption[picNumber-1];
}
function Play( b )
{
    bContinue = b
    if ( bContinue )
    {
       nextPicture();
       window.setTimeout("Play(bContinue)", 2000);
    }
}
function PlayNoLoop( f )
{
    fContinue = f
    if ( fContinue == 1 )
    {
        picNumber = numberofPics
        fContinue = 2
    }

    if (picNumber == 1 )
    {
        fContinue = 0
    }

    if ( fContinue > 0 )
    {
       nextPictureNoLoop();
       window.setTimeout("PlayNoLoop(fContinue)", 2000);
    }
}

function DiveMap ( location, displayedLocation, latitude, longitude, zoom, type )
{
    if (type != 'h' && type != 's' & type != 'm' )
    {
       type = 'h'
    }
    urlSite = 'http://maps.google.com/maps?f=q&hl=en&q=' + latitude + ',' + longitude + '+(' + displayedLocation + ')&ie=UTF8&om=1&z=' + zoom + '&t=' + type + '&iwloc=addr'
    w( '<a href=' + urlSite + ' target=GoogleMaps>' + location + '</a>' )
}

function DiveMap2 ( location, displayedLocation, latitude, longitude, latitude2, longitude2, zoom, type )
{
    if (type != 'h' && type != 's' & type != 'm' )
    {
       type = 'h'
    }
    urlSite = 'http://maps.google.com/maps?f=q&hl=en&saddr=' + latitude + ',' + longitude + '+(' + displayedLocation + ')&daddr=' + latitude2 + ',' + longitude2 + '&ie=UTF8&om=1&z=' + zoom + '&t=' + type + '&iwloc=addr'
    w( '<a href=' + urlSite + ' target=GoogleMaps>' + location + '</a>' )
}
function ATJsMarineAquariumSite( filename, text )
{
   w( '<a href=http://atj.net.au/marineaquaria/' + filename + ' target=ATJsMarine>'+text+'</a>' )
}

function VimeoVideo( VimeoID, CameraDetails )
{
   w( '<iframe src="http://player.vimeo.com/video/' + VimeoID + '?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=0" width="640" height="360" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>' )
   w( '<br><b>Video captured with ' + CameraDetails + '</b><br>' )
}
