// build by Lennart Hildebrandt (http://www.untalentiert.de)

function newsticker() {

	var __method = this;

	__method.entry_id = 0; // ID des Eintrags, mit dem gestartet werden soll
	__method.seconds_steps = 25; // Millisekunden zwischen den einzellnen Schritten der Bewegungen
	__method.wait_blend = 3000; // Zeit, die ein Eintrag verweilen soll
	__method.start_normal = true; // Ohne Blend-Effekt starten
	
	__method.entrys = '';
	__method.parent = 'newsticker';
	var position_top = new Array();
	var news_parent = '';
	var blend = new Array();
	var active_blend = new Array();
	active_blend[0] = 'first';
	active_blend[1] = 'second';
	var mouse_over = false;
	
	__method.start = function() {
		
		news_parent = document.getElementById(__method.parent);
		if(__method.start_normal == true) position_top['first'] = 0;
		else position_top['first'] = parseInt(news_parent.style.height);
		position_top['second'] = parseInt(news_parent.style.height);
		news_parent.innerHTML = '<div id="first_blend_' + __method.parent + '"></div><div id="second_blend_' + __method.parent + '"></div>';
		
		blend['first'] = document.getElementById('first_blend_' + __method.parent);
		blend['second'] = document.getElementById('second_blend_' + __method.parent);
		blend['first'].style.position = 'absolute';
		blend['second'].style.position = 'absolute';
		// Keine Zeilenumbrüche erlauben
		if(blend['first'].style.whiteSpace) {
			blend['first'].style.whiteSpace = 'nowrap';
			blend['second'].style.whiteSpace = 'nowrap';
		}
		blend['first'].style.top = position_top['first'] + 'px';
		blend['second'].style.top = position_top['second'] + 'px';
		
		// Blend-Effekt stoppen, wenn Maus über Layer
		news_parent.onmouseover = function() { mouse_over = true; }
		news_parent.onmouseout = function() { mouse_over = false; }
		
		putContent();
		
	}
	
	var putContent = function() {
		
		if(!mouse_over) {
			// Nächsten Blendeffekt-Layer ausrichten und mit Inhalt füllen
			if(!__method.start_normal)
				position_top[active_blend[0]] = parseInt(news_parent.style.height);
			blend[active_blend[0]].innerHTML = __method.entrys[__method.entry_id];
			__method.entry_id++;
			if(!__method.entrys[__method.entry_id]) __method.entry_id = 0;
			
			if(!__method.start_normal) moveBlend();
			else if(__method.entrys.length > 1) {
				active_blend[0] = 'second';
				active_blend[1] = 'first';
				__method.start_normal = false;
				window.setTimeout(putContent, __method.wait_blend);
			}
		}else window.setTimeout(putContent, 1);
		
	}
	
	var moveBlend = function() {
		
		// Blendeffekt-Layer bewegen
		if(position_top[active_blend[0]] != position_top[active_blend[1]]) {
			position_top[active_blend[1]]--;
			blend[active_blend[1]].style.top = position_top[active_blend[1]] + 'px';
		}
		position_top[active_blend[0]]--;
		blend[active_blend[0]].style.top = position_top[active_blend[0]] + 'px';
		if(position_top[active_blend[0]] == 0 && __method.entrys.length > 1) {
			if(active_blend[0] == 'first') {
				active_blend[0] = 'second';
				active_blend[1] = 'first';
			}else {
				active_blend[0] = 'first';
				active_blend[1] = 'second';
			}
			window.setTimeout(putContent, __method.wait_blend);
		}else if(position_top[active_blend[0]] > 0 || position_top[active_blend[0]] < 0) 
			window.setTimeout(moveBlend, __method.seconds_steps);
		
	}

}