﻿

//Scolling functions... 
			//Get the current y position
			function currentYPosition() {
				// Firefox, Chrome, Opera, Safari
				if (self.pageYOffset) return self.pageYOffset;
				// Internet Explorer 6 - standards mode
				if (document.documentElement && document.documentElement.scrollTop)
					return document.documentElement.scrollTop;
				// Internet Explorer 6, 7 and 8
				if (document.body.scrollTop) return document.body.scrollTop;
				return 0;
			}

			//Get the elements y postion... 
			function elmYPosition(eID) {
				var elm = document.getElementById(eID);
				var y = elm.offsetTop;
				var node = elm;
				while (node.offsetParent && node.offsetParent != document.body) {
					node = node.offsetParent;
					y += node.offsetTop;
				}
				return y;
			}

			//Smooth Scroll Javascript 
			function smoothScroll(eID) {

				//Get the current postion of the view
				var startY = currentYPosition();

				//Get the elements y position
				var stopY = elmYPosition(eID) -40;

				//Determine the elements distance (above or below)
				var distance = stopY > startY ? stopY - startY : startY - stopY;
				
				//IF less than 100 don't do anything
				if (distance < 100) {
					scrollTo(0, stopY); return;
				}

				//Detemine Scroll Speeds 
				var speed = Math.round(distance / 30);
				if (speed >= 40) speed = 40;
				var step = Math.round(distance / 25);
				var leapY = stopY > startY ? startY + step : startY - step;
				var timer = 1;

				//Scroll To
				if (stopY > startY) {
					for (var i = startY; i < stopY; i += step) {
						setTimeout("window.scrollTo(0, " + leapY + ")", timer * speed);
						leapY += step; if (leapY > stopY) leapY = stopY; timer++;
					} return;
				}
				for (var i = startY; i > stopY; i -= step) {
					setTimeout("window.scrollTo(0, " + leapY + ")", timer * speed);
					leapY -= step; if (leapY < stopY) leapY = stopY; timer++;
				}
			}

			$(function () {
				//Top link scroll on click
				$('#top_link').click(function () {
					smoothScroll('container');
				});


				$(window).scroll(function () {
					var scroll = $(window).scrollTop();
					if (scroll >= 330) {

						$('#top_link').removeClass('default');
						$('#top_link').addClass('active');
					}
					else if (scroll <= 330) {
						$('#top_link').removeClass('active');
						$('#top_link').addClass('default');
					}
				});

				$('#retentionPlatform div.nav a').click(function () {
					$('#retentionPlatform div div:not(.nav)').hide();
					$('#retentionPlatform div div.nav a').removeClass('isSelected');
					$('.' + this.id).show();
					$('#retentionPlatform div div.nav a#' + this.id).addClass('isSelected');
					return false;
				});
			});
