if (HANZO === undefined) {
	var HANZO = {};
}
HANZO.ticker = function () {
	var ticker_delay = '8000'; 
	var hanzo_messages = new Array();
	var hanzo_i = 0;
	var HANZO_VERTICAL = 0;
	var HANZO_HORIZONTAL = 1;
	var HANZO_TYPING = 2;
	var hanzo_orientation = HANZO_VERTICAL;
	var hanzo_f = 26;
	
	function moveh(firstdiv, seconddiv) {
		this.div1 = eval(firstdiv);
		this.div2 = eval(seconddiv);
		if (parseInt(div1.style.left) > 0 && parseInt(div1.style.left) <= 4) {
		    div1.style.left = "0px";
		    setTimeout("HANZO.ticker.moveh(div1, div2)",ticker_delay);
		    return;
		}
		if (parseInt(div1.style.left) >= div1.offsetWidth * -1) {
		    div1.style.left = parseInt(div1.style.left) - 4 + "px";
		    setTimeout("HANZO.ticker.moveh(div1, div2)", 15);
		} else {
			setTimeout("HANZO.ticker.moveh(div2, div1)", 10);
		    div1.style.left = parseInt(ticker_width) + "px";
		    div1.innerHTML = hanzo_messages[hanzo_i];
		    if (hanzo_i === hanzo_messages.length-1) {
		      hanzo_i = 0;
		    } else {
		      hanzo_i++;
		    }
		}
	}
	
	function movev(firstdiv, seconddiv) {
		this.div1 = eval(firstdiv);
		this.div2 = eval(seconddiv);
		if (parseInt(div1.style.top) > 0 && parseInt(div1.style.top) <= 2) {
		    div1.style.top = "0px";
		    setTimeout("HANZO.ticker.movev(div1, div2)", ticker_delay);
		    return;
		}
		if (parseInt(div1.style.top) >= div1.offsetHeight * -1) {
		    div1.style.top = parseInt(div1.style.top) - 2 + "px";
		    setTimeout("HANZO.ticker.movev(div1, div2)", 25);
		} else {
		    div1.style.top = parseInt(ticker_height) + "px";
		    div1.innerHTML = hanzo_messages[hanzo_i];
		    if (hanzo_i === hanzo_messages.length-1) {
		      hanzo_i = 0;
		    } else {
		      hanzo_i++;
		    }
			setTimeout("HANZO.ticker.movev(div2, div1)", 10);
		}
	}
	function movet(firstdiv, action){
		this.div1 = eval(firstdiv);
		switch (action) {
			case "m":
				hanzo_f++;
				var text = hanzo_messages[hanzo_i];
				if (hanzo_f === text.length-6) {
					hanzo_f = 26;
					setTimeout("HANZO.ticker.movet(div1, 'n')", ticker_delay);
				} else {
					div1.firstChild.innerHTML = text.substring(26, hanzo_f);
					setTimeout("HANZO.ticker.movet(div1, 'm')", 10);
				}
				break;
			case "n":
				div1.firstChild.innerHTML = "";
			    if (hanzo_i === hanzo_messages.length-1) {
			      hanzo_i = 0;
			    } else {
			      hanzo_i++;
			    }
				setTimeout("HANZO.ticker.movet(div1, 'm')", 10);
				break;
		}
	}
	
	function cascadedstyle(el, cssproperty){
		if (el.currentStyle)
			return el.currentStyle[cssproperty]
		else if (window.getComputedStyle){
			var elstyle=window.getComputedStyle(el, "")
			return elstyle.getPropertyValue(cssproperty)
		}
	}
	
	function initTicker(ticker_div_name, delay, orientation) {
		var ticker_div = document.getElementById(ticker_div_name);
		if (delay !== undefined) {// otherwise use default value
			ticker_delay = delay;
		}
		if (orientation !== undefined) {// otherwise use default value
			if (orientation === 'H' || orientation === 'h' || orientation === 'horizontal' || orientation === HANZO_HORIZONTAL) {
				hanzo_orientation = HANZO_HORIZONTAL;			
			} else if (orientation === 'V' || orientation === 'v' || orientation === 'vertical' || orientation === HANZO_VERTICAL) {
				hanzo_orientation = HANZO_VERTICAL;
			} else {
				hanzo_orientation = HANZO_TYPING;
			}
		}
		var empty_ticker_message='<span class="ticker_text">Texto de exemplo para o caso de aus&ecirc;ncia de respostas dispon&iacute;veis na Campanha. Substitua pelo seu pr&oacute;prio texto.</span>';
		var empty_ticker_message2='<span class="ticker_text">Um bom exemplo: instru&ccedil;&otilde;es de como enviar uma resposta para a Campanha. Para editar estas mensagens troque o texto das linhas 108 e 109 do tickerHanzo.js</span>';
		
		var hanzo_t = new Ticker();
		
		var scroll = true;	
		if (hanzo_t != null && hanzo_t.feedbacks.length > 0) {
			for (var hanzo_g = 0; hanzo_g < hanzo_t.feedbacks.length; hanzo_g++) {
				hanzo_messages[hanzo_g] = '<span class="ticker_text">'+hanzo_t.feedbacks[hanzo_g].text+'</span>';
			}
		} else {
			hanzo_messages[0] = empty_ticker_message;
			hanzo_messages[1] = empty_ticker_message2;
		}
		if (hanzo_messages.length > 2) {
			hanzo_i = 2;
		} else {
			hanzo_i = 0;
		}
		// START:ADD: Text Lenght Test. To test, remove the comment "//" from the JavaScript bellow
		// hanzo_messages[0] = '<span class="text">Texto com 160 caracteres para testar se o tamanho definido no layout suporta mensagens grandes recebidas atraves de torpedos enviados dos celulares dos usuarios</span>';
		// END:ADD: Text Lenght Test.  To test, remove the comment "//" from the JavaScript above
			
		if (document.all || document.getElementById) {
			ticker_width = cascadedstyle(ticker_div, "width");
			ticker_height = cascadedstyle(ticker_div, "height");
			ticker_div.innerHTML = '<div style="overflow:hidden;position:relative;width:'+ticker_width+';height:'+ticker_height+';clip:rect(0px,0px,'+ticker_width+','+ticker_height+');left:0px;top:0px">' +
								'<div id="hanzo_first2" style="position:absolute;padding:4px;width:'+ticker_width+';left:1px;top:0px;">' +
								hanzo_messages[0] + 
								'</div>' + 
								'<div id="hanzo_second2" style="position:absolute;padding:4px;width:'+ticker_width+';left:0px;top:0px;visibility:hidden">' +
								hanzo_messages[dyndetermine = (hanzo_messages.length==1)? 0 : 1] + 
								'</div></div>';

		}
		first2_obj = document.getElementById("hanzo_first2");
		second2_obj = document.getElementById("hanzo_second2");
		switch (hanzo_orientation) {
				case HANZO_VERTICAL:
					movev(first2_obj, second2_obj);
					second2_obj.style.top = ticker_height;
					second2_obj.style.visibility = 'visible';
					break;
				case HANZO_HORIZONTAL:
					moveh(first2_obj, second2_obj);
					second2_obj.style.left = ticker_width;
					second2_obj.style.visibility = 'visible';
					break;
				case HANZO_TYPING:
					movet(first2_obj,'n');
					break;
		}	
	}
	return {
		initTicker: initTicker,
		moveh: moveh,
		movev: movev,
		movet: movet
	};
} ();
