
var current_link = null;
var current_button = null;
var timer = null;

// build the subnav HTML, we
// could cache this if needed
function make_subnav(item) {

    var right_align = false;
    var html = '';

    if (item == 'dining' || item == 'specials' || 
        item == 'meetings' || item == 'real_estate')
        right_align = true;

    if (right_align) html = '<div style="text-align:right; padding-right:32px;">'; 

    html += "\t<ul>\n";
    var fclass = '';

    var index = 0;
    for (element in subnav[item]) {
        fclass = (index++ == 0) ? ' class="first" ' : '';
        html += "\t\t<li"+fclass+"><a href='"+subnav[item][element]+
            "' onclick=\"switch_leftnav('" + element + "');\">" + element +"</a></li>\n";
    }    
    html += "\t\t</ul>\n";    
    if (right_align) html += '</div>'; 
    return html;
}

// switch subnav to match current highlighted button
function switch_subnav(e, nav) {
    rollback();
    current_button = e;
    $(e).setStyle({backgroundPosition: '0 -23px'});
    clear_revert();
    $("subnav").innerHTML = make_subnav(nav);    
}

// the delayed callback 
function revert_callback() {

    rollback();
    clear_revert();

    if (!current_link) 
        $("subnav").innerHTML = "";    
    else
        $("subnav").innerHTML = make_subnav(current_link);    
}

// revert to selected nav button
// after a short delay
function revert_subnav() {
    timer = setInterval(revert_callback, 300);
}

// stop countdown to revert
function clear_revert() {
    if (timer) clearInterval(timer);
    timer = null;
}

// undo rollover
function rollback() {
    if (!current_button) return;

    // see if button needs to be red or blue
    var selected_button = document.getElementsByClassName('selected'); 
    
    // shift bg image
    if (selected_button[0] == current_button) {
        current_button.setStyle({'background-position': '0 0'});
    } else {
        current_button.setStyle({'background-position': '0 -46px'});
    }

    // button is no longer "current"
    current_button = null;
}


function switch_leftnav(nav) {
    //$("area_header_content").innerHTML = nav;    
}








