function runFormAjax(){
	
	var e = $('#account_form');
	var action = e.attr('action');
	var data = e.serialize();
	var method = e.attr('method')
	
	$.ajax({
		type: method,
		url: action,
		data: data,
		success: function(xml){
			
			$(xml).find('wrapper').children().each(function(){
				var element = $(this).attr('id');
				var html = $(this).text();
				$('#'+element).html(html);
			})
			
			$.fn.colorbox({
				inline: true,
				href: '#thankyou'
			})
		}
	});
	
	$.fn.colorbox.close(); 
	
}




function updateStatus(status){
	var query = "status="+status;
	$.ajax({
		type: "GET",
		url: "/getStatusUpdate.asp", 
		data: "" + query,
		cache: false,
		success: function(img){
			$('#post_comment_text h4').html('Last been cooking');
			$('#comment_thanks').html("<strong>Thanks for letting the community know you're cooking " + status+"</strong>");
		}
	});
}


function setKeepFavourites(){
$('.keep_favourite').each(function(){
		$(this).click( function(){ 
			getFavouritesForSidebar($(this).attr('rel'));
			return false; 
		});

	})
}



function getFavouritesForSidebar(id){
	
			var url ="";
			var data =""
	
			data = "recipeId=" + id;
			url = "/getFavouriteRecipesForProfile.asp";
			$.ajax({
				type: "GET",
				url: url, 
				data: data,
				cache: false,
				success: function(html){
					var cat = $('#fav_recipes');
					cat.empty();
					cat.append(html);
				} 
				});
			return true;
		
		}





$(document).ready(function(){


	setKeepFavourites();

	$('#comment_submit').click( function(){ 
		var comment = $('#post_comment').val();
		updateStatus(comment)
		return false; 
	});

	$('#edit_account, #edit_password, #edit_account2, #edit_picture, #send_email, #tesco_login').colorbox({
		scrolling: false,
		onComplete: function(){
			if($('#browse').length > 0){
				new AjaxUpload('browse', {
					action: '/imageUpload.php',
					responseType: "text/xml",
					onComplete: function(file, response) {
						$('#profile_avatar').attr('src', response);
						$.fn.colorbox({
							inline: true,
							href: '#thankyou'
						})
					}
				}); 
			}
		}
	});
})
