//
// Navigation Bar & Text Links Specific Declarations
//

// Height and Width of the navigation images...
var NavImage_H = 40;
var NavImage_W = 135;

// Paw print effect image locations...
var NavPaw_0 = 0;
var NavPaw_1 = 2;
var NavPaw_2 = 1;

// Directory shorthand for NavBar images...
var NavGfx_d  = '/Common/Graphics/Navigation/';

// Text link line break interval, for auto-wrap determination
var NavText_Brk = 5;

// Common definition of the blank images....
var NavBlanks    = null;
var NavBlank_url =
    [
        NavGfx_d + 'Blank.jpg',
        NavGfx_d + 'Blank_2H.jpg',
        NavGfx_d + 'Blank_LtH.jpg',
        NavGfx_d + 'Blank_RtH.jpg'
    ];

var NavSeperator = null;

// Paw Gfx Basenames... Must be in order of appearance!
var _NavBaseNames = 
    [
        'Home', 'Philosophy',
        'Comm', 'Behavior', 'Energy', 'Flowers', 'Nutrition', 'Cystitis',
        'Consult', 'Workshops', 'Testimonials', 
        'About',
        'Links',
    ];

// NavImageURLs(idx)
//
// Constructor function used to create the array of URLs for each
// navigation link element.
//
// idx: index for _NavBaseNames array...
function NavImageURLs(idx, top)
{
    // Paw Gfx Suffixes...
    var npaw = '.jpg';
    var bpaw = '_2H.jpg';
    var lpaw = '_LtH.jpg';
    var rpaw = '_RtH.jpg';
    var base = top + NavGfx_d + _NavBaseNames[idx];

    return(new Array(base + npaw, base + bpaw, base + lpaw, base + rpaw));
}

// NavImages(w, h)
//
// Constructor function used to create an array of three Image() objects,
// which will define the walking paw effect.
//
// w:   image width
// h:   image height
function NavImages(num, w, h)
{
    var obj = new Array(num);
    for (var idx=0; idx < obj.length; idx++) obj[idx] = new Image(w, h);
    return(obj);
}

// Text and URL (relative to Site_Top) for each item on the Navigation Bar
//      Single point editing for Navigation information!
//
// name:    Text to be displayed in the Navigation Bar (optional)
// type:    The type of object to be added to the Navigation Bar
//          'link'      - standard hyper-link
//          'seperator' - horizontal rule
//          'blank'     - void space equal in size to a link
// url:     The target of the navigation Bar element relative to the
//          top of the site (leading '/' required) (optional)
var NavLinks =
    [
        {   type:   'blank' },
        {
            name:   'Home',
            type:   'link',
            url:    '/Home.html'
        },
        {
            name:   'Philosophy',
            type:   'link',
            url:    '/Resources/Philosophy.html'
        },
        {   type:   'blank' },
        {
            name:   'Animal Communication',
            type:   'link',
            url:    '/Services/Communication.html'
        },
        {
            name:   'Behavior',
            type:   'link',
            url:    '/Services/Behavior.html'
        },
        {
            name:   'Energy Healing',
            type:   'link',
            url:    '/Services/Energy.html'
        },
        {
            name:   'Bach Flower Essence',
            type:   'link',
            url:    '/Services/Flowers.html'
        },
        {
            name:   'Nutrition',
            type:   'link',
            url:    '/Services/Nutrition.html'
        },
        {
            name:   'Interstitial Cystitis',
            type:   'link',
            url:    '/Services/Cystitis.html'
        },
        {   type:   'blank' },
        {
            name:   'Consultations',
            type:   'link',
            url:    '/Services/Consultation.html'
        },
        {
            name:   'Workshops',
            type:   'link',
            url:    '/Services/Workshops.html'
        },
        {
            name:   'Testimonials',
            type:   'link',
            url:    '/Resources/Testimonials/index.html'
        },
        {   type:   'blank' },
        {
            name:   'About Karla',
            type:   'link',
            url:    '/About/index.html'
        },
        {   type:   'blank' },
        //{
        //    name:   'Books',
        //    type:   'link',
        //    url:    '/Resources/Books.html'
        //},
        {
            name:   'Links',
            type:   'link',
            url:    '/Resources/Links.html'
        },
        {   type:   'blank' }
      ];

