window.start = false

global = window


trace = function( text )
    {
    var DEBUG = 0
    if ( DEBUG ) alert( text )
    }

onLoad = function()
    {
    window.start = true
    if ( ! window.iHistory ) 
        {
        window.iHistory = history.length
        trace( 'iHistory entry ' + window.iHistory )
        }

    // Is there a search?
    var search = window.location.search
    if ( search )
        {

        search = unescape( search )
        parts = search.split( '?' )
        var find = parts[ 1 ]

        // Autostart at slide number?
        find = find.match( /\d+/, find )
        window.autostart = find

        }

    // Is there a hash?
    var hash = window.location.hash
    if ( hash )
        {

        hash = unescape( hash )
        parts = hash.split( '#' )
        var find = parts[ 1 ]

        // Autostart at slide number?
        find = find.match( /\d+/, find )
        window.autostart = find

        }

    control_pane.location.reload( true )
    choose_pane.location.reload( true )

    }
onViewLoaded = function()
    {
    // Disabled - some shows include long slides by default
    // on first showing.
    return
    // Make sure newly added items during slide presentations
    // always appear by scrolling window down, if necessary.
    if ( 0 != slideIndex ) view_pane.scrollTo(0, screen.height )
    }

function onePane()
    {
    var href = global.location.href
    return ( -1 != href.search( 'onepane.htm' ) ) 
    }
    

// One problem we have with capturing keystrokes is that we don't
// control the content of the slides which are shown within the view_pane.
// Therefore, when a person clicks on a link on a slide or otherwise
// interacts with it, the focus moves away and we no longer get key
// events.  We work around this by forcing focus to return to our
// window periodically.
function onTimeoutFocusHolder()
    {
    timeoutID=setTimeout("onTimeoutFocusHolder()", 5000);
    global.focus()
    }

// If running in one pane.
if ( onePane() ) 
    {
    // No audio.
    global.play = false
    // Retain focus.
    timeoutID=setTimeout("onTimeoutFocusHolder()", 1000); 
    }

function onTimeoutEscape()
    {
    var url = './index.htm'
    if ( ! global.onePane() ) url = './onepane.htm'
    window.location.href = url
    }


// Key press events.
onKey = function( inEvent )
    {
    var key = undefined
    var code = undefined
    // Non-IE event.
    if ( inEvent )
        {
        key = inEvent.which
        key = inEvent.keyCode
        }
    // IE event?
    else
        {
        if ( window.event ) key = window.event.keyCode
        }
    trace( 'key + ' + key )
    var handled = false
    switch ( key )
        {
        case 27 :
            //trace( 'Escape' )
            //top.location.href="index.htm"
            if ( inEvent.shiftKey )
                {
                var timeoutID=setTimeout("onTimeoutEscape()", 1000);
                handled = true
                }
            break;
        case 32 :
            trace( 'Space Bar' )
            // Leave this to pause/continue audio playback in regular mode.
            if( onePane() ) 
                {
                global.onNext()
                handled = true
                }
            break;
        case 33 :
            trace( 'Page up' )
            // Leave page up for scrolling.
            //global.onPrevious()
            //handled = true
            break;
        case 34 :
            trace( 'Page down' )
            // Leave page down for scrolling.
            //global.onNext()
            //handled = true
            break;
        case 37 :
            trace( 'Left arrow' )
            global.onPrevious()
            handled = true
            break;
        case 39 :
            trace( 'Right arrow' )
            global.onNext()
            handled = true
            break;
        case 38 :
            trace( 'Up arrow' )
            global.onPrevious()
            handled = true
            break;
        case 40 :
            trace( 'Down arrow' )
            global.onNext()
            handled = true
            break;
        case 13 :
            trace( 'Return' )
            global.onNext()
            handled = true
            break
        case 8 :
            trace( 'Backspace' )
            // ALWAYS DISABLED - DEFAULT OPERATION WORKS AS EXPECTED
            if( false && onePane() ) 
                {
                global.onPrevious()
                handled = true
                }
            break
        default :
            trace( 'Unknown ' + key )
        }
    trace( 'Handled ' + handled )
    return (! handled )
    }


