// JavaScripts for Joyce and Peter Froome's Web pages
//
//-----------------------------------------------------
// History
//
// V0.2  28/04/2001 (Peter Froome)
// Modified for site version 5.1
//
// V0.1  Created 01/07/2000 (Peter Froome)
// The first version of the JavaScripts
//
//------------------------------------------------------

// Image swapping functions

function flipImage(name, url)
{
    if ( document.images )
    {   document.images[name].src = path+url
    }
}

// Open an information window

function openInfoWin(url)
{
    window.open(url, "_blank", "width=590,height=430,scrollbars=yes,resizable=yes")
}

// Scroll the browser window to bottom right

function scrollBmRt()
{ if ( window.scrollBy )
	{ scrollBy(1000,1000)
	}
}


// Set up the page header according to the browser etc.
// It uses the following global variables:
//   pagetype: string is "home", "books", etc.
//   path: string is the path to the top level

function tailorHeader()
{
    // Select the CSS for the browser
    if ( is.brV5up )
    {   document.write('<link rel="stylesheet" type="text/css" href="' + path);
        if ( is.brMac )
        {   document.write('includes/jandpfmac.css">')
        }
        else
        {   document.write('includes/jandpf.css">')
        }
    }
    else if ( is.brV4 && is.brIE )
    {   document.write('<link rel="stylesheet" type="text/css" href="' + path);
        if ( is.brMac )
        {   document.write('includes/jandpfie4mac.css">')
        }
        else
        {   document.write('includes/jandpf.css">')
        }
    }
    else if ( is.brV4 && is.brNS )
    {   document.write('<link rel="stylesheet" type="text/css" href="' + path);
        if ( is.brMac )
        {   document.write('includes/jandpfns4mac.css">')
        }
        else
        {   document.write('includes/jandpfns4.css">')
        }
    }
    else
    {	document.write('<link rel="stylesheet" type="text/css" href="' + path);
    	document.write('includes/jandpf.css">')
    }
}

// Reloads NS4 window after resize

function handleResize()
{
    location.reload();
    return false
}

// Actions to be performed when onload event occurs.
// It uses the same global variables as 'tailorHeader'

function loadActions()
{
    // Swap logo
    if ( pagetype == "home" )
    {   flipImage("mercat", "images/mercat5.gif")
    }
    else if ( pagetype == "artwork" )
    {   flipImage("mercat", "images/mercat5_palette.gif")
    }
    else if ( pagetype == "about" )
    {   flipImage("mercat", "images/mercat5_palette.gif")
    }

    // Handle NS4 resize
    if ( is.brNS && is.brV4 )
    {
        // Handle resize
        window.setTimeout("window.captureEvents(Event.RESIZE);window.onresize = handleResize", 1000)
    }
}

// This displays the visitor's browser version and OS

function writeBrowserInfo()
{
    document.write("<p>You are running ");
    document.write(navigator.appName);
    if (is.brver != "unknown")
    {   document.write(" version ");
        document.write(is.brver + " on " + is.brOS)
    }
    document.write(".</p>");
    if ( is.brV4 || is.brV5up )
    {   document.write("\n<p>Your screen area is ");
        document.write(screen.width + " by " + screen.height + " pixels");
        document.write(" and the colour display is " + screen.colorDepth + " bits per pixel.</p>")
    }
}

// This function detects the browser, version and OS
// .br: string - browser name
// .brver: string - browser version
// .brOS: string - OS
// .brMac: boolean
// .brWin: boolean
// .brIE: boolean
// .brNS: boolean
// .brV3dn: boolean - true if version <= 3
// .brV4: boolean
// .brV5up: boolean - true if version >= 5

function sniffBrowserVer()
{
    var p1=0, p2=0;
    var ver=navigator.appVersion;
    
    this.br = navigator.appName;
    this.brIE = this.br.indexOf("Microsoft") != -1;
    this.brNS = this.br.indexOf("Netscape") != -1;
    
    if ( this.brIE )
    {   p1 = ver.indexOf("MSIE") + 5;
        p2 = ver.indexOf(";", p1);
        this.brver = ver.substring(p1, p2);
        p1 = p2 + 2;
        p2 = ver.indexOf(";", p1) > p1 ? ver.indexOf(";", p1) : ver.indexOf(")", p1);
        this.brOS = ver.substring(p1, p2);
    }
    else if ( this.brNS )
    {   p2 = ver.indexOf(" ");
        this.brver = ver.substring(0, p2);
        if ( this.brver == "5.0" )
        {	this.brver = "6.0"
        }
        p1 = ver.indexOf("(", p2) + 1;
        p2 = ver.indexOf(";", p1);
        this.brOS = ver.substring(p1, p2);
    }
    else
    {   this.brver = ver;
        this.brOS = "";
    }
    this.brMac = this.brOS.indexOf("Mac") != -1;
    this.brWin = this.brOS.indexOf("Win") != -1;
    this.brV3dn = parseInt(this.brver) <= 3;
    this.brV4 = parseInt(this.brver) == 4;
    this.brV5up = parseInt(this.brver) >= 5
}

var is = new sniffBrowserVer();

