/**
 * 123plakat.de - Content Management System
 *
 * This is the HOTLINE JS DOCUMENT
 * of the 123plakat.de - content managament system frontend
 *
 * @file    hotline.js
 * @author  dpi one <www.dpi-one.de>
 */


jQuery(document).ready(function() {
	animateHotlineInit();
//	if (jQuery.browser.msie && jQuery.browser.version < 7) {
//		jQuery('SPAN#hotline-text1').css({'background': '#FFFFFF'});
//		jQuery('SPAN#hotline-text2').css({'background': '#FFFFFF'});
//	}
//	if (jQuery.browser.msie && jQuery.browser.version > 7) {
//		jQuery('SPAN#hotline-text1').css({'display': 'inline-block'});
//	}
	window.setTimeout('animateHotlineText()', 5000);
});

function animateHotlineInit(){
	var value1 = jQuery('SPAN#hotline-number1').text();
	var value2 = jQuery('SPAN#hotline-number2').text();
	if (!value1 || !value2 || value1.length != value2.length) return;
	var newValue1 = '';
	var newValue2 = '';
	var index1 = 0, index2 = 0;
	for (var i = 0; i < value1.length; i++) {
		if (value1.substr(i, 1) != ' ') {
			newValue1 += '<span id="hotline-number1-' + index1 + '">' + value1.substr(i, 1) + '</span>';
			index1++;
		} else {
			newValue1 += ' ';
		}
		if (value2.substr(i, 1) != ' ') {
			newValue2 += '<span id="hotline-number2-' + index2 + '">' + value2.substr(i, 1) + '</span>';
			index2++;
		} else {
			newValue2 += ' ';
		}
	}
	jQuery('SPAN#hotline-number1').html(newValue1);
	jQuery('SPAN#hotline-number1 SPAN').each(function() {
		if (typeof(this.style.removeAttribute) == 'function') this.style.removeAttribute('filter');
	});
	jQuery('SPAN#hotline-number2').html(newValue2);
	window.setTimeout('animateHotline(0, ' + Math.min(index1, index2) + ')', 2000);
//	if (jQuery.browser.msie && jQuery.browser.version > 7) {
//		jQuery('SPAN#hotline-number1 SPAN').css({'display': 'inline-block'});
//	}
}

function animateHotline(index, max) {
	var elem1 = jQuery('SPAN#hotline-number1-' + index);
	var elem2 = jQuery('SPAN#hotline-number2-' + index);
	var value = elem1.text();
	if (elem1.text() != ' ' || elem2.text() != ' ') {
		elem1.fadeOut('slow', function() {
			elem1.text(elem2.text());
			elem2.text(value);
			elem1.fadeIn('slow', function() {
				var next = (index + 1 < max);
				window.setTimeout('animateHotline(' + (next ? (index + 1) : 0) + ', ' + max + ')', (next ? 1000 : 5000));
			});
		});
	} else {
		animateHotline((index + 1 < jQuery('SPAN#hotline-number1').text().length) ? (index + 1) : 0, max);
	}
}

function animateHotlineText() {
	if (!jQuery('SPAN#hotline-text1').text() || !jQuery('SPAN#hotline-text2').text()) return;
	jQuery('SPAN#hotline-text1').fadeOut('slow', function() {
		var value = jQuery('SPAN#hotline-text1').text();
		jQuery('SPAN#hotline-text1').text(jQuery('SPAN#hotline-text2').text());
		jQuery('SPAN#hotline-text2').text(value);
		jQuery('SPAN#hotline-text1').fadeIn('slow', function() {
			window.setTimeout('animateHotlineText()', 5000);
		});
	});
}