/*
	JavaScript for The Job Finding Centre
	Author: Nick Strupat
	Date: August 2008
*/

var pages = new Array();
var currentPage;

window.addEvent( 'domready', function()
{
    // Build array of elements using the anchors in the navigation list
    $( 'navigation' ).getElements( 'a' ).each( function( navLink )
    {
        pages.push( $( navLink.getProperty( 'href' ).substring(1) ) );
    } );
    
    // Start infinite check loop
    setInterval( check, 10 );
} );

function navigate( page )
{
    // Scroll to the top
    scrollTo( 0, 0 );
    
    // Hide all pages
    pages.each( function( page )
    {
        page.setStyle( 'display', 'none' );
    } );
    
    // Show the page
    page.setStyle( 'display', 'block' );
}

function check()
{
    if( currentPage != location.hash )
    {
        // Check the hash and navigate to that page
        if( !location.hash )
        {
            // No hash, navigate to the first page
            navigate( pages[0] );
        }
        else
        {
            pages.each( function( page )
            {
                if( "#" + page.id == location.hash )
                    // Hash matches one of the page ids, navigate to it
                    navigate( page );
            } );
        }
    
        currentPage = location.hash;
    }
}