
/*** TRIM FUNKTIONEN ***/

function LTrim( value ) {	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

function trim( value ) {
	return LTrim(RTrim(value));
}



/*** PRELOADER ***/

function preloadImages( images ) {
	var imageCache = new Array();
	for ( var i=0; i<images.length; i++ ) {
		var path = images[i];
		path = path.replace(/&amp;/g,'&');
		imageCache[i] = new Image();
		imageCache[i].src = path;
	}
}


/*** SCROLLER ****/

//HORIZONTAL
function HorizontalScroller( scrollerId ) {
	this.scroller = getobject(scrollerId);
	this.currentSpeed = 0;
	this.timer;
	this.acceleration = 1;
	this.maxacc = 10;
	this.timing = 50;
	this.maxOffset = null;
	
	//Nach links
	this.scrollLeft = function() {
		clearTimeout(this.timer);
		if ( this.maxOffset==null ) {
			this.maxOffset = this.scroller.scrollWidth;
		}
		if ( this.currentSpeed<this.maxacc ) this.currentSpeed += this.acceleration;
		var xpos = this.scroller.scrollLeft;
		if( 0<this.maxOffset ){
			xpos -= this.currentSpeed;
			var oldpos = this.scroller.scrollLeft;
			this.scroller.scrollLeft = xpos;
			if ( oldpos==this.scroller.scrollLeft ) {
				this.stop();
			}
			else {
				var self = this;
				this.timer = setTimeout(function() { self.scrollLeft(); }, this.timing);
			}
		}
		else {
			this.stop();
		}
	}
	
	//Nach rechts
	this.scrollRight = function() {
		clearTimeout(this.timer);
		if ( this.maxOffset==null ) {
			this.maxOffset = this.scroller.scrollWidth;
		}
		if ( this.currentSpeed<this.maxacc ) this.currentSpeed += this.acceleration;
		var xpos = this.scroller.scrollLeft;
		if( xpos<this.maxOffset ){
			xpos += this.currentSpeed;
			var oldpos = this.scroller.scrollLeft;
			this.scroller.scrollLeft = xpos;
			if ( oldpos==this.scroller.scrollLeft ) {
				this.stop();
			}
			else {
				var self = this;
				this.timer = setTimeout(function() { self.scrollRight(); }, this.timing);
			}
		}
		else {
			this.stop();
		}
	}
	
	//Scroll beenden
	this.stop = function() {
		this.currentSpeed = 0;
		clearTimeout(this.timer);
	}
}


//VERTIKAL
function VerticalScroller( scrollerId ) {
	this.scroller = getobject(scrollerId);
	this.currentSpeed = 0;
	this.timer;
	this.acceleration = 1;
	this.maxacc = 20;
	this.timing = 50;
	this.maxOffset = null;
	//Nach oben
	this.scrollUp = function() {
		clearTimeout(this.timer);
		if ( this.maxOffset==null ) {
			this.maxOffset = this.scroller.scrollHeight;
		}
		if ( this.currentSpeed<this.maxacc ) this.currentSpeed += this.acceleration;
		var xpos = this.scroller.scrollTop;
		if( 0<this.maxOffset ){
			xpos -= this.currentSpeed;
			var oldpos = this.scroller.scrollTop;
			this.scroller.scrollTop = xpos;
			if ( oldpos==this.scroller.scrollTop ) {
				this.stop();
			}
			else {
				var self = this;
				this.timer = setTimeout(function() { self.scrollUp(); }, this.timing);
			}
		}
		else {
			this.stop();
		}
	}
	
	//Nach unten
	this.scrollDown = function() {
		clearTimeout(this.timer);
		if ( this.maxOffset==null ) {
			this.maxOffset = this.scroller.scrollHeight;
		}
		if ( this.currentSpeed<this.maxacc ) this.currentSpeed += this.acceleration;
		var xpos = this.scroller.scrollTop;
		if( xpos<this.maxOffset ){
			xpos += this.currentSpeed;
			var oldpos = this.scroller.scrollTop;
			this.scroller.scrollTop = xpos;
			if ( oldpos==this.scroller.scrollTop ) {
				this.stop();
			}
			else {
				var self = this;
				this.timer = setTimeout(function() { self.scrollDown(); }, this.timing);
			}
		}
		else {
			this.stop();
		}
	}
	
	//Scroll beenden
	this.stop = function() {
		this.currentSpeed = 0;
		clearTimeout(this.timer);
	}
}