(function($) { 
  $(function() {

	function attachPrevLink() {
		$('.prev-link').click( function() {
			var page = $(this).attr('id').slice(1);
			page = parseInt(page, 10 );
			page_backward(page);
			return false;
		});
	};

	function attachNextLink() {
		$('.next-link').click( function() {
			var page = $(this).attr('id').slice(1);
			page = parseInt(page, 10 );
			page_forward(page);
			return false;
		});
	};


	function page_forward(page)
	{
		var num = page + 1;
		$.get('includes/Activity.Display.Ajax.php', { current_page:num }, function(data) {
			$(".activity").html(data);
			attachPrevLink();
			attachNextLink();
			show_details();
		});
	};

	function page_backward(page)
	{
		var num = page - 1;
		$.get('includes/Activity.Display.Ajax.php', { current_page:num }, function(data) {
			$(".activity").html(data);
			attachNextLink();
			attachPrevLink();
			show_details();
		});
	};

	function show_details() {
		$("div.package-wrapper").each(function() {
			// Div for the Toggler to be Held
			$(this).append("<div class=\"package-toggle\">");
			// If this is a package that is going to be expanded
			// add a control for it
			if( $(this).is(".package-expandable") ) {
				// Since this is expandable hide the details
				$(this).find("div.package-long").hide();
				// Add the Control
				$(this).find(".package-toggle").append("<a class=\"view_details\" href=\"#\">View Details</a>");
			}
		});
		$("div.package-toggle a").toggle(function() {
			$(this).parents("div.package-wrapper").find("div.package-long").animate({
				height: 'show'
			}, 'slow');
			// Changes the Text of the Control
			$(this).html("Hide Details");
			}, function() {
			$(this).parents("div.package-wrapper").find("div.package-long").animate({
				height: 'hide'
			}, 'slow');
			// Changes the Text of the Control
			$(this).html("View Details");
		});
	};

	attachPrevLink();
	attachNextLink();

  });
})(jQuery);
	
