﻿/*
 * 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
 *
 * Original script by Geoff Stearns ( geoff @ deconcept.com )
 *
 */


// the id of the element with overflow:auto set
var target = "section";

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(target);
    b.scrollTop = document.anchors[a].offsetTop - b.offsetTop;
}

if (navigator.userAgent.indexOf("Safari") > -1 ||
    navigator.userAgent.indexOf("Konqueror") > -1) {
    window.onload = init;
}
