﻿// the id of the element with overflow: auto set, in this case the div

var targBox = "content_scroll";



function init() {

	if (document.getElementById) {

		var atags = document.getElementsByTagName("A");

		for (var i=0;i<atags.length;i++) {

			var ca = atags[i];

			if (ca.href.indexOf("#") > -1) {

				ca.onclick = function() {

					scrollDivToAnchor(this.href.split("#")[1]);

				}

			}

		}

	}

}



function scrollDivToAnchor(a) {



	var b = document.getElementById(targBox);

	b.scrollTop = document.getElementById(a).offsetTop - b.offsetTop;



	// alternately, if your elements are not nested within other nodes inside the box,

	// you could use document.getElementById(a).parentNode.scrollTop

	// that way you wouldn't need to specify the id of the scrollable box



}



if (navigator.userAgent.indexOf("Safari") > -1) {

	window.onload = init;

}