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

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

    w('<body onLoad="preloadImages()" bgcolor="#000000" text="#ffffff" link="#0000ff" vlink="#800080" topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>')
    w('<table border=0 cellspacing=0 cellpadding=0 width=930 summary=banner>')
    w('<tr valign=top align=left>')
    w('<td height=50 bgcolor="#000000" align=center valign=middle><span class="banner"><a href=./>Andrew Trevor-Jones - Nature Photography</a></span></td>')
    w('</tr>')
    w('</table>')

    w('<div class="nav">')
    w('<table border=0 cellspacing=0 cellpadding=0 width=930 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>')
    w('<td width=80 height=30 align=center>&nbsp;</td>')
    w('<td width=40 height=30 align=center><a href=./aboutme.html>&nbsp;About</a></td>')
    w('<td width=40 height=30 align=center><a href=./blog.html>&nbsp;Blog</a></td>')
    w('<td width=40 height=30 align=center><a href=./feedback.html>&nbsp;Feedback</a></td>')
    w('<td width=40 height=30 align=center><a href=./galleries.html>&nbsp;Galleries</a></td>')
    w('<td width=40 height=30 align=center><a href=./publications.html>&nbsp;Publications</a></td>')
    w('<td width=40 height=30 align=center><a href=./copyright.html>&nbsp;Purchase</a></td>')
    w('</tr>')
    w('</table>')

    w('</td>')
    w('</tr>')
    w('</table>')
    w('</div>')


    w('<table cellpadding=0 cellspacing=0 border=0 width=930 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>')
    }

    w('</table>')
    w('</td>')
    w('</tr>')
    w('</table>')
    w('</div>')
    w('</td>')
    w('<td>')
    w('<table border=0 cellspacing=0 cellpadding=0 width=780 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=673 summary=content>')
//        w('<br>' + mainArea + '->' + category + '->' + subCategory + '->' + menuItem + '<br><br>' )
    }
    w('<tr align=left valign=top>')
    w('<td>')
    w('<span class="head"><p align=center><b>' + mainArea + '</b></p></span>')
}

function footer( )
{
    w('</td>')
    w('</tr>')
    w('</table>')
    w('</div></td>')
    w('</tr>')
    w('</table>')
    w('<table border=0 cellspacing=0 cellpadding=0 summary=navigator>')
    w('<tr valign=top align=left>')
    w('<td nowrap>')
    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=195>&nbsp;</td>')
    w('<td width=600>')
    w('<p align=left><span class=lnk><a href=./copyright.html>&#169; Copyright 2007-2010 Andrew Trevor-Jones</a></span></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()
{
   var ref = document.getElementById('url');

   if (ref != null)
   {
      ref.value = document.referrer;
   }

   if (picture != undefined )
   {
      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 MapIt ( 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> (Map It)</a>' )
}