$(document).ready(function() {
	$('#category-info').change(function() {	
		var catValue = $('#category-info option:selected').val();
		$('#subcategoryLI').children('select').hide().attr('name','unnamed');
		$('select#subcategory-' + catValue).show().attr('name','subcategory');
	});
	
	// Do email field focus on login page
	
	$('#email-login').focus();
	
	// Do Twitter character count
	
	var twitter = 90;
	var focusDude = 0;
	
	$('#twitter').focus(function() {
		focusDude = 1;
	});
	
	$('#twitter').blur(function() {
		focusDude = 0;
	});
	
	$(document).keyup(function() {
		if (focusDude == 1) {
			var twength = $('#twitter').val().length;
			var newTwength = twitter - twength;
			var message;
			if (newTwength == 1) {
				message = '1 character left';
			} else {
				message = newTwength + ' characters left';
			}
			$('#twitter-count').html(message);
			if (newTwength < 12) {
				$('#twitter-count').css('color','#ff4444');
			} else {
				$('#twitter-count').css('color','#FFFDC2');
			}
		}
	});
	
	// Expand/Contract categories
	var linkName = $('#showCats').html();
	var newName = 'hide categories';
	$('#showCats').click(function() {
		$('.expand').slideToggle();
		var currName = $('#showCats').html();
		var replaceName = linkName;
		if (currName == linkName) {
			replaceName = newName;
		}
		$(this).html(replaceName);
		return false;
	});
	
});
