<script type="text/javascript">
/**
*	Object zum dynamischen Scrollen von Inhalten.
*
*	Company: Gimmixx New Media
*	Programmer: Robert Engelhardt
*	E-Mail: engelhardt@gimmixx.de
*
*	Created: 03 01 2007
*
*
*	Element initialisierung:
*	------------------------
*	gxScroller.addScroller('scroller', 400, 20);
*	gxScroller.initScrolling('scroller', 50, 3);
*
*/

var gxScroller = {
    addCssProperty : function (element, property, value) {
	element.style[property] = value;
    },
    setStatusMessage : function (message) {
	window.status = message;
    },
    addScroller : function (element, width, padding) {
	if (this.e == null) {
	    this.e = {};
	}
	this.e[element] = {
	    element  			: (typeof element == 'object') ? element : document.getElementById(element),
	    top					: 0,
	    left				: padding,
	    displayHeight		: null,
	    allDisplays			: 0,
	    steps				: null,
	    displayCount		: 0,
	    newValue			: null,
	    currentValue		: null,
	    valueDifferenz		: null,
	    stoppFeadback		: false,
	    interval			: null
	};

	var obj = (this.e[element]['element'].firstChild.tagName == null) ? this.e[element]['element'].childNodes[1] : this.e[element]['element'].firstChild;
	var tds = obj.getElementsByTagName('td');

	this.addCssProperty(this.e[element]['element'], 'width', width + 'px');
	this.addCssProperty(this.e[element]['element'], 'position', 'relative');
	this.addCssProperty(this.e[element]['element'], 'overflow', 'hidden');

	this.addCssProperty(obj, 'position', 'relative');
	this.addCssProperty(obj, 'left', padding + 'px');
	this.addCssProperty(obj, 'top', '0px');
	this.addCssProperty(obj, 'width', (width - (padding * 2)) + 'px');

	for(var x = 0; x < tds.length; ++x) {
	    if (this.e[element]['displayHeight'] < (tds[x].offsetHeight  + (padding * 2))) {
		this.e[element]['displayHeight'] = tds[x].offsetHeight + (padding * 2);
	    }
	}
	for(var y = -1, x = 0; x < tds.length; ++x) {
	    this.addCssProperty(tds[x], 'height', this.e[element]['displayHeight'] + 'px');
	    this.addCssProperty(tds[x], 'cursor', 'pointer');

	    tds[x].element = element;
	    tds[x].onmouseover = function () {
		gxScroller.e[element]['stoppFeadback'] = true;
	    };

	    tds[x].onmouseout = function () {
		gxScroller.e[element]['stoppFeadback'] = false;
	    };
	}

	this.addCssProperty(this.e[element]['element'], 'height', this.e[element]['displayHeight'] + 'px');
	this.e[element]['allDisplays'] 	= tds.length;
	this.e[element]['element'] 		= obj;
    },

    easeOutQuint : function (t, b, c, d) {
	return c*((t=t/d-1)*t*t*t*t + 1) + b;
    },

    initScrolling : function (element, duration, stoppTime) {
	if(arguments[3] == null) {
	    window.clearTimeout(this.e[element]['interval']);
	    this.e[element]['steps']			= 0;
	    this.e[element]['newValue']			= -(this.e[element]['displayHeight'] * this.e[element]['displayCount']) - ((!window.opera && document.all) ? 1 : 0);
	    this.e[element]['currentValue']		= parseInt(this.e[element]['element'].style.top);
	    this.e[element]['valueDifferenz']	= this.e[element]['newValue'] - this.e[element]['currentValue'];
	    this.e[element]['interval']			= null;
	}
	if(this.e[element]['steps'] < duration) {
	    this.e[element]['element'].style.top = this.easeOutQuint(this.e[element]['steps'], this.e[element]['currentValue'], this.e[element]['valueDifferenz'], duration) + 'px';
	    if (!this.e[element]['stoppFeadback']) {
		this.e[element]['steps']++;
	    }
	    this.e[element]['interval'] = window.setTimeout('gxScroller.initScrolling("' + element + '", ' + duration + ', ' + stoppTime + ', true)', 10);
	}
	else {
	    if (++this.e[element]['displayCount'] < this.e[element]['allDisplays']) {
		window.clearTimeout(this.e[element]['interval']);
		window.setTimeout('new Function("", gxScroller.initScrolling("' + element + '", ' + duration + ', ' + stoppTime + '))', stoppTime * 1000);
	    }
	    else {
		window.clearTimeout(this.e[element]['interval']);
		this.e[element]['steps'] 			= 0;
		this.e[element]['displayCount']		= 0;
		this.e[element]['newValue']			= -(this.e[element]['displayHeight'] * this.e[element]['displayCount']);
		this.e[element]['currentValue'] 	= parseInt(this.e[element]['element'].style.top);;
		this.e[element]['valueDifferenz'] 	= this.e[element]['newValue'] - this.e[element]['currentValue'];
		this.e[element]['interval']			= null;
		window.setTimeout('new Function("", gxScroller.initScrolling("' + element + '", ' + duration + ', ' + stoppTime + ', true))', stoppTime * 1000);
	    }
	}
    }
};

function startScroller() {
    gxScroller.addScroller('scroller', 252, 20);
    gxScroller.initScrolling('scroller', 50, 3);
}
</script>

