/*
	-> Scroll Div
	internal links smooth scrolling in a fixed-height div
	
	coded in december 2006 by pinit.
	http://me.pinit.it

	(feel free to use but please keep this comment!)
*/
	      
var scrolldiv = {
	mydivheight : 400, // your div height
	mydiv : "box", // your div id
	
	mytravel : null,
	
	maxpos : 0,
	
	fire : function() {
		// this finds internal links and add them an onclick event 
		// important: name links with numbers starting by 0 (ex. #0 #1 #2)
		var mylinks = document.getElementsByTagName('a');
		for (var i=0;i<mylinks.length;i++) {
			var lnk = mylinks[i];  
			if ((lnk.href && lnk.href.indexOf('#') != -1) && ( (lnk.pathname == location.pathname) || ('/'+lnk.pathname == location.pathname) ) && (lnk.search == location.search)) {
				posizione = parseInt(lnk.href.substr((lnk.href.search("#"))+1));
				if (posizione>this.maxpos) {this.maxpos = posizione;}
				if (posizione>0) {posizione = posizione*scrolldiv.mydivheight;} else {posizione = 0;}
				lnk.pos = posizione;
				lnk.onclick = function() {
					scrolldiv.to(this.pos);
					return false;
				}
			}      
     	}
     	this.maxpos*=scrolldiv.mydivheight;
	},
	
	to : function(posizione) {
		if (this.mytravel != null) {clearInterval(this.mytravel);}	
		this.mytravel = setInterval("scrolldiv.travelling("+posizione+")",80); 			 
	},
	
	travelling : function(pos) {
		divpos = document.getElementById(scrolldiv.mydiv);
		if (divpos.scrollTop == pos) {
			clearInterval(this.mytravel); 
		    this.mytravel = null; 
		} else if(Math.abs(divpos.scrollTop-pos) > 1) {
			divpos.scrollTop = divpos.scrollTop+(pos-divpos.scrollTop)/2;
		} else {
			arrotonda = " " + divpos.scrollTop;
			if (arrotonda.indexOf("99") != -1) {divpos.scrollTop++;} else {divpos.scrollTop--;} 
			clearInterval(this.mytravel); 
		    this.mytravel = null; 
		}
		// this is for some debug output (in a div with id="debug")
		// document.getElementById("debug").innerHTML = "pos:" + divpos.scrollTop + "|target:" + pos + "|maxpos:" + this.maxpos;
	}
};