$(function(){
	$(":text").hint();
	
	// TODO: make this and the blocks below it a plugin
	if($('#tab_new_artist_name').length){
		var el = $('#tab_new_artist_name');
		var value = el.val();
		var currlength = value.length;
		
		if (currlength > 0 && value != "Enter artist name...") $('#tab_artist_id').attr("disabled","disabled");
		el.keyup(function(){
			var newlength = $(this).val().length;
			if(newlength > 0)
				$('#tab_artist_id').attr("disabled","disabled");
			else
				$('#tab_artist_id').removeAttr("disabled");
		});
	}
	
	if($('#tab_new_tuning').length){
		var el = $('#tab_new_tuning');
		var value = el.val();
		var currlength = value.length;
		
		if (currlength > 0 && value != "Enter tuning...") $('#tab_tuning_id').attr("disabled","disabled");
		el.keyup(function(){
			var newlength = $(this).val().length;
			if(newlength > 0)
				$('#tab_tuning_id').attr("disabled","disabled");
			else
				$('#tab_tuning_id').removeAttr("disabled");
		});
	}
	
	if($('#tab_new_genre').length){
		var el = $('#tab_new_genre');
		var value = el.val();
		var currlength = value.length;
		
		if (currlength > 0 && value != "Enter genre...") $('#tab_genre_id').attr("disabled","disabled");
		el.keyup(function(){
			var newlength = $(this).val().length;
			if(newlength > 0)
				$('#tab_genre_id').attr("disabled","disabled");
			else
				$('#tab_genre_id').removeAttr("disabled");
		});
	}
	
	$(".hide_linenum").click(function(){
		$(".linenum").toggle();
		return false;
	});
	
	$(".tabs").tabs({ spinner: '<em>Loading, please wait...</em>' });

	$(".tablesorter")
		.tablesorter({ 
			widgets: ['cookie'] 
		})
		.tablesorterPager({ 
			container: $("#tabs-pagination"),
			size: 30
		})
		.tablesorterFilter({ 
			filterContainer: $("#tablesorter-filter"),
			filterClearContainer: $("#tablesorter-filter-clear"),
			filterColumns: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
			filterCaseSensitive: false
		});
		
		
	// tablesorter row highlighting
	$(".tablesorter tr").livequery(function(){
		$(this).hover(function(){
			$(this).find("td").css("backgroundColor", "#ffffcc");
		}, function(){
			$(this).find("td").css("backgroundColor", "#fff");
		});
	});
});