// Nav_Init(top)
//
// Initialize our Navigation environment, pre-caching required graphics for
// better user experience.
//
// top: base site URL, or relative reference... so we can find all of our
//      resources within the site.
function Nav_Init(top)
{
    var blank_cnt = 0;
    var blanks    = new NavImages(4, NavImage_W, NavImage_H);
    var count     = 0;
    var images    = null;
    var link_cnt  = 0;
    var sep_cnt   = 0;

    // Pre-Cache blank graphics...
    for (var idx=0; idx < NavBlank_url.length; idx++)
        blanks[idx].src = top + NavBlank_url[idx];
    NavBlanks = blanks;

    // Define the walking paw order/placement
    for ( var idx=0; idx < NavLinks.length; idx++ )
    {
        images = new NavImages(3, NavImage_W, NavImage_H);
        // Set/Cache the graphics for this nav element...
        switch ( NavLinks[idx].type )
        {
            case 'blank':
                NavLinks[idx].gfx  = NavBlank_url;
                NavLinks[idx].name = '';
                images[NavPaw_0]  = blanks[NavPaw_0];
                //images[NavPaw_1]  = blanks[2 + (idx % 2)];
                //images[NavPaw_2]  = blanks[NavPaw_2];
                count = blank_cnt++;
                break;
            case 'link':
                NavLinks[idx].gfx    = new NavImageURLs(link_cnt, top);
                images[NavPaw_0].src = NavLinks[idx].gfx[NavPaw_0];
                count = link_cnt++;
                break;
            case 'seperator':
                count = sep_cnt++;
                continue;
        }

        // Generate the ID value for this nav element...
        NavLinks[idx].id     = 'nav_' + NavLinks[idx].type + '_' + count;
        NavLinks[idx].images = images;
        NavLinks[idx].url    = top + NavLinks[idx].url;
    }

    //for ( var idx=0; idx < NavLinks.length; idx++ )
    //{
    //    if ( NavLinks[idx].type != 'link' ) continue;
    //    NavLinks[idx].images[NavPaw_1].src = NavLinks[idx].gfx[2 + (idx % 2)];
    //    NavLinks[idx].images[NavPaw_2].src = NavLinks[idx].gfx[NavPaw_2];
    //}
}

//
// Navigation Bar (Left Column) Functions
//

// Auto Generate the HTML code for the Navigation Bar
function NavBar_Create(page_id)
{
    // Open the NavBar... self-contained <div>
    document.writeln('<div class=NavBar onload="Nav_LoadPaws();" width=', NavImage_W, '>');

    // Generate the Navigation Bar...
    for ( var idx=0; idx < NavLinks.length; idx++ )
    {
        // Dynamic output elements...
        var href_url   = 'javascript: void(0);';            // Do nothing!
        var image_name = ((isN4)?' name="':' id="') + NavLinks[idx].id + '"';
        var image_src  = ' src="' + NavLinks[idx].images[NavPaw_0].src + '"';

        // Set real href IFF necessary
        if ( (NavLinks[idx].type == 'link') &&
             (NavLinks[idx].name != page_id) ) href_url = NavLinks[idx].url;

        switch ( NavLinks[idx].type )
        {
            case 'link':
            case 'blank': // Add hover effects...
                var down = idx + ', ' + NavPaw_2;
                var out  = idx + ', ' + NavPaw_0;
                var over = idx + ', ' + NavPaw_1;

                document.writeln('<a class=NavBar href="', href_url, '"',
                                   ' onmousedown="NavBar_Paw(', down, ');"',
                                   ' onmouseout=" NavBar_Paw(', out,  ');"',
                                   ' onmouseover="NavBar_Paw(', over, ');">');
                                   //'>');

            default:      // Load the 'inactive' Paw image
                //document.writeln('<img alt="', NavLinks[idx].name ,'" border=0 class=NavBar',
                //                       image_name, image_src, '></a><br>');
                document.writeln('<img alt="" border=0 class=NavBar',
                                       image_name, image_src, '></a><br>');
                NavLinks[idx].image_obj =
                    (document.all)? document.all[NavLinks[idx].id] :
                                    document.images[NavLinks[idx].id];
                break;

            case 'seperator':
                document.writeln('<hr width="95%">');
                break;
        }
    }

    // Close the NavBar!
    document.writeln('</div>');
    Nav_LoadPaws();
}

// Nav_LoadPaws()
//
// Initialize our Navigation environment, pre-caching required graphics for
// better user experience.
//
function Nav_LoadPaws()
{
    var blanks    = NavBlanks;
    var images    = null;

    // Define the walking paw order/placement
    for ( var idx=0; idx < NavLinks.length; idx++ )
    {
        images = NavLinks[idx].images;
        // Set/Cache the graphics for this nav element...
        switch ( NavLinks[idx].type )
        {
            case 'blank':
                images[NavPaw_1]  = blanks[2 + (idx % 2)];
                images[NavPaw_2]  = blanks[NavPaw_2];
                break;
            case 'link':
                images[NavPaw_1].src = NavLinks[idx].gfx[2 + (idx % 2)];
                images[NavPaw_2].src = NavLinks[idx].gfx[NavPaw_2];
                break;
            case 'seperator':
                continue;
        }
    }
}

// Active the indicated Paw...
//  idx: index of the link that will be altered
//  paw: index into the images array
function NavBar_Paw(idx, paw)
{
    NavLinks[idx].image_obj.src = NavLinks[idx].images[paw].src;
}

//
// Navigation Text Links (Footer) Functions
//

// Auto Generate the HTML code for the Navigation Text Links (footer)
function NavText_Create(page_id)
{
    var link_cnt = 0;

    // Generate the Navigation Text Links...
    document.writeln('<em class=NavText>');
    for ( var idx=0; idx < NavLinks.length; idx++ )
    {
        if ( NavLinks[idx].type != 'link' ) continue;
        // No leading seperator...
        if ( (link_cnt++ % NavText_Brk) != 0 ) document.writeln(' &#124; ');
        else if ( link_cnt != 1 )              document.writeln('<br>');
        document.write('<a');
        if ( page_id != NavLinks[idx].name )
            document.write(' href=', NavLinks[idx].url);
        document.writeln('>', NavLinks[idx].name, '</a>');
    }
    document.writeln('</em><br>');
}
