/*******
	This will link to an element with an ID the same as the anchor link, OR to a proper anchor (whichever's first)
	You can use and modify this script for any project you want, but please leave this comment as credit.
*****/
$(document).ready(function() {
	$("a.anchorLink").anchorAnimate()
	$("area.anchorLink").anchorAnimate()
	$("select.anchorLink").anchorAnimate()
});

jQuery.fn.anchorAnimate = function(settings) {

 	settings = jQuery.extend({
		speed : 400
	}, settings);	
	
	return this.each(function(){
		var caller = this
		if (this.tagName.toLowerCase() != 'select') {
			$(caller).click(function (event) {	
				event.preventDefault()
				var locationHref = window.location.href
				var elementClick = $(caller).attr("href")
				var destination = $(elementClick+",a[name="+elementClick.substr(1)+"]").offset().top;
				$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
					window.location.hash = elementClick
				});
				return false;
			})
		} else {
			$(caller).bind('change', function (event) {	
				event.preventDefault()
				var locationHref = window.location.href
				var elementClick = this[this.selectedIndex].value;
				if (elementClick) {
					elementClick = '#'+elementClick;
					var destination = $(elementClick+",a[name="+elementClick.substr(1)+"]").offset().top;
					$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
						window.location.hash = elementClick
					});
				}
			})
		}
	})
}