// JavaScript Document
$(document).ready(function(){
						   
	$('.ad_controls').tipsy({gravity: 'n'});
	$('.add').tipsy({gravity: 'n'});
	$('.share_buttons').tipsy({gravity: 'n'});
	
	/*if (i > 0) {
		$("#shortlist_count").show(); //toggle from hidden
		if (i > 1) $("#shortlist_count").html('You have ' + i + ' properties in your <a href=\"../myLPW/index.php\">Shortlist</a>'); //show the count on page load if more than 0 added
		else $("#shortlist_count").html('You have ' + i + ' property in your <a href=\"../myLPW/index.php\">Shortlist</a>');
	}*/
 
	$(".add").click(function(){
		var element = $(this);
		var noteid = element.attr("id");
		var info = 'id=' + noteid + '&action=add';
		var wait_image = $('<span class="add_shortlist_box"><img src="../images/throbber.gif" alt="please wait" border="0"></span>');
		$("#add").hide(); //hide the add icon
		//$(element).html(wait_image.hide().fadeIn(1000)); //show throbber animation until added.
		$(element).html(wait_image); //show throbber animation until added.


		$.ajax({
			type: "POST",
			url: "../myLPW/myLPW_index_sc.php",
			data: info,
			success: function(resp){  
				i++;
				if (i > 1) 	$("#shortlist_count").html('You have ' + i + ' properties in your <a href=\"../myLPW/index.php\">Shortlist</a>');
				else $("#shortlist_count").html('You have ' + i + ' property in your <a href=\"../myLPW/index.php\">Shortlist</a>');
				$("#shortlist_count").effect("highlight", {color: "#FF9900"}, 3000);
				//$("#reply").html(resp);
				//$(this).addClass("noUnderline"); //add underline class to a tag of currently clicked
				//$(this).unbind('click'); //disable the clicking funcitonality of the current a tag (do people can't add agian)
 				var newtxt = $('<img src="../images/green_tick.gif" alt="tick"><span class="add_shortlist_txt_added">Added</span>');
				$(element).replaceWith(newtxt.hide().fadeIn(2000)); //replaceWith replaces the whole element so link also gets removed. .html only replaces the text inside element
 				//$(this).html('<img src="../images/green_tick.gif" alt="tick"><span class="add_shortlist_txt_added">Added</span>').hide().fadeIn(2000);
 
			 },
			  error: function(resperr){ 
			  	alert('There was an error adding this property to the Shortlist. Please try again or open a new browser window and start again.');
			 }
		});
		
 	
		//$("#saved:last").fadeIn("slow");

		return false;
	});
});