$(function() 
{
	$('#button_block').hide();
	$('#upload_container').hide();
	$('#content').val('Today, I am cooking ...');
	$('#default_button_block').hide(); 
	$('#default_content').val('Today, I am cooking ...');
	
	/**************for functions after user logge in */
	
$("#content").focus(function()
{
$(this).animate({"height": "25px"}, "fast" );
$("#button_block").slideDown("fast");
return false;
});
$("#cancel").click(function()
{
$('#default_button_block').hide(); 
$('#upload_container').hide();  
$("#content").animate({"height": "25px"}, "fast" );
$("#button_block").slideUp("fast");
return false;
});

$('#open_upload_div').click(function (){
//$('#upload_container').show();
return false;
});

$('#close_upload_div').click(function (){
$('#upload_container').hide();
return false;
});

/**************for functions before logged in */ 

$("#default_content").focus(function()
		{
		$(this).animate({"height": "25px"}, "fast" );
		$("#default_button_block").slideDown("fast");
		return false;
		});
		$("#default_cancel").click(function()
		{
		$('#default_button_block').hide(); 
		$("#default_content").animate({"height": "25px"}, "fast" );
		$("#default_button_block").slideUp("fast");
		return false;
		});

		$('#open_upload_div').click(function (){
		
		return false;
		});

				

});

/***follow the recipe function starts here **/
function follow_recipe(recipe_owner,follower){ 
$('.ajax_wait_'+recipe_owner).html($('#ajax_waiting_image').html());                 
$.ajax({

method:"post",
dataType:"json",
url:$('#follow_unfollow_url').val(),
data:'recipe_owner='+recipe_owner+'&follower='+follower,
success: follow_unfollow_success,
failure: ajax_error
	
});
return false; 
}

function follow_recipe_profile(recipe_owner,follower){

	$('.ajax_wait_'+recipe_owner).html($('#ajax_waiting_image').html());                 
	$.ajax({

	method:"post",
	dataType:"json",
	url:$('#follow_unfollow_url').val(),
	data:'recipe_owner='+recipe_owner+'&follower='+follower,
	success: follow_unfollow_success_profile,
	failure: ajax_error
		
	});
	return false; 
	}
/***follow the recipe function ends here  **/ 


function follow_unfollow_success(data){ 
    $('.ajax_wait_'+data.recipe_owner).html('');   
	var follow_unfollow_text=data.follow_unfollow_link_text;
	var follow_unfollow_link_class='follow_'+data.recipe_owner;     
	$('.'+follow_unfollow_link_class).text(follow_unfollow_text);   
	$('.'+follow_unfollow_link_class).attr('title',follow_unfollow_text);   
}

function follow_unfollow_success_profile(data){ 
    $('.ajax_wait_'+data.recipe_owner).html('');   
	var follow_unfollow_text=data.follow_unfollow_link_text;
	var follow_unfollow_link_class='follow_'+data.recipe_owner; 
	var img = $('.'+follow_unfollow_link_class).find("img")[0];
		
	if(follow_unfollow_text=='Follow'){
	var src="images/follow.png";
	}
	else if(follow_unfollow_text=='Unfollow'){
	var src="images/unfollow.png"; 
	}
	img.src = src;
		  
}


function ajax_error(){
	alert('Failed to contact the server.Please try after some time');
}

/**closes the comment box window for recipe */
function close_comment_box(recipe_id){
var comment_div='#comment'+recipe_id;
$(comment_div).hide();          
}

/**open additional comments div **/
function show_additional_comments(recipe_id){  
var additional_comments_div='#additional_comment_posts_'+recipe_id;
$(additional_comments_div).show(); 
$('#additional_comments_link_'+recipe_id).hide(); 
}

/**close additional comments div **/
function close_additional_comment_posts(recipe_id){
var additional_comments_div='#additional_comment_posts_'+recipe_id;
$(additional_comments_div).hide(); 
$('#additional_comments_link_'+recipe_id).show();   
}


/*save recipe posts from the home page or from profile page */

function save_recipe_post(recipe_id,recipe_owner_id){

	$.ajax({
	url:"save_recipe_post.php",
	method:"post",
	dataType:"json",
	data:"recipe_id="+recipe_id+"&recipe_owner_id="+recipe_owner_id,
	success:response_save_recipe_post,
	error:error_calling_json
	});
}

function response_save_recipe_post(data){
	var recipe_id=data.recipe_post_id;
	var save_recipe_id='#save_recipe_'+recipe_id;
	var save_recipe_container_id='#save_recipe_container_'+recipe_id;
	var comment_link_exists_id='comment_link_exists_'+recipe_id;
	var comment_link_exists_value=$('#'+comment_link_exists_id).val(); 
	if(comment_link_exists_value==0){
	var link_seperator='#link_seperator_'+recipe_id;
	$(link_seperator).hide();  
	}
	$(save_recipe_id).hide();
	$(save_recipe_container_id).hide();
}

function error_calling_json(){
	alert("Error occured in contacting server.Please try after sometime");
}
function open_see_more_div(recipe_see_more_div){
	
	var see_more_div='#see_more_'+recipe_see_more_div;
	var link_see_more='#link_see_more_'+recipe_see_more_div;
	var div_text=$(link_see_more).text();
	if(div_text=='See More'){$(see_more_div).show();$(link_see_more).text('See Less');}
	else{div_text=='See Less';$(see_more_div).hide();$(link_see_more).text('See More');}
	return false;
}
function delete_recipe_contents(recipe_id){
	var delete_confirm=confirm('Are you sure to delete recipe?');
	if(delete_confirm){
	var recipe_delete_div="#posted_recipe_data_"+recipe_id;
	$(recipe_delete_div).hide();
	$.ajax({

		method:"post",
		dataType:"json",
		url:'delete_recipe_ajax.php',
		data:'recipe_id='+recipe_id,
		failure: ajax_error
			
		});
	}
}
