$(document).ready(function(){
	$('div#unit-mailing-list form').submit(function(){
		$(this).find('input.placeholder').val('');
		
		var name = $('input#mailinglist-name');
		var email = $('input#mailinglist-email');
		
		if(!name.val() || !email.val()){
			if(!name.val()){
				name.addClass('has-error');
			}else{
				name.removeClass('has-error');
			}
			
			if(!email.val()){
				email.addClass('has-error');
			}else{
				email.removeClass('has-error');
			}
			return false;
		}

		$.post('/mmlib/includes/tindalstreet/ajax.mailinglist.php', $(this).serialize(), function(response){
			var confirmation = $('<div id="mailing-list-confirmation"></div>');
			confirmation.append('<p class="success">Thank you for joining our mailing list</p>');
			$('div#unit-mailing-list').append(confirmation);
			
			if(pageTracker){
				pageTracker._trackEvent('Newsletter', 'Registered', name.val() + " (" + email.val() + ")");
			}
			
			$('div#unit-mailing-list form').fadeOut('fast', function(){confirmation.fadeIn('slow');});
		})
		return false;
	});
	
	$('.placeholder').focus(function(){
		if($(this).hasClass('placeholder')){
			$(this).val('');
			$(this).removeClass('placeholder');
		}
	});
	
	$('.show-all-search-results').click(function(){
		$(this).parent().prevAll('.hidden').removeClass('hidden');
		$(this).remove();
		return false;
	});
	
	
	$('#template-books-list #visual-book-list li .annotation-wrapper').click(function(){
		window.location = $(this).next().attr('href');
	});
	
	$('#author-index #visual-book-list li .annotation-wrapper').click(function(){
	 	window.location = $(this).parent().find('.book-cover').attr('href');
	});
	
});