'use strict';

// DEV TIME CODE
if (FAKE_SERVER) {
    require('fake');
}
// DEV TIME CODE

require('./index.scss');

var $ = require('$jquery');
var util = require('lib/util');
var state = require('./state');
var repository = require('./repository');
var sections = require('./sections/section');

//var details = args.newData.hud;
var setup = state.current();

// only load things when we have the data ready to go
repository.getData(function(details) { 
	// generate the html needed for the sections
	var html = sections.render(details, setup);
	html = '<div class="glimpse"><div class="glimpse-icon"></div><div class="glimpse-hud">' + html + '</div></div>';
	
	// insert the html into the dom
	var holder = $(html).appendTo('body')
	
	// force the correct state from previous load
	state.setup(holder);
	
	// setup events that we need to listen to
	sections.postRender(holder);
	
	// TODO: need to find a better place for this
	$('.glimpse-icon').click(function() {
		window.open(util.resolveClientUrl(util.currentRequestId(), true), 'GlimpseClient');
	});
});
@@ -450,16 +450,58 @@
 ils) %7B %0A
+%09$(function() %7B setTimeout(function() %7B %0A%09
 %09// gene
@@ -538,16 +538,17 @@
 ections%0A
+%09
 %09var htm
@@ -584,16 +584,17 @@
 setup);%0A
+%09
 %09html = 
@@ -700,17 +700,19 @@
 div%3E';%0A%09
-%0A
+%09%0A%09
 %09// inse
@@ -736,16 +736,17 @@
 the dom%0A
+%09
 %09var hol
@@ -777,17 +777,19 @@
 body')%0A%09
-%0A
+%09%0A%09
 %09// forc
@@ -827,16 +827,17 @@
 us load%0A
+%09
 %09state.s
@@ -847,25 +847,27 @@
 p(holder);%0A%09
-%0A
+%09%0A%09
 %09// setup ev
@@ -897,16 +897,17 @@
 sten to%0A
+%09
 %09section
@@ -929,17 +929,19 @@
 lder);%0A%09
-%0A
+%09%0A%09
 %09// TODO
@@ -979,16 +979,17 @@
 or this%0A
+%09
 %09$('.gli
@@ -1021,16 +1021,17 @@
 n() %7B%0A%09%09
+%09
 window.o
@@ -1107,15 +1107,28 @@
 ent');%0A%09
+%09%7D);%0A%09%7D, 0); 
 %7D);%0A%7D);

Fix bug where Navigation Timing info could be accessed to quickly and hence produce weird values