function lib_bwcheck(){
    this.ver = navigator.appVersion
    this.agent = navigator.userAgent
    this.dom = document.getElementById ? 1 : 0
    this.opera5 = ( navigator.userAgent.indexOf( "Opera" ) > -1 && document.getElementById ) ? 1 : 0
    this.ie5 = ( this.ver.indexOf( "MSIE 5" ) > -1 && this.dom && ! this.opera5 ) ? 1 : 0
    this.ie6 = ( this.ver.indexOf( "MSIE 6" ) > -1 && this.dom && ! this.opera5 ) ? 1 : 0
    this.ie4 = ( document.all && ! this.dom && ! this.opera5 ) ? 1 : 0
    this.ie = this.ie4 || this.ie5 || this.ie6
    this.mac = this.agent.indexOf( "Mac" ) > -1
    this.ns6 = ( this.dom && parseInt( this.ver ) >= 5) ? 1 : 0
    this.ns4 = ( document.layers && ! this.dom ) ? 1 : 0
    this.bw = ( this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5 )
    return this
}

var bw=lib_bwcheck()

/*********************************************************************************
These are the variables you have to set:
*********************************************************************************/

//The speed of the timeout between each scroll.
timSpeed = 50

//The speed of the timeout between each size check.
sizSpeed = 25

//The height of the container (change this when it scrolls to much or to little)
var seScrlcontHeight = 300;

/*********************************************************************************
This is the object constructor function, which applies 
methods and properties to the Cross-browser layer object
*********************************************************************************/
function makeScrollObj( obj, nest ){
	nest = ( ! nest ) ? ""
                      : 'document.' + nest + '.'
                     
	this.el = bw.dom ? document.getElementById( obj )
                     : bw.ie4 ? document.all[obj]
                              : bw.ns4 ? eval( nest + 'document.' + obj )
                                       : 0
                                       
  	this.css = bw.dom ? document.getElementById( obj ).style
                      : bw.ie4 ? document.all[obj].style
                               : bw.ns4 ? eval( nest + 'document.' + obj )
                                        : 0
	this.height = bw.ns4 ? this.css.document.height
                         : this.el.offsetHeight
	this.top=b_gettop
	return this
}

// A unit of measure that will be added when setting the position of a layer.
var px = bw.ns4 || window.opera ? ""
                                : "px"

/*********************************************************************************
This is the function, which sets layer X position
*********************************************************************************/
function setXPos( obj, xval, nest ){
  	nest = ( ! nest ) ? ""
                      : 'document.' + nest + '.'
  	bw.dom ? document.getElementById( obj ).style.left = xval + px
           : bw.ie4 ? document.all[obj].style.left = xval + px
                    : bw.ns4 ? eval( nest + 'document.' + obj )
                             : 0
	return;
}

/*********************************************************************************
This is the function, which gets layer X position
*********************************************************************************/
function getXPos( obj, nest ){
  	nest = ( ! nest ) ? ""
                      : 'document.' + nest + '.'
  	return bw.dom ? document.getElementById( obj ).style.left
                  : bw.ie4 ? document.all[obj].style.left
                           : bw.ns4 ? eval( nest + 'document.' + obj )
                                    : 0
}

/*********************************************************************************
This is the function, which sets layer Y position
*********************************************************************************/
function setYPos( obj, yval, nest ){
  	nest = ( ! nest ) ? ""
                      : 'document.' + nest + '.'
  	bw.dom ? document.getElementById( obj ).style.top = yval + px
           : bw.ie4 ? document.all[obj].style.top = yval + px
                    : bw.ns4 ? eval( nest + 'document.' + obj )
                             : 0
	return;
}

/*********************************************************************************
This is the function, which gets layer Y position
*********************************************************************************/
function getYPos( obj, nest ){
  	nest = ( ! nest ) ? ""
                      : 'document.' + nest + '.'
  	return bw.dom ? document.getElementById( obj ).style.top
                  : bw.ie4 ? document.all[obj].style.top
                           : bw.ns4 ? eval( nest + 'document.' + obj )
                                    : 0
}

//Getting the top for the top method
function b_gettop(){
	var gleft = ( bw.ns4 || bw.ns6 ) ? parseInt( this.css.top )
                                     : eval( this.css.pixelTop )
	return gleft
}

//Variables
var scrollTim = 1
var sizeTim = 2
var imageTim = 3

var seScrlDefX = 840
var seScrlDefY = 188
var seScrlDx = -340
var seScrlDy = 170
    
/*********************************************************************************
Checks if an object really exists.
*********************************************************************************/
function seObjExist( obj, nest ){
  	nest = ( ! nest ) ? ""
                      : 'document.' + nest + '.'
    return bw.dom ? document.getElementById( obj )
                  : bw.ie4 ? document.all[ obj ]
                           : bw.ns4 ? eval( nest + 'document.' + obj )
                                    : 0
}

/*********************************************************************************
The scroll function. Checks what way to scroll and checks if the
layer is not already on top or bottom.
*********************************************************************************/
function scrollSimple( speed, active ) {
    clearTimeout( scrollTim )
    way = speed > 0 ? 1 : 0
    if ( ( ! way && oScroll[active].top() > - oScroll[active].height + seScrlcontHeight ) || ( oScroll[active].top() < 0 && way ) ){
        oScroll[active].css.top = ( oScroll[active].top() + speed ) + px
        scrollTim = setTimeout( "scrollSimple( " + speed + ", " + active + " )", timSpeed )
    }
}

/*********************************************************************************
The single scroll function. Checks what way to scroll and checks if the
layer is not already on top or bottom.
*********************************************************************************/
function scrollMore( speed, active ) {
    way = speed > 0 ? 1 : 0
    if ( ( ! way && oScroll[active].top() > - oScroll[active].height + seScrlcontHeight ) || ( oScroll[active].top() < 0 && way ) )
        oScroll[active].css.top = ( oScroll[active].top() + speed ) + px
}

//Clears the timeout so the scroll stops, this is called onmouseout.
function noScroll(){
	clearTimeout( scrollTim )
}

/*********************************************************************************
Put the specified layer in the specified place
*********************************************************************************/
function layerSet() {
	clearTimeout( sizeTim )
    
    // Find the center of the document area
    if( bw.ns4 || bw.ns6 ) {
      avail_width = innerWidth
      avail_height = innerHeight
    } else if( bw.ie ) {
      avail_width = document.body.clientWidth
      avail_height = document.body.clientHeight
    }

    if( getXPos( 'divContain' ) != avail_width / 2 - seScrlDx )
      if( avail_width > 1000 )
        setXPos( 'divContain', avail_width / 2 - seScrlDx );
      else
        setXPos( 'divContain', seScrlDefX )

    if( getYPos( 'divContain' ) != avail_height / 2 - seScrlDy )
      if( avail_height < 0 )
        setYPos( 'divContain', avail_height / 2 - seScrlDy )
      else
        setYPos( 'divContain', seScrlDefY )

    sizeTim = setTimeout( "layerSet()", sizSpeed )
    return
}

/*********************************************************************************
Initilizes the page, makes a oScroll Array and calls the object constructor.
Here you can add as many scrollObjects as you want
*********************************************************************************/
function scrollInit(){
	oScroll = new Array()
	
	// You can add and remove scrollObjects here.
	oScroll[0] = new makeScrollObj( 'divScroll', 'divContain' )
	
	oScroll[0].css.left = 0 + px
	oScroll[0].css.top = 0 + px
	oScroll[0].css.visibility = "visible"
    
    layerSet()
}

/*********************************************************************************
Remember to executes the scrollInit function on pageload.
*********************************************************************************/

