$(function(){ $('.accordion h2').click(function() { $(this).next('.answer').slideToggle(200); $(this).toggleClass('close'); }); //Initialise the gallery carousel $('#carousel').jCarouselLite({ btnNext: ".carouselnext", btnPrev: ".carouselprev", visible: 4 }); //The following functions control the hero video on the Understanding DDoS page var $win = $(window), $video = $('.video'), $videoBackgroundImage = $video.css('background-image'), $videoCont = $('.video-container'), $videoWrap = $('.video-wrap'), $stopBtn = $('.stopbtn'), $controls = $('.controls'), $watchBtn = $('.watchbtn'); $watchBtn.click(function(){ autoPlayVideo(youtube_id_for_animation); //declared in what_is_ddos.html }); $stopBtn.click(function(){ stopVideo(); }); // Set the initial dimensions. setVideoWrapDims(); // Adjust dims on reize. TODO: debounce this. //$win.on('resize', setVideoWrapDims); function setVideoWrapDims(){ var dims = { 'width': $videoCont.width(), 'height': $videoCont.height() + 100, 'margin-left': '-' + ($videoCont.width() / 2) + 'px', 'margin-top': '-' + (($videoCont.height() + 100) / 2) + 'px' }; $videoWrap.css(dims); } function autoPlayVideo(vcode){ //Function to fade out the play button and title text then auto play the hero video $controls.fadeOut('fast'); $stopBtn.fadeIn('fast'); $videoWrap.html(''); $video.css('background-image','none').animate({height: '650px',}); setVideoWrapDims(); } function stopVideo(){ //Undo the autoPlayVideo function $stopBtn.fadeOut('fast'); $controls.fadeIn('slow'); $videoWrap.empty(); $video.css('background-image', $videoBackgroundImage).animate({height: '500px'}); } //The following functions control custom share text / urls for G+, Twitter, Facebook function getUrlParam(name){ var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href); if (results){ return results[1] || 0; } return false; } function getDateFromUrl(){ var day, month, year; var unixTime = getUrlParam('time') * 86400 * 1000; if (unixTime !== 0){ var date = new Date(unixTime); month = date.getUTCMonth() + 1; day = date.getUTCDate(); year = date.getUTCFullYear(); return month + "/" + day + "/" + year; } return false; } function getCurrentUrlForSharing(){ //Shorten it. Encode it. var longUrl = window.location.href; return encodeURIComponent(longUrl); } function buildShareText(){ var date = getDateFromUrl(); var baseMsg = "Digital Attack Map"; if (date){ return baseMsg + " - DDoS attacks on " + date; }else{ return baseMsg + " - DDoS attacks around the globe"; } } $('a.twitter').click(function(e){ e.preventDefault(); window.open('https://twitter.com/share?url='+ getCurrentUrlForSharing() + '&text=' + buildShareText() + '&', 'twitterwindow', 'height=450, width=550, top='+($(window).height()/2 - 225) +', left='+$(window).width()/2 +', toolbar=0, location=0, menubar=0, directories=0, scrollbars=0'); return false; }); $('a.facebook').click(function(e){ e.preventDefault(); var leftPosition, topPosition, width=400, height=300; leftPosition = (window.screen.width / 2) - ((width / 2) + 10); topPosition = (window.screen.height / 2) - ((height / 2) + 50); var windowFeatures = "status=no,height=" + height + ",width=" + width + ",resizable=yes,left=" + leftPosition + ",top=" + topPosition + ",screenX=" + leftPosition + ",screenY=" + topPosition + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no"; window.open('http://www.facebook.com/sharer.php?u=' + getCurrentUrlForSharing() + '&p[summary]=' + buildShareText(),'sharer', windowFeatures); return false; }); $('a.gplus').click(function(e){ e.preventDefault(); window.open('https://plus.google.com/share?url=' + getCurrentUrlForSharing(),'','menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600'); return false; }); });