/**
 * ticker
 * @package macem page
*/

var ticker = {
	tickerarray: null,  /* speed up some */
	
	init : function () {
    //if (!dom.hasClass(document.body, "edit")) {  // FF bug for fckeditor
			window.setInterval (function(evt) {
		    var container = dom.byId('container');
				if (container) {

					if(ticker.tickerarray) {
				    var tickers = ticker.tickerarray;
				  } else {
						var tickers = dom.byClassName (container, 'paneticker');
						ticker.tickerarray = tickers;
					}

					for (var i = 0; i < tickers.length; i++) {
						var method = tickers[i].getAttribute('mode');
						var tickeranim = dom.byClassFirst(tickers[i], 'ticker');
						switch(method) {
							case "vertical":
							ticker.vertical (tickers[i], tickeranim);
							break;

							case "horizontal":
							ticker.horizontal (tickers[i], tickeranim);
							break;

							case "alpha":
							ticker.alpha (tickers[i], tickeranim);
							break;
						}
					}
				}
			}, 400);
		//}
	},

	vertical : function (parentEl, node) {
		var top = node.style.top || '0px';
		var height = node.offsetHeight;
		var offset = parseInt(top.substring(0, top.length - 2)) - 2;
		if (offset <= -height) {
			offset = parentEl.offsetHeight;
		}
		node.style.top = offset + 'px';
	},

	horizontal : function (parentEl, node) {
		var top = node.style.left || '0px';
		var width = node.offsetWidth;
		var offset = parseInt(top.substring(0, top.length - 2)) + 2;
		if (offset >= width) {
			offset = -width;
		}
		node.style.left = offset + 'px';
	},

	alpha : function (parentEl, node) {
		var step = 0.05;
		var top = html.opacity.get (node);

		if (top <= 0)
			parentEl.setAttribute ('direction', "toogle");
  	if (top >= 1)
			parentEl.setAttribute ('direction', "");

		if (parentEl.getAttribute('direction') == "toogle") {
   		var offset = top - step * -1;
		} else {
      var offset = top - step;
		}
    html.opacity.set (node, offset);

	}
}

events.addHandler(document, 'ready', ticker.init);