$(document).ready(function() {
    
    //Click for add 
 $('#fav').click(function() {
  	
  	//alert("http://www.novogradnja.rs/fav.php?id="+listing_id+"&a=add");
   $.ajax({
  	url: "../fav.php?id="+listing_id+"&a=add",
  	 complete: function(xhr) {
            //alert(xhr.status);
        },
  	success: function(data,textStatus) {
  		//alert(textStatus);
  	$('#favs').empty();
  	var fav_count = parseInt($('#fav_count').text());
  	
  	if(data == 'success')
  	{
  		$('#fav_count').text(fav_count + 1);
  		$("#goto_fav").show();
  }
    //$('#favs').html(data);
    //alert("vratio podatke"+data);
				    //Click for remove
				     $('.remlink').click(function() {
				  	 var rem_id = 0; 
				  	 rem_id = $(this).attr("rel");
				     alert('http://localhost/novogradnja/fav.php?id='+rem_id+'&a=remove');
				     $.ajax({
				  	 url: 'http://localhost/novogradnja/fav.php?id='+rem_id+'&a=remove'
				  	 });
				     $(this).parent().remove();
				     
				     var fav_count = parseInt($('#fav_count').text());
				     
				     if(fav_count == 1)
				     {
				     	$('#favs').empty();
				     }
				     else
				     {
				     	$('#fav_count').text(fav_count - 1);
				     }
				  	 });
				    //end click for remove
    }
		});
   	
   	
   
		});
   	//End click for add
   	
   	
   	//Click for remove
		$('.remlink').click(function() {
			
				  	 var rem_id = 0; 
				  	 rem_id = $(this).attr("rel");
				     $.ajax({
				  	 url: 'http://novogradnja.rs/fav.php?id='+rem_id+'&a=remove'
				  	 });
				     $(this).parent().remove();
				     
				     var fav_count = parseInt($('#fav_count').text());
				     
				     if(fav_count == 1)
				     {
				     	$('#favs').empty();
				     }
				     else
				     {
				     	$('#fav_count').text(fav_count - 1);
				     }
				     
				  	 });
				    //end click for remove
  
   	
  
});
