// SLIDER
$('#slider').nivoSlider({
    effect: 'random',
    slices: 20,
    animSpeed: 600,
    pauseTime: 4000,
    startSlide: 0,
    directionNav: true,
    directionNavHide: false,
    controlNav: true,
    controlNavThumbs: false,
    controlNavThumbsFromRel: false,
    controlNavThumbsSearch: '.jpg',
    controlNavThumbsReplace: '_thumb.jpg',
    keyboardNav: true,
    pauseOnHover: true,
    manualAdvance: false,
    captionOpacity: 0.8,
    beforeChange: function () {},
    afterChange: function () {},
    slideshowEnd: function () {}
});


// BOXXIE
$('.ref_inner').hover(function () {
    $(".figcaption", this).stop().animate({
        bottom: '0px'
    }, {
        queue: false,
        duration: 150
    });
}, function () {
    $('.figcaption', this).stop().animate({
        bottom: '-28px'
    }, {
        queue: false,
        duration: 350
    });
});

// TWITTER
$('.tweet').tweet({
    username: "martijndevalk",
    join_text: "auto",
    avatar_size: 32,
    count: 3,
    loading_text: "loading tweets..."
});


// FLICKR
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=39628604@N08&lang=en-us&format=json&jsoncallback=?", displayImages);

function displayImages(data) {
    var htmlString = "";
    $.each(data.items, function (i, item) {
        var sourceSquare = (item.media.m).replace("_m.jpg", "_s.jpg");
        if (i == 6) return false;
        htmlString += '<li><a href="' + item.link + '" title="' + item.title + '">';
        htmlString += '<img title="' + item.title + '" src="' + sourceSquare;
        htmlString += '" alt="';
        htmlString += item.title + '" />';
        htmlString += '<span class="overlay"/></a></li>';
    });
    $('#flickr').html(htmlString);
}


// SOURCE HOVER
$('.hover').hover(function () {
    var filename = $(this).attr("src").replace(/\.(\w+)$/, "_hover.$1");
    $(this).attr("src", filename);
}, function () {
    var filename = $(this).attr("src").replace(/_hover\.(\w+)$/, ".$1");
    $(this).attr("src", filename);
});


// LIGHTBOX
jQuery('.lightbox').lightbox();


// LOCAL-SCROLL
$.localScroll({
    target: '#page',
    queue: true,
    duration: 1000,
    hash: true
});
