|
| 1 | +var animatingScroll = false; |
| 2 | + |
| 3 | +$(document).ready( function() { |
| 4 | + |
| 5 | + $('.setup.switch .wifi').click(function(){ |
| 6 | + $(this).parent().children().removeClass('active'); |
| 7 | + $(this).addClass('active'); |
| 8 | + $('.setup .switchpanel').removeClass('active'); |
| 9 | + $('.setup .switchpanel.wifi').addClass('active'); |
| 10 | + }); |
| 11 | + $('.setup.switch .wired').click(function(){ |
| 12 | + $(this).parent().children().removeClass('active'); |
| 13 | + $(this).addClass('active'); |
| 14 | + $('.setup .switchpanel').removeClass('active'); |
| 15 | + $('.setup .switchpanel.wired').addClass('active'); |
| 16 | + }); |
| 17 | + |
| 18 | + |
| 19 | + //wifi by default |
| 20 | + $('.setup.switch .wired').click(); |
| 21 | + |
| 22 | + |
| 23 | + $(window).scroll( function() { |
| 24 | + update_nav_pos(); |
| 25 | + updateNav(); |
| 26 | + }); |
| 27 | + update_nav_pos(); |
| 28 | + |
| 29 | + buildAnimation(); |
| 30 | + updateLines(); |
| 31 | + $(window).on('resize', function() { |
| 32 | + setTimeout( buildAnimation, 1 ); |
| 33 | + //size is no longer window width dependant |
| 34 | + //updateVideoSize(); |
| 35 | + }); |
| 36 | + |
| 37 | + |
| 38 | + //smooth scroll anchors |
| 39 | + $('a.animate').click(function(ev){ |
| 40 | + ev.preventDefault(); |
| 41 | + animatingScroll = true; |
| 42 | + $('a').removeClass('active'); |
| 43 | + $(this).addClass('active'); |
| 44 | + if ( $(this).attr('data-navtarget') != null ) { |
| 45 | + $("#nav_" + $(this).attr('data-navtarget')).addClass('active'); |
| 46 | + } |
| 47 | + $('html,body').animate({ |
| 48 | + scrollTop: $('[name="' + $.attr(this, 'href').substr(1) + '"]').offset().top |
| 49 | + }, 400, function() { |
| 50 | + animatingScroll = false; |
| 51 | + updateNav(); |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + |
| 56 | + //open faqs on click |
| 57 | + var faqdown = function() { |
| 58 | + $(this).parent().find('p').slideDown(); |
| 59 | + $(this).unbind('click', faqdown).bind('click', faqup); |
| 60 | + }; |
| 61 | + var faqup = function() { |
| 62 | + $(this).parent().find('p').slideUp(); |
| 63 | + $(this).unbind('click', faqup).bind('click', faqdown); |
| 64 | + }; |
| 65 | + $('.faq.rollup h3').bind('click', faqdown); |
| 66 | + |
| 67 | + |
| 68 | + //video replace on image click |
| 69 | + $('#introvideo').bind( 'click', addVideo ); |
| 70 | + |
| 71 | + |
| 72 | + buildTour(); |
| 73 | + |
| 74 | +}); |
| 75 | + |
| 76 | + |
| 77 | +var buildTour = function() { |
| 78 | + var $tourslides = $('.tour .slide'); |
| 79 | + $tourslides.css('visibility','visible').hide(); |
| 80 | + for ( var x=0; x< $tourslides.length; x++ ) { |
| 81 | + var $navitem = $('<div class="item" data-slide="slide_' + x + '">'); |
| 82 | + $('.tournav').append( $navitem ); |
| 83 | + $($tourslides.get(x)).attr('data-slide', 'slide_' + x); |
| 84 | + if ( x+1 >= $tourslides.length ) { |
| 85 | + $($tourslides.get(x)).attr('data-next', 'slide_0'); |
| 86 | + } else { |
| 87 | + $($tourslides.get(x)).attr('data-next', 'slide_' + (x+1)); |
| 88 | + } |
| 89 | + $navitem.bind('click', function() { |
| 90 | + activateSlide(this); |
| 91 | + }); |
| 92 | + $($tourslides.get(x)).find('img').bind('click', function() { |
| 93 | + activateSlide( $('.tour .slide[data-slide="' + $(this).parent().attr('data-next') + '"]' ) ); |
| 94 | + }); |
| 95 | + } |
| 96 | + activateSlide( $tourslides.get(0) ); |
| 97 | +}; |
| 98 | +var activateSlide = function( item ) { |
| 99 | + $item = $(item); |
| 100 | + $slide = $('.tour .slide[data-slide="' + $item.attr('data-slide') + '"]'); |
| 101 | + $nav = $('.tournav .item[data-slide="' + $item.attr('data-slide') + '"]'); |
| 102 | + |
| 103 | + $('.tour .slide').hide(); |
| 104 | + $slide.show(); |
| 105 | + $('.tournav .item').removeClass('active'); |
| 106 | + $nav.addClass('active'); |
| 107 | +}; |
| 108 | + |
| 109 | +var vidratio = 1024/576; |
| 110 | +var addVideo = function() { |
| 111 | + var w = $('.videoframe').width(); |
| 112 | + var h = $('.videoframe').height(); |
| 113 | + vidratio = w/h; |
| 114 | + $('#introvideo').html('<iframe src="http://www.youtube.com/embed/wH24YwdayFg?rel=0&autoplay=1&autohide=1&showinfo=0&iv_load_policy=3" width="' + w + '" height="' + h + '" frameborder="0" id="videoframe"></iframe>'); |
| 115 | + //$('#introvideo').html('<iframe src="http://www.youtube.com/embed/Jl3-lzlzOJI?autoplay=1" width="' + w + '" height="' + h + '" frameborder="0" id="videoframe"></iframe>'); |
| 116 | + $('#introvideo').unbind('click', addVideo); |
| 117 | +} |
| 118 | +var updateVideoSize = function() { |
| 119 | + $vid = $('#videoframe'); |
| 120 | + if ( !$vid.get(0) ) { |
| 121 | + return; |
| 122 | + } |
| 123 | + var w = $(window).width(); |
| 124 | + var h = w / vidratio; |
| 125 | + $vid.attr('width', Math.floor(w) ); |
| 126 | + $vid.attr('height', Math.floor(h) - 1 ); |
| 127 | +} |
| 128 | + |
| 129 | +var updateNav = function() { |
| 130 | + if ( animatingScroll ) { |
| 131 | + return; |
| 132 | + } |
| 133 | + //hilight current anchor when you scroll to it |
| 134 | + var anchors = []; |
| 135 | + $('a').each(function(){ |
| 136 | + if ( this.name != null && this.name != "" ) { |
| 137 | + //console.log( "#nav_" + this.name ); |
| 138 | + if ( $("#nav_" + this.name).get(0) != null ) { |
| 139 | + anchors[anchors.length] = { name:this.name, top: $(this).offset().top}; |
| 140 | + //console.log('anchor ' + this.name + ' ' + $(this).offset().top ); |
| 141 | + } |
| 142 | + } |
| 143 | + }); |
| 144 | + |
| 145 | + var $this = $(this); |
| 146 | + var y = $this.scrollTop(); |
| 147 | + var fudge = 400; |
| 148 | + |
| 149 | + var active = -1; |
| 150 | + for ( var x=0; x<anchors.length; x++ ){ |
| 151 | + if(anchors[x]['top'] < y + fudge){ |
| 152 | + active = x; |
| 153 | + //console.log( 'y: ' + y + ' anchor: ' + anchors[x].name + " " + anchors[x].top ); |
| 154 | + } |
| 155 | + } |
| 156 | + $('a').removeClass('active'); |
| 157 | + if ( active >= 0 ) { |
| 158 | + $('#nav_' + anchors[active]['name']).addClass('active'); |
| 159 | + } |
| 160 | +}; |
| 161 | + |
| 162 | + |
| 163 | +var update_nav_pos = function() { |
| 164 | + var revealloc = $('.masthead').outerHeight(); |
| 165 | + var fixedheight = $('.fixedbar').outerHeight(); |
| 166 | + var scrollY = $(window).scrollTop(); |
| 167 | + var fadestart = 40; |
| 168 | + var navadjust = 36; |
| 169 | + |
| 170 | + var top = (revealloc - navadjust) - fixedheight - scrollY; |
| 171 | + if ( top < 0 ) { |
| 172 | + top = 0; |
| 173 | + } |
| 174 | + $('.fixedbar').css( { |
| 175 | + 'top': top + 'px' |
| 176 | + }); |
| 177 | + |
| 178 | + var revealmin = revealloc - fixedheight - fadestart; |
| 179 | + var revealmax = revealloc - fixedheight; |
| 180 | + |
| 181 | + var pos = scrollY; |
| 182 | + if ( pos < revealmin ) { |
| 183 | + pos = revealmin; |
| 184 | + } else if ( pos > revealmax ) { |
| 185 | + pos = revealmax; |
| 186 | + } |
| 187 | + |
| 188 | + |
| 189 | + |
| 190 | + revealedfraction = ((pos-revealmin) / (revealmax-revealmin)); |
| 191 | + $('.fixedbar .logo').css( { |
| 192 | + 'opacity': revealedfraction, |
| 193 | + }); |
| 194 | + |
| 195 | +}; |
| 196 | + |
| 197 | +var lines = []; |
| 198 | +var $canvas; |
| 199 | +var ctx; |
| 200 | +var buildAnimation = function() { |
| 201 | + lines = []; |
| 202 | + $canvas = $("#animation"); |
| 203 | + ctx = $canvas.get(0).getContext("2d"); |
| 204 | + var w = $canvas.parent().width(); |
| 205 | + var h = $canvas.parent().height(); |
| 206 | + $canvas.attr('width', w); |
| 207 | + $canvas.attr('height', h); |
| 208 | + //$canvas.width( w ); |
| 209 | + //$canvas.height( h ); |
| 210 | + |
| 211 | + for ( var x=0; x<50; x++ ) { |
| 212 | + |
| 213 | + var tx = (Math.random() * (w+100)) - 50; |
| 214 | + var bx = tx + (Math.random() * 500) - 250; |
| 215 | + var line = { |
| 216 | + tx: tx, |
| 217 | + bx: bx, |
| 218 | + ty: -20, |
| 219 | + by: h - 200 + (Math.random() * 200), |
| 220 | + opacity: .2, |
| 221 | + direction: Math.random() > .5? 1:-1 |
| 222 | + }; |
| 223 | + lines.push( line ); |
| 224 | + } |
| 225 | + |
| 226 | +}; |
| 227 | +var updateLines = function() { |
| 228 | + ctx.clearRect(0, 0, $canvas.width(), $canvas.height()); |
| 229 | + for ( var x=0; x<lines.length; x++ ) { |
| 230 | + line = lines[x]; |
| 231 | + |
| 232 | + ctx.beginPath(); |
| 233 | + ctx.lineWidth = .8; |
| 234 | + ctx.strokeStyle = "rgba(255,255,255," + line.opacity + ")"; |
| 235 | + ctx.moveTo( line.tx, line.ty ); |
| 236 | + ctx.lineTo( line.bx, line.by ); |
| 237 | + ctx.stroke(); |
| 238 | + ctx.closePath(); |
| 239 | + |
| 240 | + line.opacity += (Math.random() * .1) - .05; |
| 241 | + if ( line.opacity < 0 ) { |
| 242 | + line.opacity = 0; |
| 243 | + } else if ( line.opacity > 1 ) { |
| 244 | + line.opacity = 1; |
| 245 | + } |
| 246 | + |
| 247 | + line.bx += (Math.random() * .2) * line.direction; |
| 248 | + if ( line.bx < line.tx - 250 ) { |
| 249 | + line.bx = line.tx - 250; |
| 250 | + line.direction=1; |
| 251 | + } else if ( line.bx > line.tx + 250 ) { |
| 252 | + line.bx = line.tx + 250; |
| 253 | + line.direction = -1; |
| 254 | + } |
| 255 | + |
| 256 | + |
| 257 | + } |
| 258 | + requestAnimationFrame( updateLines ); |
| 259 | +}; |
| 260 | + |
| 261 | +//requestAnimationFrame polyfill |
| 262 | +//http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/ |
| 263 | +(function() { |
| 264 | + var lastTime = 0; |
| 265 | + var vendors = ['webkit', 'moz']; |
| 266 | + for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { |
| 267 | + window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; |
| 268 | + window.cancelAnimationFrame = |
| 269 | + window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame']; |
| 270 | + } |
| 271 | + |
| 272 | + if (!window.requestAnimationFrame) |
| 273 | + window.requestAnimationFrame = function(callback, element) { |
| 274 | + var currTime = new Date().getTime(); |
| 275 | + var timeToCall = Math.max(0, 16 - (currTime - lastTime)); |
| 276 | + var id = window.setTimeout(function() { callback(currTime + timeToCall); }, |
| 277 | + timeToCall); |
| 278 | + lastTime = currTime + timeToCall; |
| 279 | + return id; |
| 280 | + }; |
| 281 | + |
| 282 | + if (!window.cancelAnimationFrame) |
| 283 | + window.cancelAnimationFrame = function(id) { |
| 284 | + clearTimeout(id); |
| 285 | + }; |
| 286 | +}()); |
| 287 | + |
0 commit comments