
var globalCurrentHighlight = "divBannerItem1";
var debug = 0;

function InitJS()
    {
    var id;
//    alert( globalBaseURL);

    // determine page highlight
    // horizontal tabs
//    if ( globalPostName == 'home') // page name
//        id = 'divBannerItem1';


    // highlight
//    SetCurrentHighlight ( id);

    // fix columns
    SetColumnHeights( 'divMainContainer', 'divSidebarLeft', 'divSidebarRight', 37);

    SetColumnHeights( 'divMainContainer', 'divSepVertLeft', 'divSepVertRight', 0);

    SetSlide( '', 0);

    }

//
function BuildImageName( filename)
    {
    var name;

    name = "url(" + globaltemplateURL + "/images/" + filename + ")";

//    alert( name);
    return( name);
    }

function RandomIndex()
    {
    var ran_unrounded=Math.random()*15; // returns 0->(n-1)
    var ran_number=Math.floor(ran_unrounded);



    return( ran_number);
    }

// Set a slide
function SetSlide( id, index)
    {

    if ( debug) return;

    index = RandomIndex();
    id = 'divMainSlide';
    filename = 'slides/slideshow_raw';
    filename += index + '.jpg';

//alert( filename);

    if ( d = document.getElementById( id))
        d.style.backgroundImage = BuildImageName( filename);

    // start the js action,
    ds.Start( 'divMainSlide', 0, 600, 1);
    }



//
function SetCurrentHighlight ( id)
    {
    globalCurrentHighlight = id;

    return;

    if ( debug) return;

    // change color
//    document.getElementById( id).style.backgroundColor = '#E1D2E7';

    // only do this for divBannerItem elements
    var name = id.substring( 0, 9);
    if ( name == 'divBanner')
        {
        document.getElementById( id).style.backgroundImage = BuildImageName( 'tab_on.jpg');
        document.getElementById( id).style.borderBottom = '1px solid #E1D2E7';
        }
    else // divBrowse
        {
//        document.getElementById( id).style.backgroundImage = "url('http://babystayasleep.andregagnon.com/images/button_on.jpg')";
//        document.getElementById( id).style.backgroundImage = "url('" + globalBaseURL + "/images/button_on.jpg')";
        document.getElementById( id).style.backgroundImage = BuildImageName( 'button_on.jpg');
        }

//    alert( globalCurrentHighlight);  // test
    }

// highlight a horizontal tab
function HighlightTab ( id, on)
    {
    return;

    if ( debug) return;

    if ( on == true)
        {
        // change color
        document.getElementById( id).style.backgroundImage = BuildImageName( 'tab_on.jpg');
        document.getElementById( id).style.borderBottom = '1px solid #E1D2E7';
        }
    else
        {
        if ( id != globalCurrentHighlight)
            {
            // change color
            document.getElementById( id).style.backgroundImage = BuildImageName( 'tab_off.jpg');
            document.getElementById( id).style.borderBottom = '1px solid #FDEF97';
            }
        }
    }


// highlight a left column navigation button
function HighlightButton ( id, on)
    {
    return;

    if ( debug) return;

    if ( on == true)
        {
//        document.getElementById( id).style.backgroundColor = '#E1D2E7';
//        document.getElementById( id).style.backgroundImage = "url('http://babystayasleep.andregagnon.com/images/button_on.jpg')";
//        document.getElementById( id).style.backgroundImage = "url('" + globalBaseURL + "/images/button_on.jpg')";
        document.getElementById( id).style.backgroundImage = BuildImageName( 'button_on.jpg');
        }
    else
        {
        if ( id != globalCurrentHighlight)
//            document.getElementById( id).style.backgroundImage = "url('http://babystayasleep.andregagnon.com/images/button_off.jpg')";
//            document.getElementById( id).style.backgroundImage = "url('" + globalBaseURL + "/images/button_off.jpg')";
            document.getElementById( id).style.backgroundImage = BuildImageName( 'button_off.jpg');
//            document.getElementById( id).style.backgroundColor = '#FDEF97';
        }
    }


function SetColumnHeights( id1, id2, id3, offset)
    {
    // find the height of the tallest column, set the columns
    var h, h1, h2, h3;
    var d1 = document.getElementById( id1);
    var d2 = document.getElementById( id2);
    var d3 = document.getElementById( id3);

    if ( d1 && d2 && d3)
    {

    h1 = d1.offsetHeight;
    h2 = d2.offsetHeight;
    h3 = d3.offsetHeight;

//    alert( ' d1 oh ' + d1.offsetHeight);
//    alert( ' d2 oh ' + d2.offsetHeight);
//    alert( ' d3 oh ' + d3.offsetHeight);

    h = h1;
    if ( h2 > h)
        h = h2;
    if ( h3 > h)
        h = h3;

//    h = h + "px";

//    alert( '1 dml h ' + document.getElementById( 'div_menuleft').style.height);
//    alert( '1 dr h ' + document.getElementById( 'div_right').style.height);

    var hMod = h - offset; // ? unique to layout

    document.getElementById( id1).style.height = (hMod) + "px";
    document.getElementById( id2).style.height = h + "px";
    document.getElementById( id3).style.height = h + "px";

//    alert( '2 dml h ' + document.getElementById( 'div_menuleft').style.height);
//    alert( '2 dr h ' + document.getElementById( 'div_right').style.height);

    }
//    else
//        alert( 'column div ids?');

    }
