( function($) {
	$.anchorNavigation = {
		/**/
		mapping :null,
		/**/
		currentAnchor :null,
		/**/
		initialize : function(mapping) {
			this.mapping = mapping;

			/* hide mapped contents */
			$.each(mapping, function(i, val) {
				$(val).hide();
			});

			/* move anchors on top */
			$("a.anchor").remove().prependTo("html body");

			/* add ajax update on anchor links */
			$("a[href^='#']").each( function() {
				$(this).click( function() {
					$.anchorNavigation.toAnchor($(this).attr("href"));
				});
			});

			this._checkDocumentURL();

			return $;
		},
		/**/
		toAnchor : function(anchor) {
			if (!anchor || anchor === null)
				anchor = '';
			if (anchor[0] != '#')
				anchor = '#' + anchor;
			if (anchor !== this.currentAnchor) {
				if (this.currentAnchor !== null) {
					$(this.mapping[this.currentAnchor]).fadeOut("fast",function() {
						$($.anchorNavigation.mapping[anchor]).fadeIn("fast");
						$.anchorNavigation.currentAnchor = anchor;
					});
				} else {
					$(this.mapping[anchor]).fadeIn("fast");
					this.currentAnchor = anchor;
				}
				
			}
			return $;
		},
		/**/
		_checkDocumentURL : function() {
			/*
			 * jump to correct page based on document URL (allowing Bookmarks)
			 */
			var url = document.location.href;
			if (url.indexOf('#')) {
				var anchor = url.split('#')[1];
				this.toAnchor(anchor);
				/* add a timer to support Prev/Next browser buttons */
				setTimeout("jQuery.anchorNavigation._checkDocumentURL()", 300);
			}
			return $;
		}

	};
})(jQuery);