<commit_before>function Camera(canvas) {
  this.far = 500.0;
  this.position = [0.0, 100.0];
  this.projectedCoords = [[0, 0, 0, 0], [0, 0, 0, 0]];
  this.viewportHalfWidth = canvas.width / 2;
  this.viewportHeight = canvas.height;
}

Camera.prototype.projectShape = function(shape) {
  this.projectedCoords[0][0] = this.projectedCoords[0][1] = shape.dimension[0][0] - this.position[0];
  this.projectedCoords[0][2] = this.projectedCoords[0][3] = shape.dimension[0][1] - this.position[0];

  this.projectedCoords[1][0] = this.projectedCoords[1][1] = -this.position[1];
  this.projectedCoords[1][2] = this.projectedCoords[1][3] = shape.height - this.position[1];

  var scalar = this.far / shape.dimension[1][0];

  this.projectedCoords[0][0] *=  scalar;
  this.projectedCoords[0][2] *=  scalar;
  this.projectedCoords[1][0] *= -scalar;
  this.projectedCoords[1][2] *= -scalar;

  scalar = this.far / shape.dimension[1][1];

  this.projectedCoords[0][1] *=  scalar;
  this.projectedCoords[0][3] *=  scalar;
  this.projectedCoords[1][1] *= -scalar;
  this.projectedCoords[1][3] *= -scalar;
}

Camera.prototype.setDim = function(width, height) {
  this.viewportHalfWidth = width / 2;
  this.viewportHeight = height;
}

Camera.prototype.setPosition = function(x, y) {
  this.position[0] = x - this.viewportHalfWidth;
  this.position[1] = this.viewportHeight - y;

  if      ( this.position[0] < -this.viewportHalfWidth ) this.position[0] = -this.viewportHalfWidth;
  else if ( this.position[0] >  this.viewportHalfWidth ) this.position[0] =  this.viewportHalfWidth;

  if      ( this.position[1] < 0 )                   this.position[1] = 0;
  else if ( this.position[1] > this.viewportHeight ) this.position[1] = this.viewportHeight;
}

function Drawer(context, camera) {
  this.backgroundColor = "#000";
  this.camera = camera;
  this.context = context;
  this.offsetX = context.canvas.width  / 2.0;
  this.offsetY = context.canvas.height / 2.0;
  this.ingameMessage = "";
  this.ingameMessageTime = 0;
}

Drawer.prototype.clearScreen = function() {
  this.context.fillStyle = this.backgroundColor;
  this.context.globalAlpha = 1.0;
  this.context.fillRect(0, 0, canvas.width, canvas.height);
}

Drawer.prototype.drawShape = function(shape) {
  this.camera.projectShape(shape);

  var alpha = (3000 - shape.dimension[1][0]) / 3000;
  if ( shape.dimension[1][0] > 3000.0 ) alpha = 0.0;

  this.context.strokeStyle = shape.color;
  this.context.globalAlpha = alpha;

  this.drawLine(0, 2, 1, 3);
  this.drawLine(0, 2, 0, 0);
  this.drawLine(0, 2, 2, 2);

  this.drawLine(2, 0, 3, 1);
  this.drawLine(2, 0, 0, 0);
  this.drawLine(2, 0, 2, 2);

  this.drawLine(3, 3, 1, 3);
  this.drawLine(3, 3, 3, 1);
  this.drawLine(3, 3, 2, 2);

  this.drawLine(1, 1, 1, 3);
  this.drawLine(1, 1, 3, 1);
  this.drawLine(1, 1, 0, 0);
}

Drawer.prototype.drawLine = function(x1, y1, x2, y2) {
  this.context.beginPath();
  this.context.moveTo(this.camera.projectedCoords[0][x1] + this.offsetX, this.camera.projectedCoords[1][y1] + this.offsetY);
  this.context.lineTo(this.camera.projectedCoords[0][x2] + this.offsetX, this.camera.projectedCoords[1][y2] + this.offsetY);
  this.context.stroke();
}

Drawer.prototype.setIngameMessage = function(message) {
  this.ingameMessage = message;
  this.ingameMessageTime = 1500.0;
}

Drawer.prototype.drawIngameMessage = function(time) {
  if ( this.ingameMessageTime <= 0 ) return;
  this.context.globalAlpha = this.ingameMessageTime / 1500.0;
  this.context.fillStyle = "yellow";
  this.context.textAlign = 'center';
  this.context.font = '40px monospace';
  this.context.fillText(this.ingameMessage, 400, 250);
  this.ingameMessageTime -= time;
}

Drawer.prototype.drawTitleInfo = function(distance) {
  this.context.globalAlpha = 1.0;
  this.context.fillStyle = "yellow";
  this.context.textAlign = 'center';
  this.context.font = '15px monospace';
  this.context.fillText(words[0], 400, 25);
  this.context.font = '25px monospace';
  this.context.fillText(this.replaceText1(words[1], distance / 30 >> 0), 400, 50);

  this.context.font = '60px monospace';
  this.context.fillText(words[2], 400, 200);
  this.context.font = '20px monospace';
  this.context.fillText(words[3], 400, 230);
  this.context.font = '25px monospace';
  this.context.fillText(words[4], 400, 350);
}

Drawer.prototype.drawGameOverMessage = function(distance, time) {
  this.context.textAlign = 'center';
  this.context.font = '40px monospace';
  this.context.fillText(words[5], 400, 250);
  this.context.font = '25px monospace';
  this.context.fillText(words[6], 400, 280);
  this.context.fillText(words[7], 400, 350);
  this.context.font = '15px monospace';
  this.context.fillText(this.replaceText2(words[8], distance / 30 >> 0, time / 100 >> 0), 400, 300);
}

Drawer.prototype.drawInfo = function(distance, time, speed) {
  this.context.globalAlpha = 1.0;
  this.context.fillStyle = "yellow";
  this.context.font = '15px monospace';
  this.context.textAlign = 'left';
  this.context.fillText(this.replaceText1(words[9], speed), 25, 520);
  this.context.fillText(this.replaceText1(words[10], time / 100 >> 0), 25, 540);

  this.context.textAlign = 'center';
  this.context.fillText(words[11], 400, 25);
  this.context.font = '25px monospace';
  this.context.fillText(this.replaceText1(words[1], distance / 30 >> 0), 400, 50);
}

Drawer.prototype.replaceText1 = function(text, var1) {
  return text.replace("$1", var1);
}

Drawer.prototype.replaceText2 = function(text, var1, var2) {
  return text.replace("$1", var1).replace("$2", var2);
}

function Shape() {
  this.color = "green";
  this.dimension = [[0.0, 0.0], [0.0, 0.0]];
}

Shape.prototype.advance = function(distance) {
  this.dimension[1][0] -= distance * 0.3;
  this.dimension[1][1] -= distance * 0.3;
}

Shape.prototype.isBehindCamera = function() {
  return this.dimension[1][0] < 0.0;
}

Shape.prototype.collideWithPoint = function(x) {
  if ( x < this.dimension[0][0] ) return false;
  if ( x > this.dimension[0][1] ) return false;
  return true;
}

Shape.prototype.init = function(posZ, color) {
  var posX = Math.floor((Math.random() * 1000) - 500);
  var width = Math.floor((Math.random() * 20.0) + 50.0);
  this.dimension[0][0] = posX - width;
  this.dimension[0][1] = posX + width;
  this.dimension[1][0] = posZ;
  this.dimension[1][1] = posZ + width * 2.0;
  this.color = color;
}

Shape.prototype.height = 600.0;

Shape.prototype.reset = function(color) {
  this.init(3000.0 + this.dimension[1][0], color);
}

function Timer(interval) {
  this.now = Date.now();
  this.then = this.now;
  this.delta = 0;
  this.interval = interval;
}

Timer.prototype.advance = function() {
  this.now = Date.now();
  this.delta = this.now - this.then;
  if ( this.delta > this.interval ) {
    this.then = this.now;
    return true;
  }
  return false;
}

function Game(canvasId) {
  this.currentDistance = 0;
  this.currentTime = 0;
  this.currentSpeed = 10.0;
  this.gameState = 0; //0: TITLE, 1:GAME, 2:GAMEOVER
  this.shapes = [];

  this.bestDistance = window.localStorage.getItem("bestScore") || 0;
  this.bestDistanceBeated = false;

  this.canvas = document.getElementById(canvasId);
  this.canvas.width = 800;
  this.canvas.height = 600;

  this.context = this.canvas.getContext("2d");

  this.camera = new Camera(this.canvas);
  this.drawer = new Drawer(this.context, this.camera);
  this.tutorialCounter = 0;

  this.actTimer = new Timer(0);
  this.drawTimer = new Timer(15);

  this.init();
}

Game.prototype.accel = function() {
  this.currentSpeed += 10.0;
  this.drawer.setIngameMessage(words[12]);
}

Game.prototype.advance = function() {
  this.actTimer.advance();
  var timeRatio = (this.actTimer.delta / 10.0);
  var currentSpeed = this.currentSpeed * timeRatio;
  var shape;
  for ( var i = 0 ; i < this.shapes.length ; i++ ) {
    shape = this.shapes[i];
    shape.advance(currentSpeed);
    if ( shape.isBehindCamera() ) {
      if ( this.gameState == 1 && shape.collideWithPoint(this.camera.position[0]) )
        this.setGameOver();
      shape.reset(this.getShapeColor());
    }
  }

  if ( this.gameState == 1 ) {
    if ( this.currentSpeed <= 10.0 ) {
		if ( this.tutorialCounter == 2 && this.currentTime > 700.0 ) {
		  this.drawer.setIngameMessage(words[13]);
		  this.tutorialCounter++;
		} else if ( this.tutorialCounter == 1 && this.currentTime > 400.0 ) {
		  this.drawer.setIngameMessage(words[14]);
		  this.tutorialCounter++;
		} else if ( this.tutorialCounter == 0 && this.currentTime > 100.0 ) {
		  this.drawer.setIngameMessage(words[15]);
		  this.tutorialCounter++;
		}
	}
    if ( this.currentSpeed < 70.0 && this.currentTime / 1000.0 > this.currentSpeed ) this.accel();
    if ( !this.bestDistanceBeated && this.currentDistance > this.bestDistance) {
      this.drawer.setIngameMessage(words[16]);
      this.bestDistanceBeated = true;
    }
    this.currentDistance += currentSpeed;
    this.currentTime += timeRatio;
  }
}

Game.prototype.draw = function() {
  if ( this.drawTimer.advance() ) {
    this.drawer.clearScreen();
    for ( var i = 0 ; i < this.shapes.length ; i++ )
      this.drawer.drawShape(this.shapes[i]);

    if ( this.gameState == 1 ) {
      this.drawer.drawInfo(this.currentDistance, this.currentTime, this.currentSpeed);
      this.drawer.drawIngameMessage(this.drawTimer.delta);
    } else if ( this.gameState == 2 ) {
      this.drawer.drawInfo(this.currentDistance, this.currentTime, this.currentSpeed);
      this.drawer.drawGameOverMessage(this.currentDistance, this.currentTime, this.currentSpeed);
    } else {
      this.drawer.drawTitleInfo(this.bestDistance);
    }
  }
}

Game.prototype.init = function() {
  this.initShapes();

  var camera = this.camera;
  var game = this;

  this.canvas.addEventListener("mousemove", function(event) {
    camera.setPosition(event.pageX - canvas.offsetLeft,
                       event.pageY - canvas.offsetTop);
  }, false);

  this.canvas.addEventListener("mousedown", function(event) { game.pressButton(); }, false);

  setInterval( function() { game.advance(); }, 10);

  function draw() {
    requestAnimationFrame(draw);
    game.draw();
  }

  requestAnimationFrame(draw);
}

Game.prototype.initShapes = function() {
  var step = 3000.0 / 20;
  var shape;
  for ( var i = 0 ; i < 20 ; i++ ) {
    shape = new Shape();
    shape.init(Math.floor(3000.0 - (step * i)), this.getShapeColor());
    this.shapes[i] = shape;
  }
}

Game.prototype.getShapeColor = function() {
  var color;
  if ( this.gameState == 1 ) color = (this.currentDistance / 1000) % 360;
  else color =  Math.floor((Math.random() * 360));
  return "hsl("+ color +", 100%, 50%)";
}

Game.prototype.pressButton = function() {
  if      ( this.gameState == 1 ) this.accel();
  else if ( this.gameState == 2 ) this.setGameTitle();
  else                            this.setGameStart();
}

