
/*

*/

OTS.newsTicker = {};

OTS.newsTicker.nId = null;
OTS.newsTicker.intS = 5000;
OTS.newsTicker.intP = 0;
OTS.newsTicker.intT = 17;
OTS.newsTicker.intC = 0;
OTS.newsTicker.intI;
OTS.newsTicker.autoTimerID = 0;
OTS.newsTicker.currTxt = '';
OTS.newsTicker.currLnk = '';
OTS.newsTicker.strTxt = '';
OTS.newsTicker.active = false;

OTS.newsTicker.init = function(id) {
	OTS.newsTicker.nId = id;
	OTS.newsTicker.build();
	OTS.newsTicker.playFirst();
}
OTS.newsTicker.build = function() {
	var o = OTS.$(OTS.newsTicker.nId);
	if (!o) return;
	var os = OTS.getHTML(o);
	var s = '';
	if (OTS.newsTickerTxtObj.length > 1) {
		s += '<a href="#" onclick="OTS.newsTicker.prev(); return false;"><img src="http://images.onthesnow.com/ots/images/icon_arrow_rt.gif" alt="" border="0" align="absmiddle" /></a>';
		s += '<a href="#" onclick="OTS.newsTicker.next(); return false;"><img src="http://images.onthesnow.com/ots/images/icon_arrow_lt.gif" alt="" border="0" align="absmiddle" /></a>';
	}
	s += '<span style="text-transform:uppercase; margin:0 4px 0 4px;">' + os + '</span>';
	s += '<span id="' + OTS.newsTicker.nId + '_tick"><a href="#"></a></span>';
	s += '<span id="' + OTS.newsTicker.nId + '_cursor" style="position:relative; top:1px;"><img src="http://images.onthesnow.com/ots/images/icon_ticker_cursor.gif" alt="" border="0" align="absmiddle" /></span>';
	OTS.setHTML(o, s);
}
OTS.newsTicker.prev = function() {
	OTS.newsTicker.delay();
	if (OTS.newsTicker.active == true) return;
	if (OTS.newsTicker.intP == 0) {
		OTS.newsTicker.intP = OTS.newsTickerTxtObj.length - 1;
	} else {
		OTS.newsTicker.intP--;
	}
	OTS.newsTicker.setHD(OTS.newsTicker.intP);
}
OTS.newsTicker.next = function() {
	OTS.newsTicker.delay();
	if (OTS.newsTicker.active == true) return;
	if (OTS.newsTicker.intP == OTS.newsTickerTxtObj.length - 1) {
		OTS.newsTicker.intP = 0;
	} else {
		OTS.newsTicker.intP++;
	}
	OTS.newsTicker.setHD(OTS.newsTicker.intP);
}
OTS.newsTicker.typeText = function() {
	if (OTS.newsTicker.intC > OTS.newsTicker.currTxt.length){
		clearInterval(OTS.newsTicker.intI);
		OTS.newsTicker.setSpan(OTS.newsTicker.strTxt, OTS.newsTicker.currLnk);
		OTS.setStyle(OTS.$(OTS.newsTicker.nId + '_cursor'), 'display', 'none');
	} else {
		OTS.newsTicker.strTxt += OTS.newsTicker.currTxt.charAt(OTS.newsTicker.intC);
		OTS.newsTicker.setSpan(OTS.newsTicker.strTxt, OTS.newsTicker.currLnk);
		OTS.newsTicker.intC++;
	}
}
OTS.newsTicker.setSpan = function(t, u) {
	var o = OTS.$(OTS.newsTicker.nId + '_tick');
	if (!o) return;
	var s = '<a href="' + u + '" onclick="OTS.newsTicker.delay(); OTS.newsTicker.trk(\'' + OTS.newsTickerTxtObj[OTS.newsTicker.intP][0] + '\');" onmouseover="OTS.newsTicker.stop();" onmouseout="OTS.newsTicker.resume();">' + t + '</a>';
	OTS.setHTML(o, s);
}
OTS.newsTicker.setHD = function(n) {
	if (!OTS.newsTickerTxtObj[n]) return;
	OTS.newsTicker.active = true;
	OTS.newsTicker.intC = 0;
	OTS.newsTicker.strTxt = '';
	OTS.newsTicker.setSpan('', '#');
	OTS.setStyle(OTS.$(OTS.newsTicker.nId + '_cursor'), 'display', 'inline');
	OTS.newsTicker.currTxt = OTS.newsTickerTxtObj[n][0];
	OTS.newsTicker.currLnk = OTS.newsTickerTxtObj[n][1];
	OTS.newsTicker.intI = setInterval('OTS.newsTicker.typeText()', OTS.newsTicker.intT);
	OTS.newsTicker.active = false;
}
OTS.newsTicker.playFirst = function() {
	clearTimeout(OTS.newsTicker.autoTimerID);
	OTS.newsTicker.setHD(OTS.newsTicker.intP);
	OTS.newsTicker.play();
}
OTS.newsTicker.play = function() {
	if (OTS.newsTicker.autoTimerID != 0) {
		clearInterval(OTS.newsTicker.intI);
		OTS.newsTicker.next();
	}
	clearTimeout(OTS.newsTicker.autoTimerID);
	if (OTS.newsTickerTxtObj.length <= 1) return;
	OTS.newsTicker.autoTimerID = setTimeout('OTS.newsTicker.play()', OTS.newsTicker.intS);
}
OTS.newsTicker.stop = function() {
	clearTimeout(OTS.newsTicker.autoTimerID);
}
OTS.newsTicker.resume = function() {
	clearTimeout(OTS.newsTicker.autoTimerID);
	if (OTS.newsTickerTxtObj.length <= 1) return;
	OTS.newsTicker.autoTimerID = setTimeout('OTS.newsTicker.play()', OTS.newsTicker.intS);
}
OTS.newsTicker.delay = function() {
	clearInterval(OTS.newsTicker.intI);
	clearTimeout(OTS.newsTicker.autoTimerID);
	if (OTS.newsTickerTxtObj.length <= 1) return;
	OTS.newsTicker.autoTimerID = setTimeout('OTS.newsTicker.play()', OTS.newsTicker.intS * 2);
}
OTS.newsTicker.trk = function(label) {
	//if (!pageTracker) return;
	//alert(label);
	//pageTracker._trackEvent('News', 'Breaking', label);
}

