$(document).ready(function() {
	
	var FOCUSELTS = 'input, select, textarea'
	
    // rewrite sound links
    
	$('a.play').click(function() {
		try {
		    $('div#audioplayer object').get(0).playAudioAdapter(this.href);
		} catch(e) {
		} finally {
		    return false;
		}
    });

	// encode email address
	
	$('span.email').each(function(i) {
		var href = $(this).text().replace(' (at) ', '@').replace(' (dot) ', '.');
		$(this).html('<a href="mailto:' + href + '">' + href + '</a>');
	});
	
	// highlight focussed form row
	
	$('#left-content table').find(FOCUSELTS).focus(function() {
		var row = $(this).parents('tr');
		$('table.edit tr').not(row).removeClass('focus');
		row.addClass('focus');
	});
	
	// focus 1st error input field or 1st field when no error occured
	var error_fields = $('#left-content table.edit tr.error').find(FOCUSELTS).not(':hidden');
	if (error_fields.length > 0) {
		error_fields.eq(0).focus()
	} else {
		$('#left-content table.edit').find(FOCUSELTS).not(':hidden').eq(0).focus();
	}
	
	// bugfix for <button> problem in IE6
	$('button').click(function() {
		$('button').not(this).attr('disabled', true);
	});

});