Game.prototype.setGameOver = function() {
  this.gameState = 2;
  this.drawer.backgroundColor = "#700";
  this.drawer.ingameMessageTime = 0;
  this.bestDistanceBeated = false;

  if ( this.currentDistance > this.bestDistance ) {
    this.bestDistance = this.currentDistance;
    window.localStorage.setItem("bestScore", this.bestDistance);
  }
}

Game.prototype.setGameTitle = function() {
  this.drawer.backgroundColor = "#000";
  this.gameState = 0;
  this.currentSpeed = 10.0;
}

Game.prototype.setGameStart = function() {
  this.gameState = 1;
  this.currentDistance = 0;
  this.currentTime = 0;
  this.currentSpeed = 10.0;
}<commit_msg>Canvas scaling<commit_after>function Camera(canvas) {
  this.far = 500.0;
  this.position = [0.0, 100.0];
  this.projectedCoords = [[0, 0, 0, 0], [0, 0, 0, 0]];
  this.viewportHalfWidth = 400.0;
  this.viewportHeight = 600.0;
  this.ratio;
  this.setRatio(canvas.width)
}

Camera.prototype.setRatio = function(width) {
  this.ratio = width / 800.0;
  this.far = 500.0 * this.ratio;
}

Camera.prototype.projectShape = function(shape) {
  this.projectedCoords[0][0] = this.projectedCoords[0][1] = shape.dimension[0][0] - this.position[0];
  this.projectedCoords[0][2] = this.projectedCoords[0][3] = shape.dimension[0][1] - this.position[0];

  this.projectedCoords[1][0] = this.projectedCoords[1][1] = -this.position[1];
  this.projectedCoords[1][2] = this.projectedCoords[1][3] = shape.height - this.position[1];

  var scalar = this.far / shape.dimension[1][0];

  this.projectedCoords[0][0] *=  scalar;
  this.projectedCoords[0][2] *=  scalar;
  this.projectedCoords[1][0] *= -scalar;
  this.projectedCoords[1][2] *= -scalar;

  scalar = this.far / shape.dimension[1][1];

  this.projectedCoords[0][1] *=  scalar;
  this.projectedCoords[0][3] *=  scalar;
  this.projectedCoords[1][1] *= -scalar;
  this.projectedCoords[1][3] *= -scalar;
}

Camera.prototype.setPosition = function(x, y) {
  this.position[0] = x / this.ratio - this.viewportHalfWidth;
  this.position[1] = this.viewportHeight - y / this.ratio;

  if      ( this.position[0] < -this.viewportHalfWidth ) this.position[0] = -this.viewportHalfWidth;
  else if ( this.position[0] >  this.viewportHalfWidth ) this.position[0] =  this.viewportHalfWidth;

  if      ( this.position[1] < 0 )                   this.position[1] = 0;
  else if ( this.position[1] > this.viewportHeight ) this.position[1] = this.viewportHeight;
}

function Drawer(context, camera) {
  this.backgroundColor = "#000";
  this.camera = camera;
  this.context = context;
  this.offsetX = context.canvas.width  / 2.0;
  this.offsetY = context.canvas.height / 2.0;
  this.ingameMessage = "";
  this.ingameMessageTime = 0;
}

Drawer.prototype.clearScreen = function() {
  this.context.fillStyle = this.backgroundColor;
  this.context.globalAlpha = 1.0;
  this.context.fillRect(0, 0, canvas.width, canvas.height);
}

Drawer.prototype.transform = function(coord) {
  return this.camera.ratio * coord;
}

Drawer.prototype.drawShape = function(shape) {
  this.camera.projectShape(shape);

  var alpha = (3000 - shape.dimension[1][0]) / 3000;
  if ( shape.dimension[1][0] > 3000.0 ) alpha = 0.0;

  this.context.strokeStyle = shape.color;
  this.context.globalAlpha = alpha;

  this.drawLine(0, 2, 1, 3);
  this.drawLine(0, 2, 0, 0);
  this.drawLine(0, 2, 2, 2);

  this.drawLine(2, 0, 3, 1);
  this.drawLine(2, 0, 0, 0);
  this.drawLine(2, 0, 2, 2);

  this.drawLine(3, 3, 1, 3);
  this.drawLine(3, 3, 3, 1);
  this.drawLine(3, 3, 2, 2);

  this.drawLine(1, 1, 1, 3);
  this.drawLine(1, 1, 3, 1);
  this.drawLine(1, 1, 0, 0);
}

Drawer.prototype.drawLine = function(x1, y1, x2, y2) {
  this.context.beginPath();
  this.context.moveTo(this.camera.projectedCoords[0][x1] + this.offsetX, this.camera.projectedCoords[1][y1] + this.offsetY);
  this.context.lineTo(this.camera.projectedCoords[0][x2] + this.offsetX, this.camera.projectedCoords[1][y2] + this.offsetY);
  this.context.stroke();
}

Drawer.prototype.setContextFont = function(size) {
  this.context.font = this.transform(size) + 'px monospace';
}

Drawer.prototype.drawText = function(text, posX, posY) {
  this.context.fillText(text, this.transform(posX), this.transform(posY));
}

Drawer.prototype.setIngameMessage = function(message) {
  this.ingameMessage = message;
  this.ingameMessageTime = 1500.0;
}

Drawer.prototype.drawIngameMessage = function(time) {
  if ( this.ingameMessageTime <= 0 ) return;
  this.context.globalAlpha = this.ingameMessageTime / 1500.0;
  this.context.fillStyle = "yellow";
  this.context.textAlign = 'center';
  this.setContextFont(40);
  this.drawText(this.ingameMessage, 400, 250);
  this.ingameMessageTime -= time;
}

Drawer.prototype.drawTitleInfo = function(distance) {
  this.context.globalAlpha = 1.0;
  this.context.fillStyle = "yellow";
  this.context.textAlign = 'center';
  this.setContextFont(15);
  this.drawText(words[0], 400, 25);
  this.setContextFont(25);
  this.drawText(this.replaceText1(words[1], distance / 30 >> 0), 400 , 50);

  this.setContextFont(60);
  this.drawText(words[2], 400, 200);
  this.setContextFont(20);
  this.drawText(words[3], 400, 230);
  this.setContextFont(25);
  this.drawText(words[4], 400, 350);
}

Drawer.prototype.drawGameOverMessage = function(distance, time) {
  this.context.textAlign = 'center';
  this.setContextFont(40);
  this.drawText(words[5], 400, 250);
  this.setContextFont(25);
  this.drawText(words[6], 400, 280);
  this.drawText(words[7], 400, 350);
  this.setContextFont(15);
  this.drawText(this.replaceText2(words[8], distance / 30 >> 0, time / 100 >> 0), 400, 300);
}

Drawer.prototype.drawInfo = function(distance, time, speed) {
  this.context.globalAlpha = 1.0;
  this.context.fillStyle = "yellow";
  this.setContextFont(15);
  this.context.textAlign = 'left';
  this.drawText(this.replaceText1(words[9], speed), 25, 520);
  this.drawText(this.replaceText1(words[10], time / 100 >> 0), 25, 540);

  this.context.textAlign = 'center';
  this.drawText(words[11], 400, 25);
  this.setContextFont(25);
  this.drawText(this.replaceText1(words[1], distance / 30 >> 0), 400, 50);
}

Drawer.prototype.replaceText1 = function(text, var1) {
  return text.replace("$1", var1);
}

Drawer.prototype.replaceText2 = function(text, var1, var2) {
  return text.replace("$1", var1).replace("$2", var2);
}

function Shape() {
  this.color = "green";
  this.dimension = [[0.0, 0.0], [0.0, 0.0]];
}

Shape.prototype.advance = function(distance) {
  this.dimension[1][0] -= distance * 0.3;
  this.dimension[1][1] -= distance * 0.3;
}

Shape.prototype.isBehindCamera = function() {
  return this.dimension[1][0] < 0.0;
}

Shape.prototype.collideWithPoint = function(x) {
  if ( x < this.dimension[0][0] ) return false;
  if ( x > this.dimension[0][1] ) return false;
  return true;
}

Shape.prototype.init = function(posZ, color) {
  var posX = Math.floor((Math.random() * 1000) - 500);
  var width = Math.floor((Math.random() * 20.0) + 50.0);
  this.dimension[0][0] = posX - width;
  this.dimension[0][1] = posX + width;
  this.dimension[1][0] = posZ;
  this.dimension[1][1] = posZ + width * 2.0;
  this.color = color;
}

Shape.prototype.height = 600.0;

Shape.prototype.reset = function(color) {
  this.init(3000.0 + this.dimension[1][0], color);
}

function Timer(interval) {
  this.now = Date.now();
  this.then = this.now;
  this.delta = 0;
  this.interval = interval;
}

Timer.prototype.advance = function() {
  this.now = Date.now();
  this.delta = this.now - this.then;
  if ( this.delta > this.interval ) {
    this.then = this.now;
    return true;
  }
  return false;
}

function Game(canvasId) {
  this.currentDistance = 0;
  this.currentTime = 0;
  this.currentSpeed = 10.0;
  this.gameState = 0; //0: TITLE, 1:GAME, 2:GAMEOVER
  this.shapes = [];

  this.bestDistance = window.localStorage.getItem("bestScore") || 0;
  this.bestDistanceBeated = false;

  this.canvas = document.getElementById(canvasId);
  this.canvas.width = 320;//800;
  this.canvas.height = 240;//600;

  this.context = this.canvas.getContext("2d");

  this.camera = new Camera(this.canvas);
  this.drawer = new Drawer(this.context, this.camera);
  this.tutorialCounter = 0;

  this.actTimer = new Timer(0);
  this.drawTimer = new Timer(15);

  this.init();
}

Game.prototype.accel = function() {
  this.currentSpeed += 10.0;
  this.drawer.setIngameMessage(words[12]);
}

Game.prototype.advance = function() {
  this.actTimer.advance();
  var timeRatio = (this.actTimer.delta / 10.0);
  var currentSpeed = this.currentSpeed * timeRatio;
  var shape;
  for ( var i = 0 ; i < this.shapes.length ; i++ ) {
    shape = this.shapes[i];
    shape.advance(currentSpeed);
    if ( shape.isBehindCamera() ) {
      if ( this.gameState == 1 && shape.collideWithPoint(this.camera.position[0]) )
        this.setGameOver();
      shape.reset(this.getShapeColor());
    }
  }

  if ( this.gameState == 1 ) {
    if ( this.currentSpeed <= 10.0 ) {
		if ( this.tutorialCounter == 2 && this.currentTime > 700.0 ) {
		  this.drawer.setIngameMessage(words[13]);
		  this.tutorialCounter++;
		} else if ( this.tutorialCounter == 1 && this.currentTime > 400.0 ) {
		  this.drawer.setIngameMessage(words[14]);
		  this.tutorialCounter++;
		} else if ( this.tutorialCounter == 0 && this.currentTime > 100.0 ) {
		  this.drawer.setIngameMessage(words[15]);
		  this.tutorialCounter++;
		}
	}
    if ( this.currentSpeed < 70.0 && this.currentTime / 1000.0 > this.currentSpeed ) this.accel();
    if ( !this.bestDistanceBeated && this.currentDistance > this.bestDistance) {
      this.drawer.setIngameMessage(words[16]);
      this.bestDistanceBeated = true;
    }
    this.currentDistance += currentSpeed;
    this.currentTime += timeRatio;
  }
}

Game.prototype.draw = function() {
  if ( this.drawTimer.advance() ) {
    this.drawer.clearScreen();
    for ( var i = 0 ; i < this.shapes.length ; i++ )
      this.drawer.drawShape(this.shapes[i]);

    if ( this.gameState == 1 ) {
      this.drawer.drawInfo(this.currentDistance, this.currentTime, this.currentSpeed);
      this.drawer.drawIngameMessage(this.drawTimer.delta);
    } else if ( this.gameState == 2 ) {
      this.drawer.drawInfo(this.currentDistance, this.currentTime, this.currentSpeed);
      this.drawer.drawGameOverMessage(this.currentDistance, this.currentTime, this.currentSpeed);
    } else {
      this.drawer.drawTitleInfo(this.bestDistance);
    }
  }
}

Game.prototype.init = function() {
  this.initShapes();

  var camera = this.camera;
  var game = this;

  this.canvas.addEventListener("mousemove", function(event) {
    camera.setPosition(event.pageX - canvas.offsetLeft,
                       event.pageY - canvas.offsetTop);
  }, false);

  this.canvas.addEventListener("mousedown", function(event) { game.pressButton(); }, false);

  setInterval( function() { game.advance(); }, 10);

  function draw() {
    requestAnimationFrame(draw);
    game.draw();
  }

  requestAnimationFrame(draw);
}

