$(document).ready(function() {

	jQuery.fn.fadeToggle = function(speed, easing, callback) {
	   return this.animate({opacity: 'toggle'}, speed, easing, callback);
	}; 

	jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
		return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);  
	};

	jQuery.fn.toggleText = function(a, b) {
		return this.each(function() {
			jQuery(this).text(jQuery(this).text() == a ? b : a);
		});
	};

	$("a.readmoreUp").click(function() {
		$(this).parent().next().slideFadeToggle("fast");
		$(this).toggleText("Read more...","Read less...");
		return false;
	});

$("a.readmore").toggle(
	function () {
		$(this).text("Read less...");
		var pCtnr = $(this).prev().prev().attr("id");
		var pHeight = $("#"+pCtnr+" > div").height();
		var fHeight = $("#"+pCtnr+" > form").height();
		var tHeight = pHeight + fHeight + 60;
		$(this).prev().prev().animate({height:tHeight},300);
		return false;
	},
	function () {
		$(this).text("Read more...");
		$(this).prev().prev().animate({height:"70"},300);
		return false;
	}
);

	/** Send to Friend Form **/
	$(".shareform").submit(function(){
		var container = $(this).attr("id");
		var fdata = $(this).serialize();
				
		$.ajax({
			type: "POST",
			url: "dev/admin/mailer.php",
			data: fdata,
			error: function() {
				$(this).append("<span>Error, try later.</span>");
			},
			success: function(response){
				$("#"+container+" span:last-child").text(response).fadeIn("fast");
			},
			complete: function() {
				$("#"+container+" span:last-child").fadeTo(5000,1, function(){$(this).fadeOut("slow");});
			}
		});
	
		return false;
	});

});