(function($) {
	$.xSpander = function(options) {
	   $.xSpander.defaults = {
		   linksParent : "",
		   targetsParent : "",
		   targets : "",
		   speed : "fast"
	   };
	   var options = $.extend($.xSpander.defaults, options);
		   
	   $("a", options.linksParent).each(function() {
		   var $this = $(this);
		   $this.click(function() {
			   var showWhat = $this.attr("href");
			   // Conditional check to see if the clicked item is already visible.
			   // If it is, cancel slide animation and go to location.
			   if ($(options.targetsParent + ">" + options.targets + ":visible").is(showWhat)) {
			   	   window.location = showWhat;
			   	   return false;
			   }
			   $(options.targetsParent + ">" + options.targets + ":visible").slideUp(options.speed);
			   $(showWhat).slideDown(options.speed);
			   window.location = showWhat;
		   });
	   });
	};
	$(window).load(function() {
		// Use type coersion to convert url to string:
		var xSpander_urlStr = window.location + "";
		var xSpander_urlParamPos = xSpander_urlStr.indexOf("#");
		var xSpander_defaults = $.xSpander.defaults;
		if (xSpander_urlParamPos > 0) {
			 var xSpander_whichParam = xSpander_urlStr.substring(xSpander_urlParamPos, xSpander_urlStr.length);
		} else {
			 return false;
		}
		function startxSpander() {
			// Conditional check to see if the clicked item is already visible.
			// If it is, cancel slide animation and go to location.
			if ($(xSpander_defaults.targets + ":visible", xSpander_defaults.targetsParent).is(xSpander_whichParam)) {
			    window.location = xSpander_whichParam;
				return false;
			}
			 $(xSpander_defaults.targets + ":visible", xSpander_defaults.targetsParent).slideUp();
			 xSpanderSlideInContent();
		}
		function xSpanderSlideInContent() {
			 $(xSpander_whichParam).slideDown(xSpander_defaults.speed);
			 window.location = xSpander_whichParam;
		}
		startxSpander();
	});
})(jQuery);


/* jQuery.xSpander takes three arguments and a fourth optional argument: the parent of the links that triger the expanding, the parent of the targets to expand, and a selector indictating the targets to expand. The forth optional argument is speed. You can pass "slow" or "fast" or a number in milliseconds. The default speed is "fast". Note that any word passed in must be in quotes, milliseconds should not have quotes. Here's an examle:

    $(document).ready(function() {
    	$.xSpander({linksParent : "#KeynoteLinks", targetsParent : "#KeynoteSpeakers", targets : "li", speed : "slow"});
    });

*/