Game.prototype.initShapes = function() {
  var step = 3000.0 / 20;
  var shape;
  for ( var i = 0 ; i < 20 ; i++ ) {
    shape = new Shape();
    shape.init(Math.floor(3000.0 - (step * i)), this.getShapeColor());
    this.shapes[i] = shape;
  }
}

Game.prototype.getShapeColor = function() {
  var color;
  if ( this.gameState == 1 ) color = (this.currentDistance / 1000) % 360;
  else color =  Math.floor((Math.random() * 360));
  return "hsl("+ color +", 100%, 50%)";
}

Game.prototype.pressButton = function() {
  if      ( this.gameState == 1 ) this.accel();
  else if ( this.gameState == 2 ) this.setGameTitle();
  else                            this.setGameStart();
}

Game.prototype.setGameOver = function() {
  this.gameState = 2;
  this.drawer.backgroundColor = "#700";
  this.drawer.ingameMessageTime = 0;
  this.bestDistanceBeated = false;

  if ( this.currentDistance > this.bestDistance ) {
    this.bestDistance = this.currentDistance;
    window.localStorage.setItem("bestScore", this.bestDistance);
  }
}

Game.prototype.setGameTitle = function() {
  this.drawer.backgroundColor = "#000";
  this.gameState = 0;
  this.currentSpeed = 10.0;
}

Game.prototype.setGameStart = function() {
  this.gameState = 1;
  this.currentDistance = 0;
  this.currentTime = 0;
  this.currentSpeed = 10.0;
}<|endoftext|>


<commit_before>CLASS({
  package: 'foam.ui',

  name: 'Window',

  exports: [
    '$$',
    '$',
    'addStyle',
    'animate',
    'cancelAnimationFrame',
    'clearInterval',
    'clearTimeout',
    'console',
    'document',
    'dynamic',
    'error',
    'info',
    'log',
    'memento',
    'registerModel_',
    'requestAnimationFrame',
    'setInterval',
    'setTimeout',
    'warn',
    'window'
  ],

  properties: [
    {
      model_: 'StringProperty',
      name: 'name',
      defaultValue: 'window'
    },
    {
      name: 'window',
      postSet: function(_, w) {
        // TODO: This would be better if ChromeApp.js added this behaviour
        // in a SubModel of Window, ie. ChromeAppWindow
        if ( this.X.subDocument ) this.X.subDocument(w.document);

        return w.document;
      }
    },
    {
      name: 'document'
    },
    {
      name: 'installedModels',
      lazyFactory: function() {
        return this.document.installedModels || ( this.document.installedModels = {} );
      }
    },
    {
      model_: 'BooleanProperty',
      name: 'isBackground',
      defaultValue: false
    },
    {
      name: 'console',
      lazyFactory: function() { return this.window.console; }
    },
    {
      name: 'memento',
      lazyFactory: function() { this.window.WindowHashValue.create({window: this.window}); }
    }
  ],

  methods: {
    registerModel_: function(model) {
      var X        = this.X;
      var document = this.document;

      // TODO(kgr): If Traits have CSS then it will get installed more than once.
      // TODO(kgr): Add package support.
      for ( var m = model ; m && m.getPrototype ; m = m.extendsModel && this[m.extendsModel] ) {
        if ( this.installedModels[m.id] ) return;
        this.installedModels[m.id] = true;
        arequireModel(m)(function(m) {
          m.getPrototype().installInDocument(X, document);
        });
      }
    },
    addStyle: function(css) {
      var s = this.document.createElement('style');
      s.innerHTML = css;
      this.document.head.appendChild(s);
    },
    log:   function() { this.console.log.apply(this.console, arguments); },
    warn:  function() { this.console.warn.apply(this.console, arguments); },
    info:  function() { this.console.info.apply(this.console, arguments); },
    error: function() { this.console.error.apply(this.console, arguments); },
    $: function(id) {
      return ( this.document.FOAM_OBJECTS && this.document.FOAM_OBJECTS[id] ) ?
        this.document.FOAM_OBJECTS[id] :
        this.document.getElementById(id);
    },
    $$: function(cls) {
      return this.document.getElementsByClassName(cls);
    },
    dynamic: function(fn, opt_fn) {
      Events.dynamic(fn, opt_fn, this.X);
    },
    animate: function(duration, fn, opt_interp, opt_onEnd) {
      return Movement.animate(duration, fn, opt_interp, opt_onEnd, this.X);
    },
    setTimeout: function(f, t) {
      return this.window.setTimeout.apply(this.window, arguments);
    },
    clearTimeout: function(id) { this.window.clearTimeout(id); },
    setInterval: function(f, t) {
      return this.window.setInterval.apply(this.window, arguments);
    },
    clearInterval: function(id) { this.window.clearInterval(id); },
    requestAnimationFrame: function(f) {
      console.assert(
        this.window.requestAnimationFrame,
        'requestAnimationFrame not defined');
      return this.window.requestAnimationFrame(f);
    },
    cancelAnimationFrame: function(id) {
      this.window.cancelAnimationFrame && this.window.cancelAnimationFrame(id);
    }
  }
});

// Using the existence of 'process' to determine that we're running in Node.
X = this.subWindow(
  window,
  'DEFAULT WINDOW',
  typeof process === 'object').sub({IN_WINDOW: false}, 'TOP-X');
<commit_msg>Window fixes.<commit_after>CLASS({
  package: 'foam.ui',

  name: 'Window',

  exports: [
    '$$',
    '$',
    'addStyle',
    'animate',
    'cancelAnimationFrame',
    'clearInterval',
    'clearTimeout',
    'console',
    'document',
    'dynamic',
    'error',
    'info',
    'log',
    'memento',
    'registerModel_',
    'requestAnimationFrame',
    'setInterval',
    'setTimeout',
    'warn',
    'window'
  ],

  properties: [
    {
      model_: 'StringProperty',
      name: 'name',
      defaultValue: 'window'
    },
    {
      name: 'window',
      postSet: function(_, w) {
        // TODO: This would be better if ChromeApp.js added this behaviour
        // in a SubModel of Window, ie. ChromeAppWindow
        if ( this.X.subDocument ) this.X.subDocument(w.document);

        this.document = w.document;
      }
    },
    {
      name: 'document'
    },
    {
      name: 'installedModels',
      lazyFactory: function() {
        return this.document.installedModels || ( this.document.installedModels = {} );
      }
    },
    {
      model_: 'BooleanProperty',
      name: 'isBackground',
      defaultValue: false
    },
    {
      name: 'console',
      lazyFactory: function() { return this.window.console; }
    },
    {
      name: 'memento',
      lazyFactory: function() { this.window.WindowHashValue.create({window: this.window}); }
    }
  ],

  methods: {
    registerModel_: function(model) {
      var X        = this.X;
      var document = this.document;

      // TODO(kgr): If Traits have CSS then it will get installed more than once.
      // TODO(kgr): Add package support.
      for ( var m = model ; m && m.getPrototype ; m = m.extendsModel && this[m.extendsModel] ) {
        if ( this.installedModels[m.id] ) return;
        this.installedModels[m.id] = true;
        arequireModel(m)(function(m) {
          m.getPrototype().installInDocument(X, document);
        });
      }
    },
    addStyle: function(css) {
      var s = this.document.createElement('style');
      s.innerHTML = css;
      this.document.head.appendChild(s);
    },
    log:   function() { this.console.log.apply(this.console, arguments); },
    warn:  function() { this.console.warn.apply(this.console, arguments); },
    info:  function() { this.console.info.apply(this.console, arguments); },
    error: function() { this.console.error.apply(this.console, arguments); },
    $: function(id) {
      return ( this.document.FOAM_OBJECTS && this.document.FOAM_OBJECTS[id] ) ?
        this.document.FOAM_OBJECTS[id] :
        this.document.getElementById(id);
    },
    $$: function(cls) {
      return this.document.getElementsByClassName(cls);
    },
    dynamic: function(fn, opt_fn) {
      Events.dynamic(fn, opt_fn, this.X);
    },
    animate: function(duration, fn, opt_interp, opt_onEnd) {
      return Movement.animate(duration, fn, opt_interp, opt_onEnd, this.X);
    },
    setTimeout: function(f, t) {
      return this.window.setTimeout.apply(this.window, arguments);
    },
    clearTimeout: function(id) { this.window.clearTimeout(id); },
    setInterval: function(f, t) {
      return this.window.setInterval.apply(this.window, arguments);
    },
    clearInterval: function(id) { this.window.clearInterval(id); },
    requestAnimationFrame: function(f) {
      console.assert(
        this.window.requestAnimationFrame,
        'requestAnimationFrame not defined');
      return this.window.requestAnimationFrame(f);
    },
    cancelAnimationFrame: function(id) {
      this.window.cancelAnimationFrame && this.window.cancelAnimationFrame(id);
    }
  }
});

// Using the existence of 'process' to determine that we're running in Node.
foam.ui.Window.create(
  {
    window: window,
    name: 'DEFAULT WINDOW',
    isBackground: typeof process === 'object'
  },
  { __proto__: X, sub: function() { return X; } }
);<|endoftext|>


<commit_before>;(function($){
    var numbers = [5, 3, 2, 1, 1];
    $.decompose = function(n){
        var result = numbers.reduce(function(result, element){
            if (element <= n){
                n -= element;
                result.push(element);
                return result;
            }
            return result;
        }, []);
        return {
            result: result,
            rest: n
        }
    }

    $.frequency = function(){
        return Array.prototype.slice.call(arguments).reduce(function(frequencies, elements){
            elements.forEach(function(element){
                if (!frequencies[element]) {
                    frequencies[element] = 0;
                }
                frequencies[element] += 1;
            });
            return frequencies;
        }, {});
    }
})(window.fibonacci = window.fionacci || {});
<commit_msg>Create a Clock model<commit_after>;(function($){
    var numbers = [5, 3, 2, 1, 1];
    $.decompose = function(n){
        var result = numbers.reduce(function(result, element){
            if (element <= n){
                n -= element;
                result.push(element);
                return result;
            }
            return result;
        }, []);
        return {
            result: result,
            rest: n
        }
    }

    $.frequency = function(){
        return Array.prototype.slice.call(arguments).reduce(function(frequencies, elements){
            elements.forEach(function(element){
                if (!frequencies[element]) {
                    frequencies[element] = 0;
                }
                frequencies[element] += 1;
            });
            return frequencies;
        }, {});
    }

    var Clock = $.Clock = function(){
        this.update();
    };
    Clock.prototype.update = function(){
        var date = new Date();
        this.hour = date.getHours() % 24;
        this.minutes = Math.floor(date.getMinutes() / 10);
    }
})(window.fibonacci = window.fionacci || {});
<|endoftext|>


<commit_before><commit_msg>Change defauld basemap and modify UI map layer info<commit_after><|endoftext|>


<commit_before>
	var display ;
	var currentChord=[];
	var pianoKeyboard ;
	var synthe ;
	var midiInput ;

	const PIANOKEY_2_NOTE = {
		"0":"c",
		"1":"c#",
		"2":"d",
		"3":"d#",
		"4":"e",
		"5":"f",
		"6":"f#",
		"7":"g",
		"8":"g#",
		"9":"a",
		"10":"a#",
		"11":"b",
	};

	function init()
	{
		display = new score.Display($("#score")[0]) ;
		display.init();

		pianoKeyboard = new ui.PianoKeyboard($("#keyboard")[0]) ;
		pianoKeyboard.draw() ;

		synthe = new sound.Synthe() ;

		pianoKeyboard.keyPressed(function(event){
			var note = event.note ;
			if(pianoKeyboard.isLightened(event.note+"/"+event.octave))
			{
				pianoKeyboard.turnOff(event.note+"/"+event.octave) ;
				synthe.noteOff(note,event.octave) ;
			}
			else
			{
				pianoKeyboard.lightUp(event.note+"/"+event.octave) ;
				synthe.noteOn(note,event.octave) ;
				check() ;
			}
		});

		midiInput = new MidiInput(function(press, pianoKey){

			console.log("pianoKey="+pianoKey);
			var octave = Math.floor(pianoKey/12) ;
			var key = pianoKey-(octave*12) ;
			var note = PIANOKEY_2_NOTE[key] ;

			console.log("octave="+octave);
			console.log("note="+note);

			if(press)
			{
				pianoKeyboard.lightUp(note+"/"+octave) ;
				synthe.noteOn(note,octave) ;
				check() ;
			}
			else
			{
				pianoKeyboard.turnOff(note+"/"+octave) ;
				synthe.noteOff(note,octave) ;
			}

		}) ;

		addChord() ;
	}

	function random (low, high) {
	    return parseInt(Math.random() * (high - low) + low);
	}

	function addChord()
	{
		display.clean();

		for (var idx = 0; idx < currentChord.length; idx++)
		{
			var note = currentChord[idx] ;
			var key =  note ;
			var octave = 4 ;
			var slashIdx = note.indexOf("/") ;

			if(slashIdx>-1)
			{
				key = note.substring(0,slashIdx) ;
				var octChar= note.substring(slashIdx+1,slashIdx+2) ;
				octave = parseInt(octChar) ;
			}

			synthe.noteOff(key,octave) ;
		}
		currentChord=[] ;
		pianoKeyboard.turnAllOff() ;

		for (var idx = 0; idx < 3; idx++) {
			var noteIdx = random(0,ui.NOTES_CHAR.length) ;
			var noteChr = ui.NOTES_CHAR[noteIdx]+ "/4" ;

			while(currentChord.includes(noteChr))
			{
				noteIdx = random(0,ui.NOTES_CHAR.length) ;
				noteChr = ui.NOTES_CHAR[noteIdx]+ "/4"  ;
			}

			currentChord.push(noteChr) ;
			currentChord.sort() ;

		}

		var vexNote = new VF.StaveNote({
            clef: "treble",
            keys: currentChord,
            duration: "4",
          });
		display.addNote(vexNote);

	};

	function check()
	{
		if(pianoKeyboard.lightenedNotes().length==currentChord.length)
		{
			if(JSON.stringify(pianoKeyboard.lightenedNotes())==JSON.stringify(currentChord))
			{
				$("#result")[0].innerHTML="Bien joué" ;
				addChord() ;
			}
			else
			{
				$("#result")[0].innerHTML="Essai encore" ;
			}
		}
	}
