;(function($) {
	$.fn.gowhere = function(options) {
		var settings = {
			delay: 1500
		};
		if (options) $.extend(settings, options);
		
		var $anchors = $(this);
		var $scollerContainer = $('html:not(:animated),body:not(:animated)');
		
		var scrolling = false;
		var baseUrl;
		
		var init = function() {
			baseUrl = getHrefWithoutAnchor();
			$anchors.click(pageRedirect);
		};
		
		var getHrefWithoutAnchor = function() {
			var href = window.location.href;
			var anchorStartPosition = href.indexOf('#');
			// if not found anchor, return
			if ( anchorStartPosition == -1 ) {
				return href;
			}
			return href.substring(0, anchorStartPosition);
		};
		
		var pageRedirect = function() {
			if ( scrolling ) {
				return;
			}
			scrolling = true;
			var elementClicked = $(this).attr('href');
			var destination = $(elementClicked).offset().top;
			$scollerContainer.animate({scrollTop: destination}, settings.delay, '', function() {
				var theUrl = baseUrl + elementClicked;
				if ( theUrl != window.location.href ) {
					window.location.href = theUrl;
				}
				scrolling = false;
			});
			return false;
		};
		
		init();
	};
})(jQuery);
