/**
 *	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);
 *
 *
 *	Modifiziert zum Einsatz auf wunschliste.de
 *
 */

var gxScroller =
{

	addCssProperty : function (element, property, value)
	{
		if (value != 'nullpx')
			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)
	{
		var docloc = window.location.href;
		if (( docloc.indexOf('news') == -1 ) && ( docloc.indexOf('blog') == -1 ))
		{
			if (this.e[element]['displayCount'] == (this.e[element]['allDisplays']-1))
			{
				document.getElementById('newsbox_headtext').innerHTML = 'Aktuelle Diskussionen';
				document.getElementById('newsbox_bottomlink').innerHTML = '<a href="http://www.tvforen.de/" class="link">zum Forum</a>';
				floattext = 1;
			}
			else if ( floattext == 1)
			{
				document.getElementById('newsbox_headtext').innerHTML = 'TV-News';
				document.getElementById('newsbox_bottomlink').innerHTML = '<a href="/tvnews/" class="link">alle aktuellen Meldungen</a>';
				floattext = 0;
			}
		}
		else
		{
			if (this.e[element]['displayCount'] == (this.e[element]['allDisplays']-3))
			{
				document.getElementById('newsbox_headtext').innerHTML = 'TV-Tipp';
				document.getElementById('newsbox_bottomlink').innerHTML = '<a href="/tipps/" class="link">alle TV-Tipps</a>';
			}
			else if (this.e[element]['displayCount'] >= (this.e[element]['allDisplays']-2))
			{
				document.getElementById('newsbox_headtext').innerHTML = 'Specials';
				document.getElementById('newsbox_bottomlink').innerHTML = '<a href="/specials/" class="link">alle Specials</a>';
				floattext = 1;
			}
			else if ( floattext == 1)
			{
				document.getElementById('newsbox_headtext').innerHTML = 'weitere Meldungen';
				document.getElementById('newsbox_bottomlink').innerHTML = '<a href="/tvnews/" class="link">alle aktuellen Meldungen</a>';
				floattext = 0;
			}
		}

		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']			= 0;
				this.e[element]['currentValue'] 	= 0;
				this.e[element]['valueDifferenz'] 	= 0;
				this.e[element]['interval']			= null;
				window.setTimeout('new Function("", gxScroller.initScrolling("' + element + '", ' + duration + ', ' + stoppTime + ', true))', stoppTime * 3000);
			}
		}
	}
}

var floattext = 0;

gxScroller.addScroller('scroller', 300, 0);
gxScroller.initScrolling('scroller', 30, 5);

