


$(window).scroll(function() {
	var brackets = $('.side_brackets');
	
	
	// getPageScroll() by quirksmode.com - adapted to only return yScroll
	function getPageScroll() {
	    var yScroll;
	    if (self.pageYOffset) {
	      yScroll = self.pageYOffset;
	    } else if (document.documentElement && document.documentElement.scrollTop) {
	      yScroll = document.documentElement.scrollTop;
	    } else if (document.body) {// all other Explorers
	      yScroll = document.body.scrollTop;
	    }
	    return yScroll
	}

	// Adapted from getPageSize() by quirksmode.com
	function getPageHeight() {
	    var windowHeight
	    if (self.innerHeight) { // all except Explorer
	      windowHeight = self.innerHeight;
	    } else if (document.documentElement && document.documentElement.clientHeight) {
	      windowHeight = document.documentElement.clientHeight;
	    } else if (document.body) { // other Explorers
	      windowHeight = document.body.clientHeight;
	    }
	    return windowHeight
	}
	
	
	
	//define it
	var triggerPoint
	var docHeight = $(document).height();

	//work out the various variables. Simple maths to find the named points throughout the viewport. 
	//Actually, that's worth noting. 
	//NOTE: These are all viewport positions.
	var pageBottom = getPageScroll() + getPageHeight();	
	var quarterPoint = getPageScroll()+((pageBottom-getPageScroll())/4);
	var halfwayPoint = getPageScroll()+((pageBottom-getPageScroll())/2);
	var threeQuarterPoint = pageBottom-((pageBottom-getPageScroll())/4);
	triggerPoint = quarterPoint+(getPageHeight()/10);
	
	
	
//	console.log(triggerPoint);
	
	
	$('div.bracket_sticky').each(function(index) {
	  // this.innerHTML = this + " is the element, " + index + " is the position";
		
		var itemTop = $(this).offset().top;
		var itemBottom = ($(this).offset().top + $(this).height());
		
	
	//	console.log($(this).offset().top, ($(this).offset().top + $(this).height()), triggerPoint );
		
		if (triggerPoint > itemTop 
			&& triggerPoint < itemBottom
			) 
		{	
			var bracketPoint = itemTop+(($(this).height()/2)-100);
			brackets.stop().css({top: bracketPoint}, 1000, function(){
				stop();
			});
	//		console.log($(this).index());
		};
	
	});
});
