var countdownTimer;
jQuery(window).load(function() {
if (countdownSetup.settings.active) {
//This adds some settings that aren't titan controlled, but seem to be in the old fls/DeepWidgets/js/countdown2.js file
countdownSetup.settings.alldayStart = 9;
countdownSetup.settings.keeupfor = 1;
countdownSetup.settings.allday_duration = 8;
countdownSetup.settings.timeout_speed = 6000;
jQuery.ajax({
url:getBaseUrl()+"/xmlCache/"+page_DB_OEM_ID+"/countdown.xml",
success: function(data) {
//var dataJson = data;
var dataXml = data;
var json = xml2json(data,'');
//if (dataJson.indexOf('getGoogleJsonData') > -1) {
// dataJson = dataJson.replace('getGoogleJsonData(', '');
// dataJson = dataJson.substr(0, (dataJson.length - 1));
// dataJson = dataJson.replace('/* callback */', '');
// dataJson = jQuery.trim(dataJson);
//}
if (typeof json != 'undefined') {
//countdownBuild(JSON.parse(dataJson));
countdownBuild(dataXml,JSON.parse(json));
}
if (jQuery("#countdown-details .countdown-event .sport-image").css('display') == 'none') {
jQuery("#countdown-details .countdown-event .text").width('98%');
}
else {
jQuery("#countdown-details .countdown-event").each(function() {
jQuery(this).find(".text").width(jQuery(this).width() - jQuery(this).find(".sport-image").outerWidth() - jQuery(this).find(".countdown-links").outerWidth() - 2);
});
}
}
});
}
});
jQuery(window).resize(function () {
if (jQuery("#countdown-details .countdown-event").length > 0) {
if (jQuery("#countdown-details .countdown-event .sport-image").css('display') == 'none') {
jQuery("#countdown-details .countdown-event .text").width('98%');
}
else {
jQuery("#countdown-details .countdown-event").each(function() {
jQuery(this).find(".text").width(jQuery(this).width() - jQuery(this).find(".sport-image").outerWidth() - jQuery(this).find(".countdown-links").outerWidth() - 2);
});
}
}
});
function countdownBuild(xmlData,dataJson) {
//dataJson is a JSON object with data from the countdown.json file.
//console.log(dataJson);
//xmlData is the XML feed that correlates to the json object. It contains tournament name.
//var xmlData = jQuery.parseXML(dataJson.rss.channel.xmlString);
jQuery('body').append('
Event Starts In...
');
jQuery("#countdown-table tr").append('').append(jQuery(this).clone()).html();
var linkHtml = jQuery(this).find('img').attr('alt');
linkHtml = linkHtml+jQuery(this).attr('title');
if (linkHtml) {
var linkType = re_action.exec(linkHtml.toUpperCase());
var linkHref = jQuery(this).attr('href');
if (!linkType == null || !linkType == '') {
var spriteClass = 'dwsprite-action_'+linkType+'_'+countdownSetup.settings.icon_style;
jQuery("#"+eventid+" .countdown-links").append('
');
//console.log(jQuery('
').append(jQuery(this).clone()).html());
//console.log(linkHtml.toUpperCase());
//console.log(linkType);
}
}
});
eventCount++;
});
if (countdownSetup.settings.to_prioritize != false) {
var eventArray = jQuery.makeArray(jQuery("#countdown-details .event-slider .countdown-event"));
var timeArray = jQuery.makeArray(jQuery("#countdown-time .time-slider .time-event"));
var primaryArray = new Array();
var secondaryArray = new Array();
var primaryTimeArray = new Array();
var secondaryTimeArray = new Array();
jQuery(eventArray).each(function() {
if (jQuery(this).attr('sport') == countdownSetup.settings.to_prioritize) {
primaryArray.push(this);
primaryTimeArray.push(timeArray[jQuery(this).index()]);
}
else {
secondaryArray.push(this);
secondaryTimeArray.push(timeArray[jQuery(this).index()]);
}
//console.log(this);
});
//console.log(primaryArray);
//console.log(secondaryArray);
jQuery("#countdown-details .event-slider").html(primaryArray);
jQuery("#countdown-details .event-slider").append(secondaryArray);
jQuery("#countdown-time .time-slider").html(primaryTimeArray);
jQuery("#countdown-time .time-slider").append(secondaryTimeArray);
}
dwtoggleStartsIn();
dwcountdownBind();
jQuery("#countdown-ad .close-large-ad").click(function() {
dwToggleLargeAd();
});
if (countdownSetup.settings.show_ad_on_hover) {
if (!countdownSetup.settings.link_small_ad) {
jQuery("#countdown-ad .small-ad").mouseenter(function() {
dwToggleLargeAd();
});
}
}
else {
if (!countdownSetup.settings.link_small_ad) {
jQuery("#countdown-ad .small-ad").click(function() {
dwToggleLargeAd();
});
}
}
jQuery("#countdown-details .event-slider .countdown-event .title").mouseenter(function() {
jQuery(this).find('a').css('color', '#'+countdownSetup.settings.data_text_color_hover);
}).mouseleave(function() {
jQuery(this).find('a').css('color', '#'+countdownSetup.settings.data_text_color);
});
dwcountdownStart();
if (countdownSetup.settings.startopen) {
dwHide();
}
else {
jQuery("#deepwidget-countdown-show").show();
}
}
function dwtoggleStartsIn() {
if (jQuery("#countdown-details .event-slider .countdown-event:eq(0)").hasClass('has-countdown')) {
jQuery("#countdown-logo .event-starts-in").show();
}
else {
jQuery("#countdown-logo .event-starts-in").hide();
}
}
function dwToggleLargeAd() {
if (jQuery("#countdown-ad .large-ad").css('opacity') == 1) {
jQuery("#countdown-ad .large-ad").animate({
bottom: 0,
opacity: 0
}, 250, function() {jQuery("#countdown-ad .large-ad").css('bottom', '-1000px');});
}
else {
jQuery("#countdown-ad .large-ad").css('bottom', '0px');
jQuery("#countdown-ad .large-ad").animate({
bottom: 37,
opacity: 1
}, 250);
if(countdownSetup.settings.track_image_url && countdownSetup.settings.track_large_ad_onload && !jQuery("#countdown-ad .large-ad").hasClass('tracked')) {
var trackingImage = new Image();
trackingImage.src = countdownSetup.settings.track_image_url;
jQuery("#countdown-ad .large-ad").addClass('tracked');
}
}
}
function dwHide() {
if (jQuery("#deepwidget-countdown").css('left') == '0px') {
if (jQuery("#countdown-ad .large-ad").css('opacity') == 1) {
jQuery("#countdown-ad .large-ad").animate({
bottom: 0,
opacity: 0
}, 250, function() {jQuery("#countdown-ad .large-ad").css('bottom', '-1000px');});
}
jQuery("#deepwidget-countdown").animate({
left: -jQuery(document).width()
}, 500, function() {jQuery("#deepwidget-countdown").css('left', '-10000px');});
jQuery("#deepwidget-countdown-show").show();
}
else {
jQuery("#deepwidget-countdown").css('left', -jQuery(document).width()+'px');
jQuery("#deepwidget-countdown").animate({
left: 0
}, 500, function() {jQuery("#deepwidget-countdown-show").hide();});
}
}
function dwcountdownBind() {
jQuery("#countdown-arrows .arrow.up").click(function() {
dwcountdownStop();
dwcountdownUp();
});
jQuery("#countdown-arrows .arrow.down").click(function() {
dwcountdownStop();
dwcountdownDown();
});
jQuery("#countdown-hide .hide-link").click(function() {dwHide();});
jQuery("#deepwidget-countdown-show").click(function() {dwHide();});
}
function dwcountdownUnbind() {
jQuery("#countdown-arrows .arrow").unbind('click');
jQuery("#countdown-hide .hide-link").unbind('click');
jQuery("#deepwidget-countdown-show").unbind('click');
}
function dwcountdownUp() {
if (jQuery("#countdown-details .event-container .countdown-event").length > 1) {
dwcountdownUnbind();
var tempEvent = jQuery("#countdown-details .event-container .countdown-event:last");
var tempTime = jQuery("#countdown-time .time-container .time-event:last");
jQuery(tempEvent).remove();
jQuery(tempTime).remove();
jQuery("#countdown-details .event-slider").prepend(tempEvent);
jQuery("#countdown-details .event-slider").css('top', '-35px');
jQuery("#countdown-time .time-slider").prepend(tempTime);
jQuery("#countdown-time .time-slider").css('top', '-35px');
jQuery("#countdown-details .event-slider").animate({
top: 0
}, 500, function() {
dwtoggleStartsIn();
dwcountdownBind();
});
jQuery("#countdown-time .time-slider").animate({
top: 0
}, 500);
}
}
function dwcountdownDown() {
if (jQuery("#countdown-details .event-container .countdown-event").length > 1) {
dwcountdownUnbind();
var tempEvent = jQuery("#countdown-details .event-container .countdown-event:first");
var tempTime = jQuery("#countdown-time .time-container .time-event:first");
var eventSliderTop = parseInt(jQuery("#countdown-details .event-slider").css('top').replace('px', ''), '10');
var timeSliderTop = parseInt(jQuery("#countdown-time .time-slider").css('top').replace('px', ''), '10');
jQuery("#countdown-details .event-slider").animate({
top: eventSliderTop-35
}, 500, function() {
jQuery(tempEvent).remove();
jQuery("#countdown-details .event-slider").css('top', '0px');
jQuery("#countdown-details .event-slider").append(tempEvent);
dwtoggleStartsIn();
dwcountdownBind();
});
jQuery("#countdown-time .time-slider").animate({
top: timeSliderTop-35
}, 500, function() {
jQuery(tempTime).remove();
jQuery("#countdown-time .time-slider").css('top', '0px');
jQuery("#countdown-time .time-slider").append(tempTime);
});
}
}
function dwcountdownStart() {
if (countdownSetup.settings.doesrotate)
countdownTimer = setInterval(function() {dwcountdownDown();}, countdownSetup.settings.timeout_speed);
setInterval(function() {dwCountdown();}, 1000);
}
function dwcountdownStop() {
clearInterval(countdownTimer);
}
Date.prototype.stdTimezoneOffset = function() {
var jan = new Date(this.getFullYear(), 0, 1);
var jul = new Date(this.getFullYear(), 6, 1);
return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
}
Date.prototype.dst = function() {
return this.getTimezoneOffset() < this.stdTimezoneOffset();
}
function dwCountdown() {
jQuery("#countdown-time .time-event.has-countdown .time-countdown").each(function() {
//if (!(countSeconds < 0 || countMinutes < 0 || countHours < 0)) {
days = jQuery.trim(jQuery(this).find('.days').html());
hours = jQuery.trim(jQuery(this).find('.hours').html());
minutes = jQuery.trim(jQuery(this).find('.minutes').html());
seconds = jQuery.trim(jQuery(this).find('.seconds').html());
if (!(seconds <= 0 && minutes <= 0 && hours <= 0 && days <= 0)) {
seconds--;
if (seconds < 0) {
minutes--;
seconds = 59;
}
if (minutes < 0) {
hours--;
minutes = 59;
}
if (hours < 0) {
days--;
hours = 23;
}
//leading 0s
if (hours.toString().length < 2)
hours = '0'+hours;
if (minutes.toString().length < 2)
minutes = '0'+minutes;
if (seconds.toString().length < 2)
seconds = '0'+seconds;
jQuery(this).find('.days').html(days);
jQuery(this).find('.hours').html(hours);
jQuery(this).find('.minutes').html(minutes);
jQuery(this).find('.seconds').html(seconds);
}
//}
});
}