$(document).ready(function() {
	//  Toggle services
	$('.more_info').click(function() {
		$(this).parent().next().next().toggle();
	});
	
	//  Toggle custom info
	$('.btn_reviews').click(function() {
		$(this).parent().next().next().next().toggle();
	});
	
	// Save new note
	$('.save_new_note').click(function() {
		var target = $(this).attr('rel');
		var note = $(this).prev().val();
		var self = $(this);
		$.post('http://www.towsearch.com/default.php?page=save_note', { target: target, note: note }, function(success) {
			if (success) {
				self.parent().children(':first').prepend(success);
			} else {
				alert('Failed');
			}
		});
	});
	
	// Save new score
	$('.user_score').keyup(function() {
		$(this).stop();
		var target = $(this).attr('rel');
		var score = $(this).val();
		var self = $(this);
		$.post('http://www.towsearch.com/default.php?page=save_score', { target: target, score: score }, function(success) {
			if (success) {
				self.css('background', '#E6EFC2');
				self.css('color', '#264409');
				self.animate({ backgroundColor: 'white', color: 'gray' }, 1000);
			} else {
				alert('Failed');
			}
		});
	});
	
	// Save preferred provider
	$('.btn_preferred').live('click',function() {
		
		var target = $(this).attr('rel');
		var is_checked = $(this).hasClass('star-on').toString();
		
		if ( is_checked == 'true' ) {
			is_checked = 'false';
			$(this).addClass('star-off');
			$(this).removeClass('star-on');
		} else {
			is_checked = 'true';
			$(this).addClass('star-on');
			$(this).removeClass('star-off');
		}
		
		$.post('http://www.towsearch.com/default.php?page=save_preferred', { target: target, is_checked: is_checked }, function(success) {
			//alert(success);
		});
	});
});