ISO.addModule('smoothScroll',function()
{
	self.addEvent(_w,'load',init);
	
	function init()
	{
		var e = $$('a',_d.body);
		
		for(var i=0,l=e.length;i<l;i++)
		{
			var ref = e[i].href;
			var loc = (_l.href.lastIndexOf('#') >= 0)? _l.href.substring(0,_l.href.lastIndexOf('#')): _l.href;
			ref = ref.replace(loc,'');
			
			var s = ref.lastIndexOf('#');
			if(s == 0)
			{
				ref = ref.substring(s+1);
				e[i].ref = ref;
				
				e[i].onclick = function()
				{
					smoothScroll(this.ref);
				};
				
				e[i].href = 'javascript:void(0);'
			}
		}
	}
	
	function smoothScroll(id)
	{
		var e2 = $(id);
		if(e2)
		{
			var posi = e2.offsetTop;
			var w = self.window;
			var scroll = w.scroll()[1];
			
			var handler = setInterval(function()
			{
				scroll += (posi - scroll)/2;
				w.scroll(null,scroll);
				
				if(Math.abs(posi - scroll) < 2)
				{
					w.scroll(null,posi);
					clearInterval(handler);
				}
			},40);
		}
		else
		{
			_l.href = _l.href+'#'+id;
		}
	}
});

