$(document).ready(function () {

  // Font replaces
  Cufon.replace('div#main h1', { fontFamily: 'RotisSemiSans' });
  Cufon.replace('div.column h2', { fontFamily: 'RotisSemiSans' });
  Cufon.replace('div#content h2', { fontFamily: 'RotisSemiSans' });
  Cufon.replace('div#banner h3', { fontFamily: 'RotisSemiSans' });
  Cufon.replace('div#quiz h1', { fontFamily: 'RotisSemiSans' });
  Cufon.replace('div#quiz h3', { fontFamily: 'RotisSemiSans' });


  // Fancyboxes
  // afbeeldingen in artikelen
  $("a.fancybox").fancybox({
    'titleShow': false,
    'showNavArrows': false
  });

  // selectie scherm voor besturingssysteem
  $("#popup-os").fancybox({
    'type': 'iframe',
    'titleShow': false,
    'showNavArrows': false,
    'autoDimensions': false,
    'autoScale': false,
    'width': 620,
    'height': 200,
    'scrolling': 'no',
    'onClosed': function () {
      parent.location.reload(true);
    }
  });

  // instructievideo's
  $("#popup-video0").fancybox({
    'titleShow': false,
    'showNavArrows': false,
    'autoScale': false,
    'padding': 0,
    'width': 800,
    'height': 640
  });

  $("#popup-video1").fancybox({
    'titleShow': false,
    'showNavArrows': false,
    'autoScale': false,
    'padding': 0,
    'width': 800,
    'height': 640
  });

  $("#popup-video2").fancybox({
    'titleShow': false,
    'showNavArrows': false,
    'autoScale': false,
    'padding': 0,
    'width': 800,
    'height': 640
  });

  $("#popup-video3").fancybox({
    'titleShow': false,
    'showNavArrows': false,
    'autoScale': false,
    'padding': 0,
    'width': 800,
    'height': 640
  });

  $("#popup-video4").fancybox({
    'titleShow': false,
    'showNavArrows': false,
    'autoScale': false,
    'padding': 0,
    'width': 800,
    'height': 640
  });

  // gekoppelde spellen
  $("#popup-game-geheugentrainer").fancybox({
    'titleShow': false,
    'showNavArrows': false,
    'autoScale': false,
    'padding': 10,
    'width': 915,
    'height': 420,
    'scrolling': 'no'
  });

  $("#popup-game-zoekdeverschillen").fancybox({
    'titleShow': false,
    'showNavArrows': false,
    'autoScale': false,
    'padding': 10,
    'width': 925,
    'height': 460,
    'scrolling': 'no'
  });

  $("#popup-game-raaddeplaat").fancybox({
    'titleShow': false,
    'showNavArrows': false,
    'autoScale': false,
    'padding': 15,
    'width': 900,
    'height': 460,
    'scrolling': 'no'
  });

  $("#popup-game-fotopuzzel").fancybox({
    'titleShow': false,
    'showNavArrows': false,
    'autoScale': false,
    'padding': 10,
    'width': 918,
    'height': 433,
    'scrolling': 'no'
  });

  // scherm voor waardering van artikelen
  $(".popup-waardering").fancybox({
    'type': 'iframe',
    'titleShow': false,
    'showNavArrows': false,
    'autoScale': false,
    'width': 620,
    'height': 400
  });

  $("#popup-quiz").fancybox({
    'titleShow': false,
    'showNavArrows': false,
    'scrolling': 'no'
  });

  // prijspuzzel : woordzoeker
  $(".woordzoeker").fancybox({
    'type': 'iframe',
    'titleShow': false,
    'showNavArrows': false,
    'scrolling': 'no',
    'width': 800,
    'height': 600,
    'padding': 0
  });


  // Bus animatie	
  if ($('div#routeDetail ul#haltes').length) {
    $("div#routeDetail ul#haltes li.selected").css("background", "none");

    if ($('ul#haltes li:first').hasClass('start')) {
      $startPos = '13';
    }
    else if ($('ul#haltes li:last').hasClass('start')) {
      $startPos = '919';
    }
    else {
      $startPos = $('ul#haltes li.start').position().left + ($('ul#haltes li.start').width() / 2 - 16);
    }

    $('div#bus').css({ 'left': $startPos + 'px' });

    if ($('ul#haltes li:first').hasClass('selected')) {
      $endPos = '13';
    }
    else if ($('ul#haltes li:last').hasClass('selected')) {
      $endPos = '919';
    }
    else {
      $endPos = $('ul#haltes li.selected').position().left + ($('ul#haltes li.selected').width() / 2 - 16);
    }

    if ($startPos < $endPos) {
      distance = Math.round($endPos - $startPos);
    }
    else {
      distance = Math.round($startPos - $endPos);
    }

    $('div#bus').animate(
      { left: $endPos + 'px' },
      { duration: (10 * (distance))
      });
  }


  // Toggle
  $("p.more").css("display", "none");

  $('a.more').click(function () {
    $(this).toggleClass("open");
    $(this).next("p.more").toggle();
  });


  // Tooltip voor kaarten
  $('div#main ul#haltes li a').tooltip({
    delay: 0,
    showURL: false,
    track: true,
    top: -180,
    left: -119,
    bodyHandler: function () {
      return $(this).next("div").html();
    }
  });
});