<commit_msg>fix octave difference between vexflow and midi keyboard<commit_after>
	var display ;
	var currentChord=[];
	var pianoKeyboard ;
	var synthe ;
	var midiInput ;

	const PIANOKEY_2_NOTE = {
		"0":"c",
		"1":"c#",
		"2":"d",
		"3":"d#",
		"4":"e",
		"5":"f",
		"6":"f#",
		"7":"g",
		"8":"g#",
		"9":"a",
		"10":"a#",
		"11":"b",
	};

	function init()
	{
		display = new score.Display($("#score")[0]) ;
		display.init();

		pianoKeyboard = new ui.PianoKeyboard($("#keyboard")[0]) ;
		pianoKeyboard.draw() ;

		synthe = new sound.Synthe() ;

		pianoKeyboard.keyPressed(function(event){
			var note = event.note ;
			if(pianoKeyboard.isLightened(event.note+"/"+event.octave))
			{
				pianoKeyboard.turnOff(event.note+"/"+event.octave) ;
				synthe.noteOff(note,event.octave) ;
			}
			else
			{
				pianoKeyboard.lightUp(event.note+"/"+event.octave) ;
				synthe.noteOn(note,event.octave) ;
				check() ;
			}
		});

		midiInput = new MidiInput(function(press, pianoKey){

			console.log("pianoKey="+pianoKey);
			var octave = Math.floor(pianoKey/12) ;
			var key = pianoKey-(octave*12) ;
			var note = PIANOKEY_2_NOTE[key] ;

			console.log("octave="+octave);
			console.log("note="+note);

			if(press)
			{
				pianoKeyboard.lightUp(note+"/"+octave) ;
				synthe.noteOn(note,octave) ;
				check() ;
			}
			else
			{
				pianoKeyboard.turnOff(note+"/"+octave) ;
				synthe.noteOff(note,octave) ;
			}

		}) ;

		addChord() ;
	}

	function random (low, high) {
	    return parseInt(Math.random() * (high - low) + low);
	}

	function addChord()
	{
		display.clean();

		var octave = 5 ;

		for (var idx = 0; idx < currentChord.length; idx++)
		{
			var note = currentChord[idx] ;
			var key =  note ;
			var slashIdx = note.indexOf("/") ;

			if(slashIdx>-1)
			{
				key = note.substring(0,slashIdx) ;
				var octChar= note.substring(slashIdx+1,slashIdx+2) ;
				octave = parseInt(octChar) ;
			}

			synthe.noteOff(key,octave) ;
		}

		currentChord=[] ;
		currentChordVex=[] ;
		pianoKeyboard.turnAllOff() ;

		for (var idx = 0; idx < 3; idx++) {
			var noteIdx = random(0,ui.NOTES_CHAR.length) ;
			var noteChr = ui.NOTES_CHAR[noteIdx]+ "/" + octave ;
			var noteChrVex = ui.NOTES_CHAR[noteIdx]+ "/" + (octave - 1) ;

			while(currentChord.includes(noteChr))
			{
				noteIdx = random(0,ui.NOTES_CHAR.length) ;
				noteChr = ui.NOTES_CHAR[noteIdx]+ "/" + octave ;
				noteChrVex = ui.NOTES_CHAR[noteIdx]+ "/" + (octave - 1) ;
			}

			currentChord.push(noteChr) ;
			currentChord.sort() ;

			currentChordVex.push(noteChrVex) ;
			currentChordVex.sort() ;
		}

		var vexNote = new VF.StaveNote({
            clef: "treble",
            keys: currentChordVex,
            duration: "4",
          });
		display.addNote(vexNote);

	};

	function check()
	{
		var lightenedNotes = pianoKeyboard.lightenedNotes() ;

		if(lightenedNotes.length==currentChord.length)
		{
			var lightenedNotesStr = JSON.stringify(lightenedNotes) ;
			var currentChordStr = JSON.stringify(currentChord) ;
			if(lightenedNotesStr == currentChordStr)
			{
				$("#result")[0].innerHTML="Good job" ;
				addChord() ;
			}
			else
			{
				$("#result")[0].innerHTML="Try again" ;
			}
		}
	}
<|endoftext|>


