jQuery(document).ready(function(){
	
/* Flash */
	$("#flash p")
		.animate({ opacity: 1 }, 6000)
		.animate({ height: 0, paddingBottom: 0, paddingTop: 0 }, 500)
		.animate({ border: 0 }, 1); 

/* Autofocus */
	$('form input.autofocus').each(function () { this.focus(); });

/* Stripes */
  $('table.add_stripes').each(function () {
		$(this).removeClass('add_stripes'); 
    $(this).find('tr:odd').addClass('odd'); 
    $(this).find('tr:even').addClass('even'); 
	});
	
/* List options */
  $('ul.items').each(function () {
		var $list = $(this); 
		var classes = $list.attr('class').split(/\s+/); 
		for (var i = 0; i < classes.length; ) {
			if (classes[i].match(/^displayable_as_.+/)) i++; 
			else classes.splice(i, 1); 
		}
		if (classes.length < 1) return;
		var $display_list = $('<ul class="display options" />'); 
		for (var i = 0; i < classes.length; i++) {
			var option = classes[i].replace(/^displayable_as_/, ''); 
			$display_list.append(
        $('<li />')
				  .append($('<span />').text(option))
					.addClass(option)
					.addClass($list.hasClass(option) ? 'selected' : null)
					.click(function () {
						if ($(this).hasClass('selected')) return;
						$display_list.find('li.selected').removeClass('selected').each(function () { $list.removeClass($(this).attr('class')); });
						$list.addClass($(this).attr('class')); 
						$(this).addClass('selected'); 
					})
			); 
		} 
		$display_list.attr('id', this.id+'_display_options'); 
		var $h2 = $('#'+this.id+'_title'); 
		if ($h2.size() > 0) {
			$h2.addClass("with display options"); 
			$h2.before($display_list); 
		} else {
      $list.before($display_list); 
		}
	}); 
});
