/*
* Global vars
*/

var $w;
var $h;
var $slides;
var $sections;
var $components;
var $play;
var $video;
var chapter;
var store;
var anchors;

var breakSlidesForMobile = function() {
    /*
    * break slides into multiple slides if the screen is too small
    */
    $w = $(window).width();
    $h = $(window).height();
    if ($w < 768) {
        $components.addClass('slide');
        chapter = $components.parents('.section');
        store = $components.clone();
        $components.parents('.slide').remove();
        $(chapter).append(store);
    }
};

var setSlideHeight = function() {

    /*
    * Set the window width and height, make all slides fill the screen.
    */

    $w = $(window).width();
    $h = $(window).height();
    $slides.css('height', $h);
    $slides.css('width', $w);

    // also resize the video

    jwplayer('player').resize($w, $h);
};

var setUpFullPage = function() {
    // clear all anchors
    anchors = [];

    // get the anchors

   _.each($sections, function(section) {
        var anchor = $(section).data('anchor');
        if (anchor == undefined) {
            var slides = $(section).find('.slide');
            console.log(slides);
            anchor = $(slides[0]).data('anchor');
            console.log(anchor);
        }
        anchors.push(anchor);
    });

    $.fn.fullpage({
        autoScrolling: false,
        anchors: anchors,
        verticalCentered: true,
        resize: true,
        css3: true,
        scrollingSpeed: 800,
        loopHorizontal: false,
        easing: 'swing'
    });
};

var revealVideo = function() {

    /*
    * Show the video.
    */

    var text = $(this).parents('.text');
    $(text).hide();
    $(text).parent().css('background-image', '');
    $(text).next().css('display', 'table-cell');
    var player = text.siblings('#player');
    initPlayer(player);
};

var initPlayer = function(player) {

    /*
    * Setup JWPlayer.
    */

    jwplayer('player').setup({
        modes: [{
            type: 'flash',
            src: 'http://www.npr.org/templates/javascript/jwplayer/player.swf',
            config: {
                skin: 'http://media.npr.org/templates/javascript/jwplayer/skins/mle/npr-video-archive/npr-video-archive.zip',
                file: 'http://pd.npr.org/npr-mp4/npr/nprvid/2013/02/20130219_nprvid_oscars-n-600000.mp4',
                image: 'http://apps.npr.org/oscars-2013/img/cheat-sheet-promo_wide.jpg',
                'hd.file': 'http://pd.npr.org/npr-mp4/npr/nprvid/2013/02/20130219_nprvid_oscars-n-1200000.mp4'
            }
        }, {
            type: 'html5',
            config: {
                levels: [
                    {
                        file: 'http://pd.npr.org/npr-mp4/npr/nprvid/2013/02/20130219_nprvid_oscars-n-600000.mp4',
                        image: 'http://apps.npr.org/oscars-2013/img/cheat-sheet-promo_wide.jpg'
                    }
                ]
            }
        }],
        bufferlength: '5',
        controlbar: 'over',
        icons: 'true',
        autostart: false,
        width: $w,
        height: $h
    });
    jwplayer('player').play();

};

$(document).ready(function() {

    /*
    * Define vars
    */

    $slides = $('.section, .slide');
    $sections = $('.section');
    $play = $('.btn-play');
    $video = $('.video');
    $components = $('.component');

    // init chapters

    breakSlidesForMobile();
    setSlideHeight();
    setUpFullPage();

    // handlers

    // $(document).keydown(handleKeyPress);
    $play.on('click', revealVideo);

    // Redraw slides if the window resizes

    $(window).resize(setSlideHeight);
});
@@ -1078,16 +1078,17 @@
 nchor ==
+=
  undefin
@@ -1089,24 +1089,24 @@
 ndefined) %7B%0A
-
             
@@ -1149,41 +1149,8 @@
 ');%0A
-            console.log(slides);%0A
     
@@ -1199,41 +1199,8 @@
 ');%0A
-            console.log(anchor);%0A
     

kill console logs