$(document).ready(function(){
    loadFacts();
    loadFlickrPhotos();

})


//a 'fun' function to add a random fact below the image on the about page, clicking the link will load a different fact
function loadFacts() {
    var factArray = ["I've had the same piece of chin hair/soul plate/mini beard for the last 10 years. It's been different sizes and colours but always been there.", "I have a pet rat, his name is Lancelot and he's lovely", "I met my fiancee playing the online game Medal of Honour",
    "I love Chinese food", "My mum and dad emigrated to Crete and I now get flight only holidays", "I speak 'kitchen French'", "I could eat Sushi for every meal", "I broke my collar bone when I was 9", "I have had my appendix taken out. (meh, I didn't need it)", "I love UFC and WWE",
    "I had braces when I was a kid", "I am still 'best mates' with my best mate from school"];
    var i = Math.floor(Math.random()*factArray.length);
    var fact = factArray[i];
    $('.randomFact').html('<p>Random fact: '+fact+' <a href="#loadFact">Another?</a></p>').css({"display":"block"});
    $('.randomFact a').click(function(){
        $('.randomFact').empty();
        loadFacts();
    })

}

function loadFlickrPhotos() {
    $.getJSON("http://api.flickr.com/services/rest/?&method=flickr.people.getPublicPhotos&api_key=298f781f1cc78b7f52d45be91cc4e575&user_id=92856267@N00&per_page=6&extras=url_s&format=json&jsoncallback=?", displayFlickrImages);
}

function displayFlickrImages(data) { 
    $.each(data.photos.photo, function(i, item){
        var url = item.url_s.substring(item.url_s.lastIndexOf('/')).replace("/", "");
        var urlID = url.split('_');
        $('#flickr ul').append('<li><a href="http://flickr.com/photo.gne?id='+urlID[0]+'"><img src="'+item.url_s+'"/></li></a>');
    })
    $('#flickr ul li:odd').addClass('last');
    $('#flickr').show();
}


