/*
	module name: lu-infoshade.js
	date: Monday, August 10, 2009
	version: 1.0
	author: Jay Dansand (jay.dansand@gmail.com) for Lawrence University ITS
	revisions:
		11/12/2009 - JJD - Added isIE6 attribute to solve issue with a:hover background property when using
			infoShade in navigation menus (caused IE6 to crash if hovered while sliding open/close)
		11/12/2009 - JJD - Added zoom:1 property to all elements to guarantee hasLayout in IE7
	purpose:
		Use JQuery's easing options to hide all .infoShade containers on a page,
		and respond to link click by displaying selected information container.
	configuration:
		None.
	usage:
		1) Define any number of containers with class "infoShade".
		2) Create links to "#infoShade" above each container.
		3) OPTIONAL:
			If the link has a span in it, that span will become a plus/minus sign indicating
			the collapsed/expanded nature of the associated infoShade container.
		
		When a user clicks the link, the next ".infoShade" node in the DOM will be expanded,
		after all .infoShade children are collapsed.
*/

var lu_infoshade_lastChoice = null;
$(document).ready( function()
	{
		var selectedShade = String(window.name).match(new RegExp(window.location + ".*?(\#infoShade[0-9]+)", "i"));
		if (selectedShade) selectedShade = selectedShade[1];
		$(".infoShade").hide().css("zoom", "1");
		var tmp = $("a[href^=#infoShade]");
		tmp.click( function()
			{
				var isIE6 = document.all && navigator.appVersion.match(/MSIE 6\.\d+;/) !== null;
				if (isIE6)
					$(".infoShade").hide();
				else
					$(".infoShade").slideUp("fast");
				$("a[href^=#infoShade]>span").text("[+]");
				if (this != lu_infoshade_lastChoice)
				{ //Expanding the window
					window.name = window.location + this.href;
					if (isIE6)
						$(this).nextAll(".infoShade").eq(0).show();
					else
						$(this).nextAll(".infoShade").eq(0).slideDown("fast");
					$(this).children("span").html("[&ndash;]");
					lu_infoshade_lastChoice = this;
				}
				else
				{ //Collapsing the window
					lu_infoshade_lastChoice = null;
					window.name = "";
				}
				return false;
			}
		);
		tmp.each( function(i) { this.href = "#infoShade" + i; });
		tmp = tmp.children("span");
		tmp.attr("style", "font-size: 80%;");
		tmp.append("[+]");
		$("a[href=" + selectedShade + "]").click();
		
		//Since the .hide() causes anchor calculation to die a bit, we'll need to re-scrollTo any anchors
		if (!document.all)
		{
			var anchor = String(window.location).match(/#([\w\-]+)/);
			if (anchor) $("a[name=" + anchor[1] + "]").each( function () {
				//window.scrollTo(this);
				window.scrollTo(this.offsetLeft, this.offsetTop);
			});
		}
	}
);
