$(document).ready(function() {

	$("a.anchorLink").anchorAnimate({topmargin : 0})

});



jQuery.fn.anchorAnimate = function(settings) {

	settings = jQuery.extend({

	speed : 700,

	topmargin : 0,

	}, settings);	

	

	return this.each(function(){

		var caller = this

		$(caller).click(function (event) {	

			event.preventDefault()

			var locationHref = window.location.href

			var locationHrefClean = deleteAnchor(locationHref);

			var destHref = $(caller).attr("href");

			var destHrefClean = deleteAnchor(destHref);

			var destanchor = $(caller).attr("hash");

			if (locationHrefClean == destHrefClean || locationHref == 'http://www.talentsdemode.com/' || locationHref == 'http://www.talentsdemode.com') {

				var destination = $(destanchor).offset().top-settings.topmargin;

				$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed);

				return false;

			} else {

				window.location = destHref;

			}

		})

	})

}



function deleteAnchor(url) {

	var anchorpos = url.indexOf('#');

	if ( anchorpos != -1) {

		url = url.substring(0,anchorpos);

	}

	return url;

}
