/* JavaScript Document [j_fixed_scroll.js]
	Author: Steven Robbins
	Entity: Rayhawk Corporation
	Copyright: 2011
	Requirements: jQuery [core: current release].
	Original Creation Date: 02.23.2011
	Last Update On: 05.20.2011 */
	
$(document).ready(function() {
			
	if ($("*").is("#jFixedScroll")) {
		
		var position = $("#jFixedScroll").css("position"); // element original position (static, relative, absolute, etc)
		var left = $("#jFixedScroll").css("left"); // element original relative left offset
		var top = $("#jFixedScroll").css("top"); // element original relative top offset
		var offsetL = $("#jFixedScrollBottom").offset().left; // element original document left offset
		var offsetT = $("#jFixedScrollBottom").offset().top; // element original document top offset
		
		if (offsetT < $(window).scrollTop()) {
			
			$("#jFixedScroll").css({"position": "fixed", "left": offsetL , "top": 0});
		}
		
		$(window).scroll(function() {
			
			// if the viewer has scrolled beyond the top offset of the element container, set the element to fixed position
			if (offsetT < $(window).scrollTop()) {
				
				$("#jFixedScroll").css({"position": "fixed", "left": offsetL , "top": 0});
			}
			else {
				
				// otherwise set the element back to it's original position and relative top offset.
				$("#jFixedScroll").css({"position": position, "left": left, "top": top});
			}
		});
		
		$(window).resize(function() {
			
			left = $("#jFixedScroll").css("left"); // element original relative left offset
			top = $("#jFixedScroll").css("top"); // element original relative top offset
			offsetL = $("#jFixedScrollBottom").offset().left; // element original document left offset
			offsetT = $("#jFixedScrollBottom").offset().top; // element original document top offset
			
			if (offsetT < $(window).scrollTop()) {
				
				$("#jFixedScroll").css({"position": "fixed", "left": offsetL , "top": 0});
			}
		});
	}
});

