/*--------------------------------------------------------------------------
 *  Smooth Scroller Script, version 1.0.1
 *  (c) 2007 Dezinerfolio Inc. <midart@gmail.com>
 *
 *  For details, please check the website : http://dezinerfolio.com/
 *
/*--------------------------------------------------------------------------*/

Scroller = {
	speed:10,

	gy: function (d) {
		gy = d.offsetTop
		if (d.offsetParent) while (d = d.offsetParent) gy += d.offsetTop
		return gy
	},

	scrollTop: function (){
		body=document.body
		d=document.documentElement
		if (body && body.scrollTop) return body.scrollTop
		if (d && d.scrollTop) return d.scrollTop
		if (window.pageYOffset) return window.pageYOffset
		return 0
	},

	add: function(event, body, d) {
		if (event.addEventListener) return event.addEventListener(body, d,false)
		if (event.attachEvent) return event.attachEvent('on'+body, d)
	},

	end: function(e){
		if (window.event) {
			window.event.cancelBubble = true
			window.event.returnValue = false
			return;
		}
		if (e.preventDefault && e.stopPropagation) {
			e.preventDefault()
			e.stopPropagation()
		}
	},

	scroll: function(d){
		i = window.innerHeight || document.documentElement.clientHeight;
		h=document.body.scrollHeight;
		a = Scroller.scrollTop()
		if(d>a)
			if(h-d>i)
				a+=Math.ceil((d-a)/Scroller.speed)
			else
				a+=Math.ceil((d-a-(h-d))/Scroller.speed)
		else
			a = a+(d-a)/Scroller.speed;
		window.scrollTo(0,a)
		if(a==d || Scroller.offsetTop==a)clearInterval(Scroller.interval)
		Scroller.offsetTop=a
	},
	init: function(){
		Scroller.add(window,'load', Scroller.render)
	},

	render: function(){
		a = document.getElementsByTagName('a');
		Scroller.end(this);
		window.onscroll
		for (i=0;i<a.length;i++) {
			l = a[i];
			if(l.href && l.href.indexOf('#') != -1 && ((l.pathname==location.pathname) || ('/'+l.pathname==location.pathname)) ){
			Scroller.add(l,'click',Scroller.end)
				l.onclick = function(){
					Scroller.end(this);
					l=this.hash.substr(1);
					var tagname = new Array('a', 'span');
					for (x in tagname)
						for (xx in b = document.getElementsByTagName(tagname[x]))
							if(b[xx].name == l || b[xx].id == l){
								clearInterval(Scroller.interval);
								Scroller.interval=setInterval('Scroller.scroll('+Scroller.gy(b[xx])+')',10);
							}
				}
			}
		}
	}
}
Scroller.init();