// JavaScript Document

(function(jQuery) {
	jQuery.fn.fignavigation = function(settings) {
		
		function _initialize(){	
			jQuery('#going-up a').click(function(){
				jQuery(document).scrollTo(0, 500);
				return false;
			});
			jQuery('#more-fig a').click(function(){
				var href = jQuery(this).attr("href");
				paged++;
				if(!jQuery('#more-fig a').hasClass("loading")){
					jQuery('#more-fig a').addClass("loading");
					var h = jQuery("#fig-list").height();
					var lastClear = jQuery('#fig-list .clear:last');
					jQuery.ajax({
						type: "GET",
						url: href,
						data: "fig-filter=1&filter-paged="+paged,
						success: function(msg){
							jQuery('#more-fig a').removeClass("loading");
							jQuery('#fig-list').append(msg);
							var newh = jQuery("#fig-list").height();
							jQuery('#fig-list-container').css({"overflow":"hidden", "height":h+"px"}).animate({"height":newh+"px"},1000, function(e){
								jQuery(document).scrollTo(lastClear, 500);
							});
						}
					});
				}
				return false;
			});
		}
		
		_initialize();

	};
})(jQuery);