//@Class SmoothScrillingBox START
function SmoothScrillingBox () {
	this.myName			= '';

	this.Offset			= 0;
	this.GlobalObj		= false;
	this.textHeight		= 0;
	this.viewBoxHeight	= 0;
	this.scrollRange	= 0;
	this._timeout;

	this.ScrollBy		= 200;

	this.Init = function ( obj, varname, ViewPartSize ) {
		this.myName = varname;
		this.GlobalObj = obj;
		this.viewBoxHeight = ViewPartSize;
		this.textHeight = this.GlobalObj.clientHeight;
		this.GlobalObj.style.top = this.Offset + 'px';
		this.scrollRange = this.textHeight - this.viewBoxHeight;
	}

	this.startScroll = function ( down ) {
//		dbg('Scroll called! ' + this.Offset + ' ? ' + this.textHeight);

		if ( down ) {
			this._smooth ( -1 * this.ScrollBy, 20, true );
		} else {
			this._smooth ( this.ScrollBy, 20, true);
		}
		return false; // Disable default events
	}

	this._smooth = function ( distance, mtime ) {
		obj = this.GlobalObj;
//		dbg('Distance: ' + distance + 'px; for: ' + mtime + ' msec');
		var next_dist = false;
		if ( Math.abs( distance ) > 5 ) {
			clearTimeout ( this._timeout );
		} else {
			return;
		}

//		dbg (this.Offset + (distance * 0.05) + ' >= ' + this.scrollRange);
		if ( -1 * (this.Offset + (distance * 0.05))  >= this.scrollRange ) {
			this.Offset = -1 * this.scrollRange;
		} else if ( this.Offset + (distance * 0.05) >= 0 ) {
			this.Offset = 0;
		} else {
			this.Offset += distance * 0.05;
			next_dist = distance * 0.95;
		}

		obj.style.top = this.Offset + 'px';
			// TODO [ScrollIntegration]: Add scrollbar to Init
			first_sb.setToPerc( ( -100 * this.Offset ) / this.scrollRange );
			if ( next_dist )
				this._timeout = setTimeout (this.myName + '._smooth(' + next_dist +', ' + mtime + ', false)', mtime );

//		dbg ('first_sb.setToPerc( ' + (-100*Offset)/textHeight + ' )');

	}
}//SmoothScrillingBox END

function kiksscrollbar () {
	var p_current	= 0;
	var p_max		= 0;

	var my_height	= 0;
	var myBoxSize	= 0;

	var o_holeder	= false;
	var o_box		= false;

	this.Init = function ( max, holder, box ) {
		this.p_max		= max;
		this.o_holeder	= holder;
		this.o_box		= box;

		this.my_height	= holder.clientHeight;
		this.myBoxSize	= box.clientHeight;
	} 

	this.setTo = function ( int ) {
		if (this.p_max<int)
			int = this.p_max;
		if ( int>0 ) {
			this.MoveTo( int/this.p_max );
		}
	}

	this.setToPerc = function ( perc ) {
			this.MoveTo( perc / 100 );
	}

	// Sets the box in the scrollbar to sonme offset from top. Works with percentages, represented in float arg 
	this.MoveTo = function ( float ) {
//		dbg('MoveTo(' + float + ');');

		if ( float < 0 )	float = 0;
		if ( float > 100 )	float = 100;

		this.p_current = float;
		this.o_box.style.top = ( this.p_current * (this.my_height - this.myBoxSize) ) + 'px';

//		dbg('Move ScrollBar to: ' + this.p_current * this.my_height + 'px');
	}

	this.clicked = function () {
		dbg('ScrollBox Clicked');
	}

	this.released = function () {
		dbg('ScrollBox Released');
	}
}
