$(document).ready(function() {
	$('.radioList :radio').click(function(){
		if ($(this).attr('value') == 'image')
		{
			$('#bandInformation label[for="band_name"]').text(aliases.author_name);
			$('#bandInformation label[for="band_registered"]').text(aliases.author_registered);
		}
		else
		{
			$('#bandInformation label[for="band_name"]').text(aliases.band_name);
			$('#bandInformation label[for="band_registered"]').text(aliases.band_registered);
		}
	});
	$('.controls a').attr('target', '_blank');
	
	$('.fieldContainer input:not(:radio), .fieldContainer select, .fieldContainer textarea').bind('error', function(e){
		$('label[for=' + $(this).attr('id') + ']').css({color: 'red'});
		$(this).blur(function(){
			$('label[for=' + $(this).attr('id') + ']').css({color: 'inherit'});
		});
	});
	
	function formatItem(row, i, max, term)
	{
		return row[0].replace(new RegExp("(" + encodeURIComponent(term) + ")", "gi"), "<strong>$1</strong>") + " <span class='mute'>&times;" + row[1] + "</span>";
	}
	
	function formatResult(row)
	{
		var escaped = row[0];
		
		var findReplace = [[/&amp;/g, '&'], [/&lt;/g, '<'], [/&gt;/g, '/>'], [/&quot;/g, '"']];
		for(var itemKey in findReplace)
		{
			var item = findReplace[itemKey];
		    escaped = escaped.replace(item[0], item[1]);	
		}
		
		return escaped;
	}
	
	$('#keywords').autocomplete(
		window.location.protocol + '//' + window.location.host + window.location.pathname + '?tags',
		{
			width: 480,
			multiple: true,
			matchContains: true,
			formatItem: formatItem,
			formatResult: formatResult
		}
	);
});