function PagesNav ( element ) {
	this.t = element
	this.wOut = this.t.scrollWidth
	this.list = this.t.getElementsByTagName( 'div' )[0]
	this.wIn = this.list.scrollWidth
	this.proportion = this.wIn / this.wOut
	this.wScr = Math.round( this.wOut / this.proportion )
	
	this.scrollBar = document.createElement( 'div' )
	this.scrollBar.className = 'scrollbar'
	this.t.appendChild( this.scrollBar )
	if ( this.proportion <= 1 ) return false
	this.scroller  = document.createElement( 'div' )
	this.scroller.style.width = this.wScr + 'px'
	this.scrollBar.appendChild( this.scroller )
	obj = this

	this.t.onselectstart = function () { return false }

	this.scrollToCurrent = function () {
				var cur = obj.list.getElementsByTagName('span')[0]
				obj.list.scrollLeft = getX( cur ) - getX( obj.scrollBar ) - 100
				obj.scroller.style.marginLeft = Math.min(
					( ( getX( cur ) - getX( obj.scrollBar ) - 100 ) / obj.proportion ),
					( this.wOut - this.wScr )
				) + 'px'
			}

	this.setL =	function ( e ) {
				obj.l = 0
				var o = obj.scrollBar
				if ( o.offsetParent )
					do { obj.l += o.offsetLeft } while ( o = o.offsetParent )
				obj.l2 = 0
				o = obj.scroller
				if (o.offsetParent)
					do { obj.l2 += o.offsetLeft } while ( o = o.offsetParent )
				
				obj.l = e.clientX - ( obj.l2-obj.l )
				obj.l2 = obj.wOut - obj.wScr
			}

	this.drag =	function ( e ) {
				e = e || event
				obj.setL( e )
				document.onmousemove = obj.move
			}

	this.drop =	function ( e ) {
				document.onmousemove = function () {}
			}

	this.move =	function ( e ) {
				e = e || event
				var l = Math.max( 0, Math.min( e.clientX - obj.l, obj.l2 ) )
				obj.scroller.style.marginLeft = l + 'px'
				obj.list.scrollLeft = Math.round( l * obj.proportion )
			}

	this.scrollBar.onmousedown = this.drag
	document.onmouseup = this.drop
	obj.scrollToCurrent()
/*
	this.list.onmousedown = this.drag2

	this.drag2 =	function (e) {
				e = e || event
				obj.setL(e)
				document.onmousemove = obj.move2
			}

	this.move2 =	function (e) {
				e = e || event
				var l = obj.wIn - obj.wOut - (e.clientX-obj.l)
				obj.list.scrollLeft = Math.round(l)
			}
*/

}

function getX ( element ) {
	var x = 0
	while (element) {
		x += element.offsetLeft
		element = element.offsetParent
	}
	return x
}
