jQuery(function(){
	$("nav.menu a, ul#responsive a, a.scrollData, a.scroll").click(function(event){
		var $a = $(this);
		var speed = 100; // pixels per second
		
		//get the full url - like mysitecom/index.htm#home
		var full_url = this.href;

		//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
		var parts = full_url.split("#");
		var trgt = parts[1];

		//get the top offset of the target anchor
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top;

		var thisElement = $(this).offset();
		var difference = thisElement.top - target_top;
		if ( difference < 0  )
		{
			difference = difference * -1;
		}
		// determine scrollspeed
		var minspeed = 500;
		var maxspeed = 2000;
		var speed = difference / 4;
		if(speed < minspeed) speed = minspeed;
		if(speed > maxspeed) speed = maxspeed;
		
		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:target_top}, speed, function(){
			window.location.href = $a.attr('href');
		});
		
		return false;
	});
	
});
