﻿/*
 * Javascript fix for Safari's inability to link to named anchors (or ids of elements) inside 
 * elements with overflow: auto set
 *
 * see http://blog.deconcept.com/code/overflowsafari/overflowsafari.html
 * for more information
 *
 * by Geoff Stearns ( geoff @ deconcept.com )
 *
 */


// the id of the element with overflow: auto set, in this case the div
var targBox = "box";

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;
}
