// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var Feature = {
  rotate: function(element) {
    Feature.stopLoop();
    Feature._rotate(element);
    Feature.startLoop(30000);
  },
  next: function() {
    var nextIndex = Feature.list.indexOf(Feature.current) + 1;
    if (nextIndex > 0 && nextIndex < Feature.list.length) {
      Feature._rotate(Feature.list[nextIndex]);
    } else {
      Feature._rotate(Feature.list[0]);
    }
  },
  startLoop: function(arg) {
    Feature.next_timeout = setTimeout(Feature.nextLoop, arguments[0] || 5000);
  },
  stopLoop: function() {
    clearTimeout(Feature.next_timeout);
  },
  nextLoop: function() {
    Feature.next();
    Feature.startLoop();
  },
  _rotate: function(element) {
    if (element != Feature.current) {
      $(Feature.current + '_menu').removeClassName('active');

      Effect.Fade(Feature.current);
      Effect.Appear(element);
    
      Feature.current = element;
  
      $(Feature.current + '_menu').addClassName('active');
    }
  }
}

var Times = {
	toggle: function(checked) {
		var no_end_time = $('event_no_end_time')

		no_end_time.disabled = checked;
		Times.toggle_by_name('start_time', checked);
		
		if (!checked && no_end_time.checked) {
			Times.toggle_by_name('end_time', true);
		} else {
			Times.toggle_by_name('end_time', checked);
		}
	},
	
	toggle_by_name: function(name, checked) {
		matcher = new RegExp('^' + name);
		
		$$('select').each(function(element) {
		  if (element.name.match(matcher)) {
		    element.disabled = checked;
		  }
		});
	}
}
