//***************** OBJEKT FUNKTIONEN ******************

//DOM-Type
var domtype=0;
if (document.getElementById) {
	domtype=1;
}
else if (document.all) {
	domtype=2;
}
else if (document.layers) {
	domtype=3;
}


//Objekt ID
function getobject(theid) {
	if ( domtype==1 ) return document.getElementById(theid);
	else if ( domtype==2 ) return document.all[theid];
	else if ( domtype==3 ) return document.layers[theid];
	return 0;
}


//in_array
function in_array(my_value,my_array){
	caseSensitive = in_array.arguments.length<3?0:in_array.arguments[2];

	for(i=0;i<my_array.length;i++){
		if((caseSensitive==0?my_array[i]:my_array[i].toUpperCase())==(caseSensitive==0?my_value:my_value.toUpperCase())){
			return true;
		}
	}

	return false;
}













/*** 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);
	}
}