<commit_before>var content = jQuery('#content');
var grafs = content.text().split('\n\n');
var len = grafs.length;
if ( len == 1 ) {
    grafs = content.text().split('

');
    len = grafs.length;
    if ( len == 1 ) {
        grafs = content.text().split('
\n
');
        len = grafs.length;
        if ( len == 1 ) {
            grafs = content.text().split('
');
            len = grafs.length;
            if ( len == 1 ) {
                grafs = content.text().split('
 \n
');
                len = grafs.length;
            }
        }
    }
}
var promos = [1,2,3,4,5].sort(function() { return .5 - Math.random(); });
promos.pop(); promos.pop();
var item = promos.pop();
var editing = true;
var ceiling = 10;
if ( content.text().indexOf('in-article-promo') !== -1 ) {
    promos = [];
    item = undefined;
}
if ( typeof item !== 'undefined' ) {
    var section_id = prompt('Enter 1 for soft-news promos, 2 for hard-news promos, 3 for Broncos and nothing for sports, 6 = entertainment, 7 restaurants, 8 food, 9 Ask Amy, 10 books. 11 movies, 12 home-garden, 13 yourhub, 14 editorials, 15 politics, 16 travel 17 real-estate 18 business 19 tech 20 featured homes \n 21 season to share\n 420 marijuana.', '');
    var section = 'sports';
    if ( section_id.indexOf('420') >= 0 ) { section = 'marijuana'; item = 'map'; }
    else if ( section_id.indexOf('10') >= 0 ) { section = 'books'; }
    else if ( section_id.indexOf('11') >= 0 ) { section = 'movies'; }
    else if ( section_id.indexOf('12') >= 0 ) { section = 'home-garden'; }
    else if ( section_id.indexOf('13') >= 0 ) { section = 'yourhub'; }
    else if ( section_id.indexOf('14') >= 0 ) { section = 'editorials'; }
    else if ( section_id.indexOf('15') >= 0 ) { section = 'politics'; }
    else if ( section_id.indexOf('16') >= 0 ) { section = 'travel'; }
    else if ( section_id.indexOf('17') >= 0 ) { section = 'real-estate'; }
    else if ( section_id.indexOf('18') >= 0 ) { section = 'business'; }
    else if ( section_id.indexOf('19') >= 0 ) { section = 'tech'; }
    else if ( section_id.indexOf('20') >= 0 ) { section = 'featured-homes'; }
    else if ( section_id.indexOf('21') >= 0 ) { section = 'season-to-share'; }
    else if ( section_id.indexOf('1') >= 0 ) { section = 'dont-miss'; }
    else if ( section_id.indexOf('2') >= 0 ) { section = 'hard-news'; }
    else if ( section_id.indexOf('3') >= 0 ) { section = 'broncos'; }
    else if ( section_id.indexOf('4') >= 0 ) { section = 'nuggets'; }
    else if ( section_id.indexOf('5') >= 0 ) { section = 'rockies'; }
    else if ( section_id.indexOf('6') >= 0 ) { section = 'entertainment'; }
    else if ( section_id.indexOf('7') >= 0 ) { section = 'restaurants'; }
    else if ( section_id.indexOf('8') >= 0 ) { section = 'food'; }
    else if ( section_id.indexOf('9') >= 0 ) { section = 'ask-amy'; }
}
if ( len > 10 ) {
    grafs.splice(4, 0, '[dfm_iframe src=\'http://extras.denverpost.com/app/in-article-promo/' + section + '-' + item + '.html\' width=\'100%\' height=\'100px\']');
    item = promos.pop();
    if ( len > 16 ) {
        grafs.splice(Math.floor(len/2) + 1, 0, '[dfm_iframe src=\'http://extras.denverpost.com/app/in-article-promo/' + section + '-' + item + '.html\' width=\'100%\' height=\'100px\' scrolling=\'no\']');
        item = promos.pop();
    }
}
if ( typeof item !== 'undefined' && grafs[grafs.length-1].indexOf('in-article') === -1 ) {
    grafs.splice(grafs.length, 0, '[dfm_iframe src=\'http://extras.denverpost.com/app/in-article-promo/' + section + '-' + item + '.html\' width=\'100%\' height=\'100px\' scrolling=\'no\']');
}
jQuery('#content').text(grafs.join('\n\n'));
<commit_msg>Add stock show<commit_after>var content = jQuery('#content');
var grafs = content.text().split('\n\n');
var len = grafs.length;
if ( len == 1 ) {
    grafs = content.text().split('

');
    len = grafs.length;
    if ( len == 1 ) {
        grafs = content.text().split('
\n
');
        len = grafs.length;
        if ( len == 1 ) {
            grafs = content.text().split('
');
            len = grafs.length;
            if ( len == 1 ) {
                grafs = content.text().split('
 \n
');
                len = grafs.length;
            }
        }
    }
}
var promos = [1,2,3,4,5].sort(function() { return .5 - Math.random(); });
promos.pop(); promos.pop();
var item = promos.pop();
var editing = true;
var ceiling = 10;
if ( content.text().indexOf('in-article-promo') !== -1 ) {
    promos = [];
    item = undefined;
}
if ( typeof item !== 'undefined' ) {
    var section_id = prompt('Enter 1 for soft-news promos, 2 for hard-news promos, 3 for Broncos and nothing for sports, 6 = entertainment, 7 restaurants, 8 food, 9 Ask Amy, 10 books. 11 movies, 12 home-garden, 13 yourhub, 14 editorials, 15 politics, 16 travel 17 real-estate 18 business 19 tech 20 featured homes \n 21 season to share\n 22 stock show & 420 marijuana.', '');
    var section = 'sports';
    if ( section_id.indexOf('420') >= 0 ) { section = 'marijuana'; item = 'map'; }
    else if ( section_id.indexOf('10') >= 0 ) { section = 'books'; }
    else if ( section_id.indexOf('11') >= 0 ) { section = 'movies'; }
    else if ( section_id.indexOf('12') >= 0 ) { section = 'home-garden'; }
    else if ( section_id.indexOf('13') >= 0 ) { section = 'yourhub'; }
    else if ( section_id.indexOf('14') >= 0 ) { section = 'editorials'; }
    else if ( section_id.indexOf('15') >= 0 ) { section = 'politics'; }
    else if ( section_id.indexOf('16') >= 0 ) { section = 'travel'; }
    else if ( section_id.indexOf('17') >= 0 ) { section = 'real-estate'; }
    else if ( section_id.indexOf('18') >= 0 ) { section = 'business'; }
    else if ( section_id.indexOf('19') >= 0 ) { section = 'tech'; }
    else if ( section_id.indexOf('20') >= 0 ) { section = 'featured-homes'; }
    else if ( section_id.indexOf('21') >= 0 ) { section = 'season-to-share'; }
    else if ( section_id.indexOf('22') >= 0 ) { section = 'stock-show'; }
    else if ( section_id.indexOf('1') >= 0 ) { section = 'dont-miss'; }
    else if ( section_id.indexOf('2') >= 0 ) { section = 'hard-news'; }
    else if ( section_id.indexOf('3') >= 0 ) { section = 'broncos'; }
    else if ( section_id.indexOf('4') >= 0 ) { section = 'nuggets'; }
    else if ( section_id.indexOf('5') >= 0 ) { section = 'rockies'; }
    else if ( section_id.indexOf('6') >= 0 ) { section = 'entertainment'; }
    else if ( section_id.indexOf('7') >= 0 ) { section = 'restaurants'; }
    else if ( section_id.indexOf('8') >= 0 ) { section = 'food'; }
    else if ( section_id.indexOf('9') >= 0 ) { section = 'ask-amy'; }
}
if ( len > 10 ) {
    grafs.splice(4, 0, '[dfm_iframe src=\'http://extras.denverpost.com/app/in-article-promo/' + section + '-' + item + '.html\' width=\'100%\' height=\'100px\']');
    item = promos.pop();
    if ( len > 16 ) {
        grafs.splice(Math.floor(len/2) + 1, 0, '[dfm_iframe src=\'http://extras.denverpost.com/app/in-article-promo/' + section + '-' + item + '.html\' width=\'100%\' height=\'100px\' scrolling=\'no\']');
        item = promos.pop();
    }
}
if ( typeof item !== 'undefined' && grafs[grafs.length-1].indexOf('in-article') === -1 ) {
    grafs.splice(grafs.length, 0, '[dfm_iframe src=\'http://extras.denverpost.com/app/in-article-promo/' + section + '-' + item + '.html\' width=\'100%\' height=\'100px\' scrolling=\'no\']');
}
jQuery('#content').text(grafs.join('\n\n'));
<|endoftext|>


<commit_before>(function ($, undefined) {

    /*
     * Slider object.
     */
    $.Slider = function (options, element) {
        this.$el = $(element);
        this._init(options);

    };

    $.Slider.defaults = {
        width:1170, //Max slider width
        height:500, //max slider height
        current: 0, // index of current slide
        bgincrement: 100, // increment the bg position (parallax effect) when sliding
        autoplay: true, // slideshow on / off
        interval: 6000 // time between transitions
    };

    $.Slider.prototype = {
            _init: function (options) {
             var  self = this;
            this.options = $.extend(true, {}, $.Slider.defaults, options);
            this.ratio = this.$el.width() / this.$el.height();
            this.$slides = this.$el.children().children('.da-slide');
            this.slidesCount = this.$slides.length;

            this.current = this.options.current;

            if (this.current < 0 || this.current >= this.slidesCount) {

                this.current = 0;

            }

            this.$slides.eq(this.current).addClass('da-slide-current');

            var $navigation = $('<nav class="da-dots"/>');
            for (var i = 0; i < this.slidesCount; ++i) {

                $navigation.append('<span/>');

            }
            $navigation.appendTo(this.$el);

            this.$pages = this.$el.find('nav.da-dots > span');
            this.$navNext = this.$el.find('span.da-arrows-next');
            this.$navPrev = this.$el.find('span.da-arrows-prev');

            this.isAnimating = false;

            this.bgpositer = 0;

            this.cssAnimations = Modernizr.cssanimations;
            this.cssTransitions = Modernizr.csstransitions;

            if (!this.cssAnimations || !this.cssAnimations) {

                this.$el.addClass('da-slider-fb');

            }

            this._updatePage();

            // load the events
            this._loadEvents();

            // slideshow
            if (this.options.autoplay) {

                this._startSlideshow();

            }
            $(window).bind('resize', function() {
               setTimeout(function() {
                    self._makeResponsive();
                }, 150);
			});
           this._makeResponsive();

        },
        _navigate: function (page, dir) {

            var $current = this.$slides.eq(this.current),
                $next, _self = this;

            if (this.current === page || this.isAnimating) return false;

            this.isAnimating = true;

            // check dir
            var classTo, classFrom, d;

            if (!dir) {

                (page > this.current) ? d = 'next' : d = 'prev';

            } else {

                d = dir;

            }

            if (this.cssAnimations && this.cssAnimations) {

                if (d === 'next') {

                    classTo = 'da-slide-toleft';
                    classFrom = 'da-slide-fromright';
                    ++this.bgpositer;

                } else {

                    classTo = 'da-slide-toright';
                    classFrom = 'da-slide-fromleft';
                    --this.bgpositer;

                }

                this.$el.css('background-position', this.bgpositer * this.options.bgincrement + '% center');
            }

            this.current = page;

            $next = this.$slides.eq(this.current);

            if (this.cssAnimations && this.cssAnimations) {

                var rmClasses = 'da-slide-toleft da-slide-toright da-slide-fromleft da-slide-fromright';
                $current.removeClass(rmClasses);
                $next.removeClass(rmClasses);

                $current.addClass(classTo);
                $next.addClass(classFrom);

                $current.removeClass('da-slide-current');
                $next.addClass('da-slide-current');

            }

            // fallback
            if (!this.cssAnimations || !this.cssAnimations) {
 $next.addClass('da-slide-current');
                $next.css('left', (d === 'next') ? '100%' : '-100%').stop().animate({
                    left: '0%'
                }, 1000, function () {
                    _self.isAnimating = false;

                });

                $current.stop().animate({
                    left: (d === 'next') ? '-100%' : '100%'
                }, 1000, function () {
                    $current.removeClass('da-slide-current');
                });

            }

            this._updatePage();

        },
        _updatePage: function () {

            this.$pages.removeClass('da-dots-current');
            this.$pages.eq(this.current).addClass('da-dots-current');

        },
        _startSlideshow: function () {

            var _self = this;

            this.slideshow = setTimeout(function () {

                var page = (_self.current < _self.slidesCount - 1) ? page = _self.current + 1 : page = 0;
                _self._navigate(page, 'next');

                if (_self.options.autoplay) {

                    _self._startSlideshow();

                }

            }, this.options.interval);

        },
        page: function (idx) {
            if (idx >= this.slidesCount || idx < 0) {
                return false;
            }

            if (this.options.autoplay) {
                clearTimeout(this.slideshow);
                this.options.autoplay = false;
            }

            this._navigate(idx);

        },
        _makeResponsive: function () {

            var _self = this;

            var w = this.$el.width();
            var h = this.$el.height();
            var nH = h;
            if(w < _self.options.width){
            var xy = this.options.width / this.options.height;
            var nH = w / xy;
                this.$el.height(Math.ceil(nH));

            }else{
                this.$el.height(Math.ceil(this.options.height));
            }
        },
        _loadEvents: function () {

            var _self = this;

            this.$pages.on('click.cslider', function (event) {

                _self.page($(this).index());
                return false;

            });

            this.$navNext.on('click.cslider', function (event) {

                if (_self.options.autoplay) {

                    clearTimeout(_self.slideshow);
                    _self.options.autoplay = false;

                }

                var page = (_self.current < _self.slidesCount - 1) ? page = _self.current + 1 : page = 0;
                _self._navigate(page, 'next');
                return false;

            });

            this.$navPrev.on('click.cslider', function (event) {

                if (_self.options.autoplay) {

                    clearTimeout(_self.slideshow);
                    _self.options.autoplay = false;

                }

                var page = (_self.current > 0) ? page = _self.current - 1 : page = _self.slidesCount - 1;
                _self._navigate(page, 'prev');
                return false;

            });

            if (this.cssTransitions) {

                if (!this.options.bgincrement) {

                    this.$el.on('webkitAnimationEnd.cslider animationend.cslider OAnimationEnd.cslider', function (event) {

                        if (event.originalEvent.animationName === 'toRightAnim4' || event.originalEvent.animationName === 'toLeftAnim4') {

                            _self.isAnimating = false;

                        }

                    });

                } else {

                    this.$el.on('webkitTransitionEnd.cslider transitionend.cslider OTransitionEnd.cslider', function (event) {

                        if (event.target.id === _self.$el.attr('id'))
                            _self.isAnimating = false;

                    });

                }

            }

        }
    };

    var logError = function (message) {
        if (this.console) {
            console.error(message);
        }
    };

    $.fn.cslider = function (options) {

        if (typeof options === 'string') {

            var args = Array.prototype.slice.call(arguments, 1);

            this.each(function () {

                var instance = $.data(this, 'cslider');

                if (!instance) {
                    logError("cannot call methods on cslider prior to initialization; " +
                        "attempted to call method '" + options + "'");
                    return;
                }

                if (!$.isFunction(instance[options]) || options.charAt(0) === "_") {
                    logError("no such method '" + options + "' for cslider instance");
                    return;
                }

                instance[options].apply(instance, args);

            });

        } else {

            this.each(function () {

                var instance = $.data(this, 'cslider');
                if (!instance) {
                    $.data(this, 'cslider', new $.Slider(options, this));
                }
            });

        }

        return this;

    };

})(jQuery);<commit_msg>Update jquery.cslider.js<commit_after>(function ($, undefined) {

    /*
     * Slider object.
     */
    $.Slider = function (options, element) {
        this.$el = $(element);
        this._init(options);

    };

    $.Slider.defaults = {
        width:1170, //Max slider width
        height:500, //max slider height
        current: 0, // index of current slide
        bgincrement: 100, // increment the bg position (parallax effect) when sliding
        autoplay: true, // slideshow on / off
        interval: 6 // time between transitions
    };

    $.Slider.prototype = {
            _init: function (options) {
             var  self = this;
            this.options = $.extend(true, {}, $.Slider.defaults, options);
            this.ratio = this.$el.width() / this.$el.height();
            this.$slides = this.$el.children().children('.da-slide');
            this.slidesCount = this.$slides.length;

            this.current = this.options.current;

            if (this.current < 0 || this.current >= this.slidesCount) {

                this.current = 0;

            }

            this.$slides.eq(this.current).addClass('da-slide-current');

            var $navigation = $('<nav class="da-dots"/>');
            for (var i = 0; i < this.slidesCount; ++i) {

                $navigation.append('<span/>');

            }
            $navigation.appendTo(this.$el);

            this.$pages = this.$el.find('nav.da-dots > span');
            this.$navNext = this.$el.find('span.da-arrows-next');
            this.$navPrev = this.$el.find('span.da-arrows-prev');

            this.isAnimating = false;

            this.bgpositer = 0;

            this.cssAnimations = Modernizr.cssanimations;
            this.cssTransitions = Modernizr.csstransitions;

            if (!this.cssAnimations || !this.cssAnimations) {

                this.$el.addClass('da-slider-fb');

            }

            this._updatePage();

            // load the events
            this._loadEvents();

            // slideshow
            if (this.options.autoplay) {

                this._startSlideshow();

            }
            $(window).bind('resize', function() {
               setTimeout(function() {
                    self._makeResponsive();
                }, 150);
			});
           this._makeResponsive();

        },
        _navigate: function (page, dir) {

            var $current = this.$slides.eq(this.current),
                $next, _self = this;

            if (this.current === page || this.isAnimating) return false;

            this.isAnimating = true;

            // check dir
            var classTo, classFrom, d;

            if (!dir) {

                (page > this.current) ? d = 'next' : d = 'prev';

            } else {

                d = dir;

            }

            if (this.cssAnimations && this.cssAnimations) {

                if (d === 'next') {

                    classTo = 'da-slide-toleft';
                    classFrom = 'da-slide-fromright';
                    ++this.bgpositer;

                } else {

                    classTo = 'da-slide-toright';
                    classFrom = 'da-slide-fromleft';
                    --this.bgpositer;

                }

                this.$el.css('background-position', this.bgpositer * this.options.bgincrement + '% center');
            }

            this.current = page;

            $next = this.$slides.eq(this.current);

            if (this.cssAnimations && this.cssAnimations) {

                var rmClasses = 'da-slide-toleft da-slide-toright da-slide-fromleft da-slide-fromright';
                $current.removeClass(rmClasses);
                $next.removeClass(rmClasses);

                $current.addClass(classTo);
                $next.addClass(classFrom);

                $current.removeClass('da-slide-current');
                $next.addClass('da-slide-current');

            }

            // fallback
            if (!this.cssAnimations || !this.cssAnimations) {
 $next.addClass('da-slide-current');
                $next.css('left', (d === 'next') ? '100%' : '-100%').stop().animate({
                    left: '0%'
                }, 1000, function () {
                    _self.isAnimating = false;

                });

                $current.stop().animate({
                    left: (d === 'next') ? '-100%' : '100%'
                }, 1000, function () {
                    $current.removeClass('da-slide-current');
                });

            }

            this._updatePage();

        },
        _updatePage: function () {

            this.$pages.removeClass('da-dots-current');
            this.$pages.eq(this.current).addClass('da-dots-current');

        },
        _startSlideshow: function () {

            var _self = this;

            this.slideshow = setTimeout(function () {

                var page = (_self.current < _self.slidesCount - 1) ? page = _self.current + 1 : page = 0;
                _self._navigate(page, 'next');

                if (_self.options.autoplay) {

                    _self._startSlideshow();

                }

            }, this.options.interval);

        },
        page: function (idx) {
            if (idx >= this.slidesCount || idx < 0) {
                return false;
            }

            if (this.options.autoplay) {
                clearTimeout(this.slideshow);
                this.options.autoplay = false;
            }

            this._navigate(idx);

        },
        _makeResponsive: function () {

            var _self = this;

            var w = this.$el.width();
            var h = this.$el.height();
            var nH = h;
            if(w < _self.options.width){
            var xy = this.options.width / this.options.height;
            var nH = w / xy;
                this.$el.height(Math.ceil(nH));

            }else{
                this.$el.height(Math.ceil(this.options.height));
            }
        },
        _loadEvents: function () {

            var _self = this;

            this.$pages.on('click.cslider', function (event) {

                _self.page($(this).index());
                return false;

            });

            this.$navNext.on('click.cslider', function (event) {

                if (_self.options.autoplay) {

                    clearTimeout(_self.slideshow);
                    _self.options.autoplay = false;

                }

                var page = (_self.current < _self.slidesCount - 1) ? page = _self.current + 1 : page = 0;
                _self._navigate(page, 'next');
                return false;

            });

            this.$navPrev.on('click.cslider', function (event) {

                if (_self.options.autoplay) {

                    clearTimeout(_self.slideshow);
                    _self.options.autoplay = false;

                }

                var page = (_self.current > 0) ? page = _self.current - 1 : page = _self.slidesCount - 1;
                _self._navigate(page, 'prev');
                return false;

            });

            if (this.cssTransitions) {

                if (!this.options.bgincrement) {

                    this.$el.on('webkitAnimationEnd.cslider animationend.cslider OAnimationEnd.cslider', function (event) {

                        if (event.originalEvent.animationName === 'toRightAnim4' || event.originalEvent.animationName === 'toLeftAnim4') {

                            _self.isAnimating = false;

                        }

                    });

                } else {

                    this.$el.on('webkitTransitionEnd.cslider transitionend.cslider OTransitionEnd.cslider', function (event) {

                        if (event.target.id === _self.$el.attr('id'))
                            _self.isAnimating = false;

                    });

                }

            }

        }
    };

    var logError = function (message) {
        if (this.console) {
            console.error(message);
        }
    };

    $.fn.cslider = function (options) {

        if (typeof options === 'string') {

            var args = Array.prototype.slice.call(arguments, 1);

            this.each(function () {

                var instance = $.data(this, 'cslider');

                if (!instance) {
                    logError("cannot call methods on cslider prior to initialization; " +
                        "attempted to call method '" + options + "'");
                    return;
                }

                if (!$.isFunction(instance[options]) || options.charAt(0) === "_") {
                    logError("no such method '" + options + "' for cslider instance");
                    return;
                }

                instance[options].apply(instance, args);

            });

        } else {

            this.each(function () {

                var instance = $.data(this, 'cslider');
                if (!instance) {
                    $.data(this, 'cslider', new $.Slider(options, this));
                }
            });

        }

        return this;

    };

})(jQuery);
<|endoftext|>


<commit_before>/**
We have 3 functions to use in GPAcalc.html
The first is: changeVal() to save the values of the drop list
The Second is: calculate() to calculate and print the answer to the user in GPAcalc.html
The Third is: clear() to clear all selected values on drop list and the filled forms

**//

		//var c1=document.getElementById("H1");
		//var strUser=c1.options[e.selectedIndex].value;
		//var strUser2=c1.options[e.selectedIndex].text;

//document.getElementById("oh").innerHTML=c1+" and "+strUser+"and"strUser2;

//Equation (Grade * hours)+(Grade * Hours)/Total sum of hours

var get_id = new Array();

		function changeVal()//to save the values of drop list in GPAcalc.html
		{
			for(var i=1;i<b1.length;i++){
				for(var j=1;j<=2;j++){
			//var get_id= document.getElementById(b1);
			get_id[i]=document.getElementById('b'+i);
			alert(get_id[i][get_id[i].selectedIndex].value);
				}
			}
		}

		function claculate()//onclick button calculate in HTML to calculate the Total GPA
		{
					for (var j=0;j<get_id.length;j++){
			document.getElementById("Result").innerHTML="Your Overall GPA is:"+"\n";
		}

		function clear()//to clear the forms and the drop list on GPAcalc.html
		{

		    if (document.selection)
              document.selection.clear ();
		}

//document.getElementByID("Calc");

<commit_msg>UPDATE 6<commit_after>/**
We have 3 functions to use in GPAcalc.html
The first is: changeVal() to save the values of the drop list
The Second is: calculate() to calculate and print the answer to the user in GPAcalc.html and the equation for calculation is (Grade * hours)+(Grade * Hours)+.../Total sum of hours

The Third is: clear() to clear all selected values on drop list and the filled forms

**//

		//var c1=document.getElementById("H1");
		//var strUser=c1.options[e.selectedIndex].value;
		//var strUser2=c1.options[e.selectedIndex].text;

//document.getElementById("oh").innerHTML=c1+" and "+strUser+"and"strUser2;

//Equation (Grade * hours)+(Grade * Hours)/Total sum of hours

var get_id = new Array();

		function changeVal()//to save the values of drop list in GPAcalc.html
		{
			for(var i=1;i<b1.length;i++){
				for(var j=1;j<=2;j++){
			//var get_id= document.getElementById(b1);
			get_id[i]=document.getElementById('b'+i);
			alert(get_id[i][get_id[i].selectedIndex].value);
				}
			}
		}

		function claculate()//onclick button calculate in HTML to calculate the Total GPA
		{
					for (var j=0;j<get_id.length;j++){
			document.getElementById("Result").innerHTML="Your Overall GPA is:"+"\n";
		}

		function clear()//to clear the forms and the drop list on GPAcalc.html
		{

		    if (document.selection)
              document.selection.clear ();
		}

//document.getElementByID("Calc");

<|endoftext|>


<commit_before>/**
 * @fileoverview OAuth client.
 *
 */

goog.provide('ydn.client.ISimpleOAuthProvider');

/**
 * @interface
 */
ydn.client.ISimpleOAuthProvider = function() {};

/**
 * @return {!goog.async.Deferred}
 */
ydn.client.ISimpleOAuthProvider.prototype.getAuthToken = goog.abstractMethod;

/**
 * @return {!goog.async.Deferred}
 */
ydn.client.ISimpleOAuthProvider.prototype.revokeToken = goog.abstractMethod;
<commit_msg>auth changes.<commit_after>/**
 * @fileoverview OAuth client.
 *
 */

goog.provide('ydn.client.ISimpleOAuthProvider');

/**
 * @interface
 */
ydn.client.ISimpleOAuthProvider = function() {};

ydn.client.ISimpleOAuthProvider.prototype.isClientLogin

/**
 * @return {!goog.async.Deferred}
 */
ydn.client.ISimpleOAuthProvider.prototype.getAuthToken = goog.abstractMethod;

/**
 * @return {!goog.async.Deferred}
 */
ydn.client.ISimpleOAuthProvider.prototype.revokeToken = goog.abstractMethod;
<|endoftext|>


<commit_before>/*!
 * Start Bootstrap - Grayscale Bootstrap Theme (http://startbootstrap.com)
 * Code licensed under the Apache License v2.0.
 * For details, see http://www.apache.org/licenses/LICENSE-2.0.
 */

// jQuery to collapse the navbar on scroll
$(window).scroll(function() {
    if ($(".navbar").offset().top > 50) {
        $(".navbar-fixed-top").addClass("top-nav-collapse");
    } else {
        $(".navbar-fixed-top").removeClass("top-nav-collapse");
    }
});

// jQuery for page scrolling feature - requires jQuery Easing plugin
$(function() {
    $('a.page-scroll').bind('click', function(event) {
        var $anchor = $(this);
        $('html, body').stop().animate({
            scrollTop: $($anchor.attr('href')).offset().top
        }, 1500, 'easeInOutExpo');
        event.preventDefault();
    });
});

// Closes the Responsive Menu on Menu Item Click
$('.navbar-collapse ul li a').click(function() {
    $('.navbar-toggle:visible').click();
});

// Google Maps Scripts
// When the window has finished loading create our google map below
google.maps.event.addDomListener(window, 'load', init);

function init() {
    // Basic options for a simple Google Map
    // For more options see: https://developers.google.com/maps/documentation/javascript/reference#MapOptions
    var mapOptions = {
        // How zoomed in you want the map to start at (always required)
        zoom: 15,

        // The latitude and longitude to center the map (always required)
        center: new google.maps.LatLng(38.7777019, -77.6131908), // New York

        // Disables the default Google Maps UI components
        disableDefaultUI: false,
        scrollwheel: false,
        draggable: true,
         /*
        // How you would like to style the map.
        // This is where you would paste any style found on Snazzy Maps.
        styles: [{
            "featureType": "water",
            "elementType": "geometry",
            "stylers": [{
                "color": "#000000"
            }, {
                "lightness": 17
            }]
        }, {
            "featureType": "landscape",
            "elementType": "geometry",
            "stylers": [{
                "color": "#000000"
            }, {
                "lightness": 20
            }]
        }, {
            "featureType": "road.highway",
            "elementType": "geometry.fill",
            "stylers": [{
                "color": "#000000"
            }, {
                "lightness": 17
            }]
        }, {
            "featureType": "road.highway",
            "elementType": "geometry.stroke",
            "stylers": [{
                "color": "#000000"
            }, {
                "lightness": 29
            }, {
                "weight": 0.2
            }]
        }, {
            "featureType": "road.arterial",
            "elementType": "geometry",
            "stylers": [{
                "color": "#000000"
            }, {
                "lightness": 18
            }]
        }, {
            "featureType": "road.local",
            "elementType": "geometry",
            "stylers": [{
                "color": "#000000"
            }, {
                "lightness": 16
            }]
        }, {
            "featureType": "poi",
            "elementType": "geometry",
            "stylers": [{
                "color": "#000000"
            }, {
                "lightness": 21
            }]
        }, {
            "elementType": "labels.text.stroke",
            "stylers": [{
                "visibility": "on"
            }, {
                "color": "#000000"
            }, {
                "lightness": 16
            }]
        }, {
            "elementType": "labels.text.fill",
            "stylers": [{
                "saturation": 36
            }, {
                "color": "#000000"
            }, {
                "lightness": 40
            }]
        }, {
            "elementType": "labels.icon",
            "stylers": [{
                "visibility": "off"
            }]
        }, {
            "featureType": "transit",
            "elementType": "geometry",
            "stylers": [{
                "color": "#000000"
            }, {
                "lightness": 19
            }]
        }, {
            "featureType": "administrative",
            "elementType": "geometry.fill",
            "stylers": [{
                "color": "#000000"
            }, {
                "lightness": 20
            }]
        }, {
            "featureType": "administrative",
            "elementType": "geometry.stroke",
            "stylers": [{
                "color": "#000000"
            }, {
                "lightness": 17
            }, {
                "weight": 1.2
            }]
        }]*/
    };

    // Get the HTML DOM element that will contain your map
    // We are using a div with id="map" seen below in the <body>
    var mapElement = document.getElementById('map');

    // Create the Google Map using out element and options defined above
    var map = new google.maps.Map(mapElement, mapOptions);
    var ctaLayer = new google.maps.KmlLayer('./kml/BRO.kml');
    console.log(ctaLayer);
    ctaLayer.setMap(map);
    // Custom Map Marker Icon - Customize the map-marker.png file to customize your icon
    /*var image = 'img/map-marker.png';
    var myLatLng = new google.maps.LatLng(38.7777019, -77.6131908);
    var beachMarker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        icon: image
    });*/
}
<commit_msg>changes<commit_after>/*!
 * Start Bootstrap - Grayscale Bootstrap Theme (http://startbootstrap.com)
 * Code licensed under the Apache License v2.0.
 * For details, see http://www.apache.org/licenses/LICENSE-2.0.
 */

// jQuery to collapse the navbar on scroll
$(window).scroll(function() {
    if ($(".navbar").offset().top > 50) {
        $(".navbar-fixed-top").addClass("top-nav-collapse");
    } else {
        $(".navbar-fixed-top").removeClass("top-nav-collapse");
    }
});

// jQuery for page scrolling feature - requires jQuery Easing plugin
$(function() {
    $('a.page-scroll').bind('click', function(event) {
        var $anchor = $(this);
        $('html, body').stop().animate({
            scrollTop: $($anchor.attr('href')).offset().top
        }, 1500, 'easeInOutExpo');
        event.preventDefault();
    });
});

// Closes the Responsive Menu on Menu Item Click
$('.navbar-collapse ul li a').click(function() {
    $('.navbar-toggle:visible').click();
});

// Google Maps Scripts
// When the window has finished loading create our google map below
google.maps.event.addDomListener(window, 'load', init);

function init() {
    // Basic options for a simple Google Map
    // For more options see: https://developers.google.com/maps/documentation/javascript/reference#MapOptions
    var mapOptions = {
        // How zoomed in you want the map to start at (always required)
        zoom: 15,

        // The latitude and longitude to center the map (always required)
        center: new google.maps.LatLng(38.7777019, -77.6131908), // New York

        // Disables the default Google Maps UI components
        disableDefaultUI: false,
        scrollwheel: false,
        draggable: true,
         /*
        // How you would like to style the map.
        // This is where you would paste any style found on Snazzy Maps.
        styles: [{
            "featureType": "water",
            "elementType": "geometry",
            "stylers": [{
                "color": "#000000"
            }, {
                "lightness": 17
            }]
        }, {
            "featureType": "landscape",
            "elementType": "geometry",
            "stylers": [{
                "color": "#000000"
            }, {
                "lightness": 20
            }]
        }, {
            "featureType": "road.highway",
            "elementType": "geometry.fill",
            "stylers": [{
                "color": "#000000"
            }, {
                "lightness": 17
            }]
        }, {
            "featureType": "road.highway",
            "elementType": "geometry.stroke",
            "stylers": [{
                "color": "#000000"
            }, {
                "lightness": 29
            }, {
                "weight": 0.2
            }]
        }, {
            "featureType": "road.arterial",
            "elementType": "geometry",
            "stylers": [{
                "color": "#000000"
            }, {
                "lightness": 18
            }]
        }, {
            "featureType": "road.local",
            "elementType": "geometry",
            "stylers": [{
                "color": "#000000"
            }, {
                "lightness": 16
            }]
        }, {
            "featureType": "poi",
            "elementType": "geometry",
            "stylers": [{
                "color": "#000000"
            }, {
                "lightness": 21
            }]
        }, {
            "elementType": "labels.text.stroke",
            "stylers": [{
                "visibility": "on"
            }, {
                "color": "#000000"
            }, {
                "lightness": 16
            }]
        }, {
            "elementType": "labels.text.fill",
            "stylers": [{
                "saturation": 36
            }, {
                "color": "#000000"
            }, {
                "lightness": 40
            }]
        }, {
            "elementType": "labels.icon",
            "stylers": [{
                "visibility": "off"
            }]
        }, {
            "featureType": "transit",
            "elementType": "geometry",
            "stylers": [{
                "color": "#000000"
            }, {
                "lightness": 19
            }]
        }, {
            "featureType": "administrative",
            "elementType": "geometry.fill",
            "stylers": [{
                "color": "#000000"
            }, {
                "lightness": 20
            }]
        }, {
            "featureType": "administrative",
            "elementType": "geometry.stroke",
            "stylers": [{
                "color": "#000000"
            }, {
                "lightness": 17
            }, {
                "weight": 1.2
            }]
        }]*/
    };

    // Get the HTML DOM element that will contain your map
    // We are using a div with id="map" seen below in the <body>
    var mapElement = document.getElementById('map');

    // Create the Google Map using out element and options defined above
    var map = new google.maps.Map(mapElement, mapOptions);
    var ctaLayer = new google.maps.KmlLayer('http://broadrunoaks.com/kml/BRO.kml');
    console.log(ctaLayer);
    ctaLayer.setMap(map);
    // Custom Map Marker Icon - Customize the map-marker.png file to customize your icon
    /*var image = 'img/map-marker.png';
    var myLatLng = new google.maps.LatLng(38.7777019, -77.6131908);
    var beachMarker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        icon: image
    });*/
}
<|endoftext|>


<commit_before>/**
 * Tweetit jQuery plugin
 *
 * Offer the option to post selected text on tweeter
 *
 * Options:
 *	- via
 *	- url
 *  - hashtags
 *
 */
(function($) {
	'use strict';

	$.fn.tweetit = function (opts) {

		var defaultOptions = {
			url : window.location.href
		};

		var opts = $.extend({}, defaultOptions, opts);

		// TODO: validate inputs

		var win = null;
		var $target = this;
		var $ico = $('<svg class="svg-icon" viewBox="0 0 20 20"><path fill="none" d="M18.258,3.266c-0.693,0.405-1.46,0.698-2.277,0.857c-0.653-0.686-1.586-1.115-2.618-1.115c-1.98,0-3.586,1.581-3.586,3.53c0,0.276,0.031,0.545,0.092,0.805C6.888,7.195,4.245,5.79,2.476,3.654C2.167,4.176,1.99,4.781,1.99,5.429c0,1.224,0.633,2.305,1.596,2.938C2.999,8.349,2.445,8.19,1.961,7.925C1.96,7.94,1.96,7.954,1.96,7.97c0,1.71,1.237,3.138,2.877,3.462c-0.301,0.08-0.617,0.123-0.945,0.123c-0.23,0-0.456-0.021-0.674-0.062c0.456,1.402,1.781,2.422,3.35,2.451c-1.228,0.947-2.773,1.512-4.454,1.512c-0.291,0-0.575-0.016-0.855-0.049c1.588,1,3.473,1.586,5.498,1.586c6.598,0,10.205-5.379,10.205-10.045c0-0.153-0.003-0.305-0.01-0.456c0.7-0.499,1.308-1.12,1.789-1.827c-0.644,0.28-1.334,0.469-2.06,0.555C17.422,4.782,17.99,4.091,18.258,3.266"></path></svg>');
		var $btn = $('').html($ico);

	    $target
	    .on('mousedown', function(e){
	    	$("#tweetit-btn").hide('fast', function () {
	    		$("#tweetit-btn").remove();
	    	});
	    })
	    .on('mouseup', function(e){
	    	e.stopPropagation();
	    	e.preventDefault();
	        var sel;
	        var mainUrl = 'https://twitter.com/intent/tweet?text={0}';
	        var twitterHt = '&hashtags=' + opts.hashtags;
	        var twitterVia = '&via=' + opts.via;
	        var twitterUrl = '&url=' + opts.url;
	        var chars = 140;

	        if (opts.hashtags) {
	        	chars -= (opts.hashtags.match(/,/g) || []).length + 1 + opts.hashtags.length;
	        	mainUrl+=twitterHt;
	        }
	        if (opts.via) {
	        	chars -= opts.via.length + 5;
	        	mainUrl+=twitterVia;
	        }
	        if (opts.url) {
	        	chars -= opts.url.length;
	        	mainUrl+=twitterUrl;
	        }

	        $("#tweetit-btn").hide().remove();

			if(window.getSelection){
				sel = window.getSelection();
			}else if(document.getSelection){
				sel = document.getSelection();
			}else if(document.selection){
				sel = document.selection.createRange().text;
			}

			if (sel.toString() !== '') {

		        var x = e.pageX;
				var y = e.pageY;
				var range;

	            if (sel.getRangeAt) {
					range = sel.getRangeAt(0).cloneRange();
					} else {
					// Older WebKit doesn't have getRangeAt
					range.setStart(sel.anchorNode, sel.anchorOffset);
					range.setEnd(sel.focusNode, sel.focusOffset);

					if (range.collapsed !== sel.isCollapsed) {
					    range.setStart(sel.focusNode, sel.focusOffset);
					    range.setEnd(sel.anchorNode, sel.anchorOffset);
					}
				}

	            var markerStart = document.createElement("span");
	            markerStart.id = "tweetit-start";
	            var markerEnd = document.createElement("span");
	            markerEnd.id = "tweetit-end";

	            range.insertNode(markerStart);
	           	range.collapse(false);
	            range.insertNode(markerEnd);

				var t = $("#tweetit-start").position().top;
				var b = $("#tweetit-end").position().top + $("#tweetit-end").height();
				$("#tweetit-start").remove();
				$("#tweetit-end").remove();
				var shift = "+=10";

				mainUrl = mainUrl.replace('{0}', sel.toString().substring(0, chars-2));

				$("body").append($btn.attr('href', mainUrl));
				if (Math.abs(t-y) > Math.abs(b-y))
				{
					y = b;
				}
				else {
					y = t - $btn.height() - 15;
					shift = "-=10";
				}

				$btn.css('top'); // apparently, just by reading the top style value is enough to reset
				$btn.css({ 'top' : parseInt(y) + 'px', 'left' : x }).show();

				$btn.animate({ top: shift }, .2);

				$btn.on("click", function(e) {
					e.preventDefault();
					e.stopPropagation();

					var width	= 550,
						height	= 350,
						top		= (window.screen.height - height)/2,
						left	= (window.screen.width - width)/2;

					var config = [
						'scrollbars=yes','resizable=yes','toolbar=no','location=yes',
						'width='+width,'height='+height,'left='+left, 'top='+top
					].join(',');

					win = window.open($(this).attr('href'), 'TweetitWindow',config);
				});

			}
		});

		return $target;
	};

})(jQuery);<commit_msg>Updated number of characters trimmed<commit_after>/**
 * Tweetit jQuery plugin
 *
 * Offer the option to post selected text on tweeter
 *
 * Options:
 *	- via
 *	- url
 *  - hashtags
 *
 */
(function($) {
	'use strict';

	$.fn.tweetit = function (opts) {

		var defaultOptions = {
			url : window.location.href
		};

		var opts = $.extend({}, defaultOptions, opts);

		// TODO: validate inputs

		var win = null;
		var $target = this;
		var $ico = $('<svg class="svg-icon" viewBox="0 0 20 20"><path fill="none" d="M18.258,3.266c-0.693,0.405-1.46,0.698-2.277,0.857c-0.653-0.686-1.586-1.115-2.618-1.115c-1.98,0-3.586,1.581-3.586,3.53c0,0.276,0.031,0.545,0.092,0.805C6.888,7.195,4.245,5.79,2.476,3.654C2.167,4.176,1.99,4.781,1.99,5.429c0,1.224,0.633,2.305,1.596,2.938C2.999,8.349,2.445,8.19,1.961,7.925C1.96,7.94,1.96,7.954,1.96,7.97c0,1.71,1.237,3.138,2.877,3.462c-0.301,0.08-0.617,0.123-0.945,0.123c-0.23,0-0.456-0.021-0.674-0.062c0.456,1.402,1.781,2.422,3.35,2.451c-1.228,0.947-2.773,1.512-4.454,1.512c-0.291,0-0.575-0.016-0.855-0.049c1.588,1,3.473,1.586,5.498,1.586c6.598,0,10.205-5.379,10.205-10.045c0-0.153-0.003-0.305-0.01-0.456c0.7-0.499,1.308-1.12,1.789-1.827c-0.644,0.28-1.334,0.469-2.06,0.555C17.422,4.782,17.99,4.091,18.258,3.266"></path></svg>');
		var $btn = $('').html($ico);

	    $target
	    .on('mousedown', function(e){
	    	$("#tweetit-btn").hide('fast', function () {
	    		$("#tweetit-btn").remove();
	    	});
	    })
	    .on('mouseup', function(e){
	    	e.stopPropagation();
	    	e.preventDefault();
	        var sel;
	        var mainUrl = 'https://twitter.com/intent/tweet?text={0}';
	        var twitterHt = '&hashtags=' + opts.hashtags;
	        var twitterVia = '&via=' + opts.via;
	        var twitterUrl = '&url=' + opts.url;
	        var chars = 140;

	        if (opts.hashtags) {
	        	chars -= (opts.hashtags.match(/,/g) || []).length + 1 + opts.hashtags.length;
	        	mainUrl+=twitterHt;
	        }
	        if (opts.via) {
	        	chars -= opts.via.length + 5;
	        	mainUrl+=twitterVia;
	        }
	        if (opts.url) {
	        	chars -= opts.url.length;
	        	mainUrl+=twitterUrl;
	        }

	        $("#tweetit-btn").hide().remove();

			if(window.getSelection){
				sel = window.getSelection();
			}else if(document.getSelection){
				sel = document.getSelection();
			}else if(document.selection){
				sel = document.selection.createRange().text;
			}

			if (sel.toString() !== '') {

		        var x = e.pageX;
				var y = e.pageY;
				var range;

	            if (sel.getRangeAt) {
					range = sel.getRangeAt(0).cloneRange();
					} else {
					// Older WebKit doesn't have getRangeAt
					range.setStart(sel.anchorNode, sel.anchorOffset);
					range.setEnd(sel.focusNode, sel.focusOffset);

					if (range.collapsed !== sel.isCollapsed) {
					    range.setStart(sel.focusNode, sel.focusOffset);
					    range.setEnd(sel.anchorNode, sel.anchorOffset);
					}
				}

	            var markerStart = document.createElement("span");
	            markerStart.id = "tweetit-start";
	            var markerEnd = document.createElement("span");
	            markerEnd.id = "tweetit-end";

	            range.insertNode(markerStart);
	           	range.collapse(false);
	            range.insertNode(markerEnd);

				var t = $("#tweetit-start").position().top;
				var b = $("#tweetit-end").position().top + $("#tweetit-end").height();
				$("#tweetit-start").remove();
				$("#tweetit-end").remove();
				var shift = "+=10";

				mainUrl = mainUrl.replace('{0}', sel.toString().substring(0, chars - 4));

				$("body").append($btn.attr('href', mainUrl));
				if (Math.abs(t-y) > Math.abs(b-y))
				{
					y = b;
				}
				else {
					y = t - $btn.height() - 15;
					shift = "-=10";
				}

				$btn.css('top'); // apparently, just by reading the top style value is enough to reset
				$btn.css({ 'top' : parseInt(y) + 'px', 'left' : x }).show();

				$btn.animate({ top: shift }, .2);

				$btn.on("click", function(e) {
					e.preventDefault();
					e.stopPropagation();

					var width	= 550,
						height	= 350,
						top		= (window.screen.height - height)/2,
						left	= (window.screen.width - width)/2;

					var config = [
						'scrollbars=yes','resizable=yes','toolbar=no','location=yes',
						'width='+width,'height='+height,'left='+left, 'top='+top
					].join(',');

					win = window.open($(this).attr('href'), 'TweetitWindow',config);
				});

			}
		});

		return $target;
	};

})(jQuery);
<|endoftext|>


<commit_before>;(function($) {

$.widget("ui.tree", {
	options: {
		expandRoot: true,
		data: null,
		root: null,
		expandOnSelect: true,
		closeOthersOnSelect: true,
		comparator: function(a, b) {
			if (a.name.toLowerCase()  b.name.toLowerCase()) return 1;
			return 0;
		}
	},

	select: function(hash, li) {
		var self = this,
			parents = [];

		if ($.isArray(hash)) {
			parents = hash;
			hash = parents.pop();
		}

		if (!this._data[hash]) {
			this.deselect();
			return;
		}

		if (hash != this._lastHash) {
			this._lastHash = hash;

			for (var i = 0; i < parents.length; i++) {
				this.open(parents[i]);
			}

			if (!li) li = $('#' + this.widgetBaseClass + '_' + hash);

			$('li.selected', this.element).removeClass('selected');
			li.addClass('selected');

			if (this.options.closeOthersOnSelect) {
				$('li.' + this.widgetBaseClass + '-open').each(function(){
					if (!$(this).equals(li) && !li.isParentOf($(this)) && !li.isChildOf($(this))) {
						self.close(null, $(this));
					}
				});
			}

			if (this.options.expandOnSelect) this.open(hash, li);
		}
	},

	deselect: function() {
		$('li.selected', this.element).removeClass('selected');
		this._lastHash = null;
	},

	open: function(hash, li) {
		if (!li) li = $('#' + this.widgetBaseClass + '_' + hash);

		if ($('> ul', li).size() != 0) {
			li.addClass(this.widgetBaseClass + '-open');
			$('> ul', li).show();
		}
		else {
			li.addClass(this.widgetBaseClass + '-open');
			li.append(this._createUL(hash));
		}
	},

	close: function(hash, li) {
		if (!li) li = $('#' + this.widgetBaseClass + '_' + hash);

		if (!li.hasClass(this.widgetBaseClass + '-root')) {
			li.removeClass(this.widgetBaseClass + '-open');
			$('> ul', li).hide();
		}
	},

	toggle: function(hash, li) {
		if (!li) li = $('#' + this.widgetBaseClass + '_' + hash);

		if (li.hasClass(this.widgetBaseClass + '-open')) {
			this.close(hash, li);
		}
		else {
			this.open(hash, li);
		}
	},

	_create: function() {
		var self = this,
			$elem = $(this.element).disableTextSelection().addClass(this.widgetBaseClass);

		if (this.options.data == null || this.options.root == null) {
			throw "data and root must be specified in the options for ui.tree.";
		}

		this._lastHash = null;
		this._data = this.options.data;

		if ($.isUndefined(this._data[this.options.root])) {
			throw "root was not found in the provided directory data.";
		}

		$elem.click(function(eo) {
			var id, li, target = $(eo.target);

			if (target.closest('div.' + self.widgetBaseClass + '-expander').size() > 0) {
				li = target.closest('li');
				id = li.attr('id');
			}

			if (li && $.isString(id) && id.indexOf(self.widgetBaseClass + '_') == 0) {
				var hash = id.substring((self.widgetBaseClass + '_').length);

				if (target.hasClass(self.widgetBaseClass + '-expander')) {
					self.toggle(hash, li);
				}
				else {
					self.select(hash, li);
					self._trigger('selection', {}, [ hash ]);
				}
			}
		});

		$elem.append('
' + this._createLI(this.options.root, this._data[this.options.root].name, this.widgetBaseClass + '-root ' + this.widgetBaseClass + '-open') + '
');

		$('#' + this.widgetBaseClass + '_' + this.options.root).append(this._createUL(this.options.root));
	},

	_createUL: function(hash) {
		if (!this._data[hash]) return '';

		var li = [],
			self = this,
			subdirs = this._data[hash].subdirs;

		for (var i = 0; i < subdirs.length; i++) {

			var data = this._data[subdirs[i]];
			var html = this._createLI(subdirs[i], data.name, data.subdirs.length > 0 ? '' : this.widgetBaseClass + '-nosubdirs');

			var index = BinarySearch(li, data, function(needle, item, index) {
				return self.options.comparator(needle, item[0]);
			});

			if (index < 0) {
				li.splice(Math.abs(index)-1, 0, [data, html]);
			}
			else {
				li.splice(index, 0, [data, html]);
			}
		}

		var finalHTML = '';
		for (var i = 0; i < li.length; i++) {
			finalHTML += li[i][1];
		}

		return '
' + finalHTML + '
';
	},

	_createLI: function(hash, name, classes) {
		return '

' + name.htmlencode() + '

';
	},

	resort: function() {
		var self = this, subUL,
			stack = [ $('>ul', this.element).get(0) ], ul;

		while ($.isDefined(ul = stack.pop())) {
			var sorted = [], original = $('>li', ul);

			$('>li', ul).each(function(){
				var hash = this.id.substr((self.widgetBaseClass + '_').length);
				var data = self._data[hash];

				if (subUL = $('>ul', this))
					stack.push(subUL);

				var index = BinarySearch(sorted, data, function(needle, item, index) {
					return self.options.comparator(needle, item[0]);
				});

				if (index < 0) {
					sorted.splice(Math.abs(index)-1, 0, [data, this]);
				}
				else {
					sorted.splice(index, 0, [data, this]);
				}
			});

			$(ul).append($($.map(sorted, function(item){ return item[1]; })));
		}
	}
});

})(jQuery);<commit_msg>Added backwards compatibility for the previous 'directory' report file format.<commit_after>;(function($) {

$.widget("ui.tree", {
	options: {
		expandRoot: true,
		data: null,
		root: null,
		expandOnSelect: true,
		closeOthersOnSelect: true,
		comparator: function(a, b) {
			if (a.name.toLowerCase()  b.name.toLowerCase()) return 1;
			return 0;
		}
	},

	select: function(hash, li) {
		var self = this,
			parents = [];

		if ($.isArray(hash)) {
			parents = hash;
			hash = parents.pop();
		}

		if (!this._data[hash]) {
			this.deselect();
			return;
		}

		if (hash != this._lastHash) {
			this._lastHash = hash;

			for (var i = 0; i < parents.length; i++) {
				this.open(parents[i]);
			}

			if (!li) li = $('#' + this.widgetBaseClass + '_' + hash);

			$('li.selected', this.element).removeClass('selected');
			li.addClass('selected');

			if (this.options.closeOthersOnSelect) {
				$('li.' + this.widgetBaseClass + '-open').each(function(){
					if (!$(this).equals(li) && !li.isParentOf($(this)) && !li.isChildOf($(this))) {
						self.close(null, $(this));
					}
				});
			}

			if (this.options.expandOnSelect) this.open(hash, li);
		}
	},

	deselect: function() {
		$('li.selected', this.element).removeClass('selected');
		this._lastHash = null;
	},

	open: function(hash, li) {
		if (!li) li = $('#' + this.widgetBaseClass + '_' + hash);

		if ($('> ul', li).size() != 0) {
			li.addClass(this.widgetBaseClass + '-open');
			$('> ul', li).show();
		}
		else {
			li.addClass(this.widgetBaseClass + '-open');
			li.append(this._createUL(hash));
		}
	},

	close: function(hash, li) {
		if (!li) li = $('#' + this.widgetBaseClass + '_' + hash);

		if (!li.hasClass(this.widgetBaseClass + '-root')) {
			li.removeClass(this.widgetBaseClass + '-open');
			$('> ul', li).hide();
		}
	},

	toggle: function(hash, li) {
		if (!li) li = $('#' + this.widgetBaseClass + '_' + hash);

		if (li.hasClass(this.widgetBaseClass + '-open')) {
			this.close(hash, li);
		}
		else {
			this.open(hash, li);
		}
	},

	_create: function() {
		var self = this,
			$elem = $(this.element).disableTextSelection().addClass(this.widgetBaseClass);

		if (this.options.data == null || this.options.root == null) {
			throw "data and root must be specified in the options for ui.tree.";
		}

		this._lastHash = null;
		this._data = this.options.data;

		if ($.isUndefined(this._data[this.options.root])) {
			throw "root was not found in the provided directory data.";
		}

		$elem.click(function(eo) {
			var id, li, target = $(eo.target);

			if (target.closest('div.' + self.widgetBaseClass + '-expander').size() > 0) {
				li = target.closest('li');
				id = li.attr('id');
			}

			if (li && $.isString(id) && id.indexOf(self.widgetBaseClass + '_') == 0) {
				var hash = id.substring((self.widgetBaseClass + '_').length);

				if (target.hasClass(self.widgetBaseClass + '-expander')) {
					self.toggle(hash, li);
				}
				else {
					self.select(hash, li);
					self._trigger('selection', {}, [ hash ]);
				}
			}
		});

		$elem.append('
' + this._createLI(this.options.root, this._data[this.options.root].name, this.widgetBaseClass + '-root ' + this.widgetBaseClass + '-open') + '
');

		$('#' + this.widgetBaseClass + '_' + this.options.root).append(this._createUL(this.options.root));
	},

	_createUL: function(hash) {
		if (!this._data[hash]) return '';

		var li = [],
			self = this,
			subdirs = this._data[hash].subdirs;

		for (var i = 0; i < subdirs.length; i++) {

			var hash = $.isString(subdirs[i]) ? subdirs[i] : subdirs[i].hash;
			var data = this._data[hash];
			var html = this._createLI(hash, data.name, data.subdirs.length > 0 ? '' : this.widgetBaseClass + '-nosubdirs');

			var index = BinarySearch(li, data, function(needle, item, index) {
				return self.options.comparator(needle, item[0]);
			});

			if (index < 0) {
				li.splice(Math.abs(index)-1, 0, [data, html]);
			}
			else {
				li.splice(index, 0, [data, html]);
			}
		}

		var finalHTML = '';
		for (var i = 0; i < li.length; i++) {
			finalHTML += li[i][1];
		}

		return '
' + finalHTML + '
';
	},

	_createLI: function(hash, name, classes) {
		return '

' + name.htmlencode() + '

';
	},

	resort: function() {
		var self = this, subUL,
			stack = [ $('>ul', this.element).get(0) ], ul;

		while ($.isDefined(ul = stack.pop())) {
			var sorted = [], original = $('>li', ul);

			$('>li', ul).each(function(){
				var hash = this.id.substr((self.widgetBaseClass + '_').length);
				var data = self._data[hash];

				if (subUL = $('>ul', this))
					stack.push(subUL);

				var index = BinarySearch(sorted, data, function(needle, item, index) {
					return self.options.comparator(needle, item[0]);
				});

				if (index < 0) {
					sorted.splice(Math.abs(index)-1, 0, [data, this]);
				}
				else {
					sorted.splice(index, 0, [data, this]);
				}
			});

			$(ul).append($($.map(sorted, function(item){ return item[1]; })));
		}
	}
});

})(jQuery);<|endoftext|>