/********************************
 * site-specific settings       *
 ********************************/

var showRolloverMenuEffect = Effect.BlindDown;
var showRolloverMenuEffectOptions = { duration: 0.2 };
var hideRolloverDelay = 150;
var hideRolloverMenuEffect = Effect.BlindUp;
var hideRolloverMenuEffectOptions = { duration: 0.2 };

/********************************
 * site-specific functions      *
 ********************************/

function addMenuHandlers() {
    $$('.nav_section').each(function (el) {
        el.onmouseover = function () {
            showSimpleRollover(this.id, 0, 24);
        };
        el.onmouseout=function() {
            hideSimpleRollover(this.id);
        };
    });
    
    $$('.nav_menu').each(function (el) {
        el.onmouseover = function () {
            el.addClassName('nav_menu_hover');
            showSimpleRolloverMenu(this.id, 150, 120, true);
        };
        el.onmouseout = function () {
            el.removeClassName('nav_menu_hover');
            hideSimpleRolloverMenu(this.id);
        };
    });
}

function moveTopNav() {
    $('top_nav').innerHTML = $('top_nav_source').innerHTML;
    $('top_nav_source').innerHTML = '';
}

function changeGalleryImage(galleryName, index) {
    var target = galleryName + '_image_' + index;
    var caption = galleryName + '_caption_' + index;
    if (!$(target)) return false;

    var queue = Effect.Queues.get('global');
    queue.each(function(e) { e.cancel() });

    for (var i = 0; i < gallerySize[galleryName]; i++) {
        el = $(galleryName + '_image_' + i);
        if (el.id != target && el.style.display != 'none') Effect.Fade(el, { duration: 0.6 });

        el = $(galleryName + '_thumb_' + i);
        if (i == index) {
            el.style.borderColor = 'white';
            el.onmouseover = null;
            el.onmouseout = null;
        } else {
            el.style.borderColor = '#5D5D5D';
            el.onmouseover = function () { el.style.borderColor = 'white' };
            el.onmouseout = function () { el.style.borderColor = '#5D5D5D' };
        }
    }

    Effect.Appear(target, { duration: 0.6 });

    if($(caption).innerHTML != '') {
        $(galleryName + '_caption').style.display = 'block';
        $(galleryName + '_caption').innerHTML = $(caption).innerHTML;
    } else {
        $(galleryName + '_caption').style.display = 'none';
    }

    prevIndex = index == 0 ? gallerySize[galleryName] - 1 : index-1;
    nextIndex = index == gallerySize[galleryName] - 1 ? 0 : index+1;
    $(galleryName + '_prev_button').onclick = function () { changeGalleryImage(galleryName, prevIndex) };
    $(galleryName + '_next_button').onclick = function () { changeGalleryImage(galleryName, nextIndex) };
}

function startSlideShow(galleryName) {
  if (typeof(galleryName) == 'undefined') galleryName = 'gallery_1';
  showDojoDialog('slideshow');
  $(galleryName + '_play_button').onclick();
}

function stopSlideShow(galleryName) {
  if (typeof(galleryName) == 'undefined') galleryName = 'gallery_1';
  hideDojoDialog('slideshow');
  $(galleryName + '_pause_button').onclick();
}




// format is [ min_max, rate_1st_year, rate_2nd_year ]
var rt_family = [
  [ '$74,500+',          '$85', '$79' ],
  [ '$59,600 - 74,499',  '$73', '$67' ],
  [ '$37,250 - 59,599',  '$61', '$55' ],
  [ '$37,249 and below', '$49', '$43' ]
];
var rt_teen = [
  [ '$74,500+',          '$22', '$22' ],
  [ '$59,600 - 74,499',  '$19', '$19' ],
  [ '$37,250 - 59,599',  '$15', '$15' ],
  [ '$37,249 and below', '$12', '$12' ]
];
var rt_single_parent = [
  [ '$67,100+',          '$70', '$64' ],
  [ '$53,650 - 67,099',  '$60', '$54' ],
  [ '$33,550 - 53,649',  '$51', '$45' ],
  [ '$33,549 and below', '$41', '$35' ]
];
var rt_adult = [
  [ '$52,200+',          '$51', '$45' ],
  [ '$41,700 - 52,199',  '$44', '$38' ],
  [ '$26,100 - 41,699',  '$38', '$32' ],
  [ '$26,099 and below', '$31', '$25' ]
];
var rt_senior = [
  [ '$52,200+',          '$47', '$41' ],
  [ '$41,700 - 52,199',  '$41', '$35' ],
  [ '$26,100 - 41,699',  '$35', '$29' ],
  [ '$26,099 and below', '$29', '$23' ]
];

var rates = [];
rates['family'] = rt_family;
rates['teen'] = rt_teen;
rates['single_parent'] = rt_single_parent;
rates['adult'] = rt_adult;
rates['senior'] = rt_senior;

function setIncomeRanges() {
    rate_table = $('calc_rate_table').value;
    
    if (rates[rate_table]) {
        $('calc_income_range').disabled = '';
        
        for (var i = 0; i < $('calc_income_range').options.length; i++) {
            $('calc_income_range').options[i] = null;
        }
        
        i = 0;
        var opt = document.createElement('option');
        opt.text = "-- Please Select --";
        $('calc_income_range').options[i++] = opt;
        
        $A(rates[rate_table]).each(function (rate) {
            var opt = document.createElement('option');
            opt.text = rate[0];
            opt.value = '' + i;
            $('calc_income_range').options[i++] = opt;
        });
    } else {
        $('calc_income_range').disabled = 'disabled';
        prompt = $('calc_income_range').options[0];
        if (prompt) prompt.text = '-- Please Select Type --';
    }
    
    setRates();
}

function setRates() {
    table = rates[$('calc_rate_table').value]
    rate_index = parseInt($('calc_income_range').value);
    
    if (rate_index > 0) {
        rate = table[rate_index-1];
        if (rate) {
            $('rate-first-year').innerHTML = rate[1];
            $('rate-second-year').innerHTML = rate[2];
            return true;
        }
    }
    
    // if we made it to here, must have been some kind of error, or nothing valid was selected
    $('rate-first-year').innerHTML = '$ --';
    $('rate-second-year').innerHTML = '$ --';
    return false;
}
