//Remove image titles
jQuery(document).ready(function($) {
    $('img[title]').each(function() {
        $(this).removeAttr('title');
    });
});

//Hyphenators
Hyphenator.config({
    displaytogglebox: false,
    minwordlength: 9
});
Hyphenator.run();

//External sites opening in new window
$(document).ready(function() {
    $('a').attr('target', '_blank');
    $('a[href*=threebyfour]').attr('target', '_self');
});

//Scrolling

function scroll(direction) {
    var scroll, i, positions = [],
        here = $(window).scrollTop() + 9,
        collection = $('.anchor');
    collection.each(function() {
        positions.push(parseInt($(this).offset()['top'], 10));
    });
    for (i = 0; i < positions.length; i++) {
        if (direction == 'next' && positions[i] > here) {
            scroll = collection.get(i);
            break;
        }
        if (direction == 'prev' && i > 0 && positions[i] >= here) {
            scroll = collection.get(i - 1);
            break;
        }
    }
    if (scroll) {
        $.scrollTo(scroll, {
            duration: 700,
            offset: -9
        });
    }
    return false;
}
$(function() {
    $("#next,#prev").click(function() {
        return scroll($(this).attr('id'));
    });
});
$(window).keydown(function(event) {

    if (event.keyCode) {
        switch (event.which) {
        case 32:
            // space for next
        case 40:
            // down arrow = next
            scroll('next');
            break;
        case 38:
            // up arrow = prev
            scroll('prev');
            break;
        }
    }

});

window.onkeydown = function(e) {
    if(e.keyCode == 32 || e.keyCode == 38 || e.keyCode == 40){return false;}
};
