/**
* Returns the value of the selected radio button in the radio group, null if
* none are selected, and false if the button group doesn't exist
*
* @param {radio Object} or {radio id} el
* OR
* @param {form Object} or {form id} el
* @param {radio group name} radioGroup
*/
function $RF(el, radioGroup) {
    if($(el).type && $(el).type.toLowerCase() == 'radio') {
        var radioGroup = $(el).name;
        var el = $(el).form;
    } else if ($(el).tagName.toLowerCase() != 'form') {
        return false;
    }
 
    var checked = $(el).getInputs('radio', radioGroup).find(
        function(re) {return re.checked;}
    );
    return (checked) ? $F(checked) : null;
}

var current_home_photo = 'home-photo-1';
var current_timeout_id = -1;

function swapFade(home_photo) {
  if (home_photo == current_home_photo) { return; }

  Effect.Fade(current_home_photo, { duration: 1, from: 1.0, to: 0.0 });
  Effect.Appear(home_photo, { duration: 1, from: 0.0, to: 1.0 });

  current_home_photo = home_photo;

  clearTimeout(current_timeout_id);
  current_timeout_id = setTimeout("swapFade('" + nextHomePhoto() + "')", 5000);
}

function nextHomePhoto() {
  next_index = parseInt(current_home_photo.substring(
    current_home_photo.length - 1)) + 1;

  if (next_index > 5) { next_index = 1; }

  return('home-photo-' + next_index);
}

Event.observe(window, 'load', function() {
  setTimeout("swapFade('home-photo-2')", 5000);
});