/*
 * 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 = "pagina";

function initDivToAnchor() {

	if( document.getElementById ){
	
		var atags = document.getElementsByTagName( "A" );
		var ca;
		
		for( var i = 0; i < atags.length; i++ ){
		
			ca = atags[i];
			
			if( ca.pathname.indexOf( document.location.pathname ) > -1 && ca.href.indexOf( "#" ) > -1 ){
				
				ca.apartat = ca.href;
				
				ca.onclick = function() {
				
					scrollDivToAnchor( this.apartat.split( "#" )[1] );
				}
				
				ca.href = null;
				ca.style.cursor = "pointer";
			}
		}
	}
}

function scrollDivToAnchor( a ) {
	
	var b = document.getElementById( targBox );
	b.scrollTop = document.getElementById( a ).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

}
