/* ------------------------DEV ONLY----------------------------*/
function urlPar(var1){
var1 = var1.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+var1+"=([^]*)";
var regex = new RegExp( regexS );
var results = regex.exec (window.location.href);
if (results == null)
return "";
else
return results[1];
}
/* ------------------------------------------------------------*/
function tracker () {
$("#tmgTracker a").each(function(){
var curH = $(this).attr("href");
curH = curH+"?source=olympicnav";
$(this).attr("href",curH);
});
var dateArr = urlPar('dmDate').split(':');
var serverTime = new Date(dateArr[2],(dateArr[1]-1),dateArr[0]);
var defaultInterval = 120000;
var minInterval = 20000;
var int1, int2, int3, int4;
var dc1 = 0, dc2, dc3, dc4, postTime = 0;
var weekDays = ['SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY'];
var dayInt = (1000*3600*24);
var blogSet = false;
var _this=this;
var LAPath = "";
var postDataInt1 = {
sectionID: '2586',
elementGroupName: 'tr_stories_01',
publicationID: '34',
customFields: 'tagName',
begin: '2',
end: '11'
}
var postDataInt2 = {
liveEventID: $('#scribbleLiveEventID').val(),
source: 'webTracker',
maxPosts: '10',
since: ''
}
var postDataInt3 = {
sectionID: '2586',
elementGroupName: 'dontmissout_stories_01',
publicationID: '34',
customFields: ['description','eventStartTime','eventStartDate','eventUnitHeadline','paEventId'],
begin: '2',
end: '11'
}
var postDataInt4 = {};
function formatDateChars(t) {
return t<10 ? "0"+t : t;
}
tracker.prototype.headlinesRefresh=function() {
$("#trackerHeadlines li").fadeIn(500);
}
function slideIn(elements, y) {
var l = (elements.length - 1);
if (l >= 0) {
elements[l].css({
'margin-top' : '-' + y + 'px',
'opacity' : '0'
});
elements[l].show().animate({
'margin-top' : 0,
'opacity' : 1
}, 1000)
for ( var s = (l - 1); s >= 0; s--) {
elements[i].css({
'opacity' : '0'
});
elements[s].show().animate({
'opacity' : 1
}, 1000);
}
}
}
function getData (jsonAddress, postData, onReadyFunc){
postData.cache = Math.random(10000);
$.ajax({
url : jsonAddress,
data : postData,
type : 'GET',
traditional : true,
dataType : 'json',
async : true,
success : onReadyFunc
});
};
function setInt(path, postData, func, timer,stopInit) {
if(!stopInit) getData(path, postData, func);
return setInterval(function() {
getData(path, postData, func);
}, timer);
}
function runHeadlines(data) {
if(data.success){
//dc1=data.lastUpdated;
var id = "trackerHeadlines",
count = 0,
breakingNews = false,
newListItem;
$("#"+id+" li").stop().fadeOut(500, function() {
$(this).remove();
});
while(count < data.data.length){
var content="";
if(data.data[count].breakingNewsItem && count==0) breakingNews=true;
var cssClass = (breakingNews && count==0) ? "breaking" : "normal";
if(data.data[count].customFields[0]) content=""+data.data[count].customFields[0]+"";
if(data.data[count].url) {
content += ""+data.data[count].title+"";
} else {
content += ''+data.data[count].title+'';
}
newListItem = $('
', {
html: content,
className : cssClass
});
$("#"+id).append(newListItem.hide());
count++;
}
var cInt = setTimeout(function() {
_this.headlinesRefresh(breakingNews);
}, 500);
}
};
function runDontMiss(data) {
var id = "dontMiss";
if (data) {
var count = 0,
newListItem;
currTime = serverTime;
$("#"+id+" li").stop().fadeOut(500, function() {
$(this).remove();
});
while (count < data.data.length) {
var itemDateStr = data.data[count].customFields[2].substring(0, 10).split('-'),
itemDate = new Date(itemDateStr[0], (itemDateStr[1]-1), itemDateStr[2]),
dateCheck = itemDate - currTime,
itemDateTime = data.data[count].customFields[2].substring(0,10).replace(/-/g,':') +":"+ data.data[count].customFields[2].substring(11,16);
currTime=itemDate;
if (dateCheck!=0)
(currTime - serverTime == dayInt) ?
$("#" + id).append($('', {
html: "TOMORROW
"
}).hide().addClass('daySep')) :
$("#" + id).append($('', {
html: ""+weekDays[itemDate.getDay()]+"
"
}).hide().addClass('daySep'));
newListItem = $('', {
html : ""
+ data.data[count].customFields[1] + "
"
+ "
" + data.data[count].title.toUpperCase() +": "+data.data[count].customFields[0] +"
"
+ "
"+data.data[count].customFields[3]+""
});
$("#" + id).append(newListItem.hide());
count++;
}
var cInt = setTimeout(function() {
$("#"+id+" li").fadeIn(500);
}, 500);
}
};
function createBlogPost(data, targetId) {
var icons="";
var heading = "";
var newListItem = null;
if(data.icons) {
for(var i=0; i-1) imgName +='_g';
if(imgName=='GOLDMEDAL' && (data.type.indexOf("BOLDGOLD"))>-1) imgName +='_g';
}
icons+=""
}
}
var pathname = window.location.pathname;
var videoWidth = "180";
var videoHeight = "160";
if( (pathname.indexOf('trackerDesktop.jsp') != -1) ){
videoWidth = $(window).width() * 0.92;
videoHeight = videoWidth * (360/480);
}
data.content = data.content.replace('">','&width=' + videoWidth + 'px&height=' + videoHeight + 'px">');
if (data.heading) heading = ""+data.heading+"
";
var itemHtml = "" +
"
"+data.dateAndTime.substring(11,16)+"
" +
icons +
"
" +
"" +
heading +
data.content +
"
";
if(targetId) {
$(targetId).html(itemHtml);
} else {
newListItem = $('', {
"html" : itemHtml,
"class" : "BIGHEADER "+data.type,
"id" : "tpID"+data.postId
});
newListItem.find('.timeStamp').click( function(event) {
window.open(LAPath+'?LAPID=pID'+data.postId, tracker.prototype.target);
} );
newListItem.find('img').click( function(event) {
window.open(LAPath+'?LAPID=pID'+data.postId, tracker.prototype.target);
} );
}
return newListItem;
}
function runBlog(data) {
var topMargin = 0;
var id = "liveBlog";
var newItemArray = new Array();
for (var x in data.posts) {
var newListItem = createBlogPost(data.posts[x]);
if(!blogSet){
$("#" + id).append(newListItem);
} else {
$("#" + id).prepend(newListItem.hide())
topMargin += (newListItem.height());
newItemArray.push(newListItem);
}
}
if(data.posts.length < parseInt(postDataInt2.maxPosts,10) && !blogSet && parseInt(data.prevPageNum,10)>-1) {
postDataInt2.prevPageNum = data.prevPageNum;
getData("/livecontent/loadPosts.spring", postDataInt2, runBlog, true);
} else {
postDataInt2.since = data.since;
blogSet=true;
slideIn(newItemArray, topMargin);
}
if(data.edits)
for(var e in data.edits)
createBlogPost(data.edits[e], '#tpID'+data.edits[e].postId)
if(data.deletes)
for(var d in data.deletes)
$('#tpID'+data.deletes).remove();
$("#liveBlog .colRight a").each(function(){
var curH = $(this).attr("href");
curH = curH+"?source=olympicnav";
$(this).attr("href",curH);
});
}
var curBlock = "";
function runLatestResults(data) {
var id = "latestResults";
var newElementArr = new Array();
var topMargin = 0;
var fullList = "";
var newBlock = false;
if (data && (data.lastUpdated > dc1)) {
var count = 0,
newListItem;
if(curBlock != ""){
if(curBlock != data.data[count].time){
newBlock = true;
curBlock = data.data[count].time;
}else{
newBlock = false;
}
}else{
curBlock = data.data[count].time;
}
while (count < data.data.length) {
var timeStamp = new Date(data.data[count].time),
htmlContent = "";
if (true) {
htmlContent = ""+formatDateChars(timeStamp.getHours()) +":"+formatDateChars(timeStamp.getMinutes())+"
";
for(var i = 0; i"+data.data[count].sportInfo[i].sport+"";
if(data.data[count].sportInfo[i].medalEvent) htmlContent+="";
htmlContent += ""+ data.data[count].sportInfo[i].title +"
";
htmlContent += '';
for(var ii = 0; ii" +
""+ data.data[count].sportInfo[i].eventInfo[ii].position +" | " +
""+
""+data.data[count].sportInfo[i].eventInfo[ii].name +""+
""+ data.data[count].sportInfo[i].eventInfo[ii].countryCode +"" +
" | "+
"";
if(data.data[count].sportInfo[i].eventInfo[ii].record != null && data.data[count].sportInfo[i].eventInfo[ii].record == 'WR')
htmlContent +="";
if(data.data[count].sportInfo[i].eventInfo[ii].qualification != null)
htmlContent +="";
htmlContent += " | "+ resultStr +" | " +
"";
}
htmlContent += "
";
}
}
newListItem = $('', {
html : htmlContent
});
fullList = ""+fullList+newListItem.html();
if(dc1>0) { //if its the second + run
$("#" + id).prepend(newListItem.hide());
topMargin+=newListItem.height();
newElementArr.push(newListItem);
} else {
$("#" + id).append(newListItem);
}
count++;
}
if(fullList != ""||fullList != null){
if(newBlock == true){
$("#" + id).fadeOut("fast");
$("#" + id).html(fullList);
$("#" + id).fadeIn("fast");
}else{
$("#" + id).html(fullList);
}
}
}
}
return {
init:function(i1,i2,i3,i4,sTime,LAlnk) {
var dateArr = sTime.split('-');
LAPath = LAlnk
if(typeof(i1)!='number' || i1', {
html : "_",
className : "cursor"
});
function toggle() {
cursorItem.css('visibility', visible);
(visible=='visible') ? visible='hidden' : visible='visible';
}
return {
flash:function(target){
clearInterval(cursorInt);
target.append(cursorItem);
cursorInt=setInterval(toggle,500);
},
stop:function() {
clearInterval(cursorInt);
cursorItem.remove();
}
};
})();
function runTicker() {
tData[eIndex][0].append(tData[eIndex][1].charAt(sIndex));
sIndex++;
if(sIndex>tData[eIndex][1].length) {
eIndex++;
sIndex=0;
if(eIndex>=tData.length) {
stopTicker();
restartInt=setTimeout(function() {
tickerElement.fadeOut(1000, function() {
if(!trackerOpen) restartTicker();
});
},5000);
}
}
}
function stopTicker() {
clearInterval(startInt);
clearInterval(tickerInt);
clearInterval(flashInt);
clearInterval(restartInt);
for(var i=0; i