// set config variables here var teasers = 4; var teaser_fade = 5000; var sponsor_fade = 4000; var sponsors = [ { 'image': 'http://www.rakmarathon.org/images/sponsor_logos/saqr_port.png', 'alt': '', 'link': 'http://www.saqrport.ae' }, { 'image': 'http://www.rakmarathon.org/images/sponsor_logos/rak_hospital.png', 'alt': '', 'link': 'http://www.rakhospital.com' }, { 'image': 'http://www.rakmarathon.org/images/sponsor_logos/alain.png', 'alt': '', 'link': 'http://agthia.com/Our-Brands/Al-Ain-Water' }, { 'image': 'http://www.rakmarathon.org/images/sponsor_logos/ups.png', 'alt': '', 'link': 'http://ups.com' }, { 'image': 'http://www.rakmarathon.org/images/sponsor_logos/hertz.png', 'alt': '', 'link': 'http://www.hertz.com' }, { 'image': 'http://www.rakmarathon.org/images/sponsor_logos/adsports.png', 'alt': '', 'link': 'http://www.adtv.ae' } ]; var countdown_ends = { 'year': 2018, 'month': 2, 'day': 9, 'hour': 7, 'minute': 0 }; var reg_countdown_ends = { 'year': 2017, 'month': 4, 'day': 1, 'hour': 0, 'minute': 01 }; // config ends here $(document).ready(function() { var mobile_set = false; $('#mobile-nav').click(function(e) { e.preventDefault(); var self = $(this); if(self.hasClass('open')) { self.removeClass('open'); $('#main-navigation').slideUp(); } else { self.addClass('open'); if(mobile_set == false) { $('#main-navigation > li > a').on('click', function(e) { e.preventDefault(); $(this).parent().children('ul').slideToggle(); }); } $('#main-navigation').slideDown(); } }); $('#social-toggle').click(function(e) { e.preventDefault(); var self = $(this); if(self.hasClass('open')) { self.removeClass('open').children('img').attr('src', 'http://www.rakmarathon.org/images/social-close-m.png'); $('#mobile-social').slideUp(); } else { self.addClass('open').children('img').attr('src', 'http://www.rakmarathon.org/images/social-open-m.png');; $('#mobile-social').slideDown(); var $target = $('html,body'); $target.animate({scrollTop: $target.height()}, 1000); } }); $('div.help-entry > a').click(function(e) { e.preventDefault(); $(this).parent().children('.help-box').slideToggle(); }); var teaser = 1; var sponsor = 0; var dateEnd = new Date(countdown_ends.year, countdown_ends.month - 1, countdown_ends.day, countdown_ends.hour, countdown_ends.minute, 0); var regDateEnd = new Date(reg_countdown_ends.year, reg_countdown_ends.month - 1, reg_countdown_ends.day, reg_countdown_ends.hour, reg_countdown_ends.minute, 0); var cd_display = 0; var cdr_display = 0; function calcTimer(reg) { var now = new Date(); if(!reg) reg = false; var w = 0; var d = 0; var h = 0; var m = 0; var s = 0; var endingDate = dateEnd; if(reg) endingDate = regDateEnd; if(now <= endingDate) { while(now.getTime() + (24*60*60*1000) < endingDate) { d++; now.setTime(now.getTime() + (24*60*60*1000)); } if(reg) { w = Math.floor(d / 7); d = d - (w * 7); } h = Math.floor((endingDate - now) / (60*60*1000)); now.setTime(now.getTime() + h * 60*60*1000); m = Math.floor((endingDate - now) / (60*1000)); now.setTime(now.getTime() + m * 60*1000); s = Math.floor((endingDate - now) / 1000); } var $cdn; if(reg) $cdn = $('#reg-countdown'); else $cdn = $('#countdown'); if(reg) $cdn.children('.weeks').text((w < 10 ? '0' : '') + w); $cdn.children('.days').text((d < 10 ? '0' : '') + d); $cdn.children('.hours').text((h < 10 ? '0' : '') + h); $cdn.children('.minutes').text((m < 10 ? '0' : '') + m); $cdn.children('.seconds').text((s < 10 ? '0' : '') + s); if(reg) { if(cdr_display == 0) $cdn.animate({'opacity': 1}); cdr_display = 1; } else { if(cd_display == 0) $cdn.animate({'opacity': 1}); cd_display = 1; } } window.setInterval(function() { calcTimer(); }, 1000); if($('#reg-countdown').length > 0) window.setInterval(function() { calcTimer(true); }, 1000); function changeSponsor() { //var rand = Math.floor(Math.random() * sponsors.length) + 1; //sponsor = rand - 1; sponsor = sponsor + 1; if(sponsor > sponsors.length - 1) sponsor = 0; $('#sponsors > a').fadeOut(750, function() { $(this).find('img').attr('src', sponsors[sponsor].image).attr('alt', sponsors[sponsor].alt); $(this).attr('href', sponsors[sponsor].link).fadeIn(750); }); window.setTimeout(function() { changeSponsor(); }, sponsor_fade); } function changeTeaser() { //var rand = Math.floor(Math.random() * teasers) + 1; //teaser = rand; teaser = teaser + 1; if(teaser > teasers) teaser = 1; var tmpimg = new Image; tmpimg.src = 'http://www.rakmarathon.org/images/headers/2017/teaser-' + teaser + '.jpg'; var img = $('').hide().css({ 'position': 'absolute', 'top': 0, 'left': 0, }).attr('src', tmpimg.src).appendTo('#frontpage-image'); img.fadeIn(1500, function() { $('#frontpage-image > img').attr('src', img.attr('src')); img.remove(); }); window.setTimeout(function() { changeTeaser(); }, teaser_fade); } window.setTimeout(function() { changeSponsor(); }, sponsor_fade); window.setTimeout(function() { changeTeaser(); }, teaser_fade); }); function getSplits(page_id) { if(page_id > 0) { $.get("http://www.rakmarathon.org/action/get_splits.php", { page_id:page_id }, function(data) { console.log('refresh'); $('#split-data').html(data); }); } }