// Scrolling sidebar for your website
// Downloaded from Marcofolio.net
// Read the full article: http://www.marcofolio.net/webdesign/create_a_sticky_sidebar_or_box.html
/*
window.onscroll = function()
{
	if( window.XMLHttpRequest ) {
		if (document.documentElement.scrollTop > 260 || self.pageYOffset > 260) {
			$('faqindex').style.position = 'fixed';
			$('faqindex').style.top = '0';
		} else if (document.documentElement.scrollTop < 260 || self.pageYOffset < 260) {
			$('faqindex').style.position = 'absolute';
			$('faqindex').style.top = '260px';
		}
	}
}
*/

window.addEvent("domready", function() {
	var scrolled = document.id("faqindex") || false, mover;

	if (scrolled) {
		
		mover = (function() {
		    var doc = document.id(document.body);
			var ssize 	= scrolled.getSize();
			var parent = document.id("content") || scrolled.getParent();
			var psize 	= parent.getSize();
			var poffset = parent.getPosition(doc).y;			
			var starttop	= scrolled.getStyle("top");
			var startoffset = scrolled.getPosition(doc).y;
			return function() {
				var scroll = window.getScroll();
				
				if (scroll.y > startoffset) {
					if (scroll.y - poffset + ssize.y > psize.y)
						scrolled.setStyle("top", psize.y - ssize.y)
					else
						scrolled.setStyle("top", scroll.y - poffset)									
				}
				else {
					scrolled.setStyle("top", starttop)
				}
			};
		}());
		
		window.addEvent("scroll", mover);
	}
});
