Photos | Do Something 101
function makeUnselectable(elem) {
if (typeof(elem) == 'string')
elem = document.getElementById(elem);
if (elem) {
elem.onselectstart = function() { return false; };
elem.style.MozUserSelect = "none";
elem.style.KhtmlUserSelect = "none";
elem.unselectable = "on";
}
}
(function($){
$.fn.shuffle = function() {
return this.each(function(){
var items = $(this).children();
return (items.length)
? $(this).html($.shuffle(items))
: this;
});
}
$.shuffle = function(arr) {
for(
var j, x, i = arr.length; i;
j = parseInt(Math.random() * i),
x = arr[--i], arr[i] = arr[j], arr[j] = x
);
return arr;
}
})(jQuery);
$(document).ready(function() {
$.getJSON("http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=140e783f60c18fab973790132bdb47f8&photoset_id=72157617395959713&format=json&extras=url_sq,url_m&jsoncallback=?", function(data) {
var photos_per_row = 5;
var rows_per_page = 2;
var photos_per_page = photos_per_row * rows_per_page;
var current_position = 0;
var photos = $.shuffle(data.photoset.photo);
$("#ds101-highlighted-image").html("");
var items = "
for(var j = 0; j < photos.length / photos_per_page; j++) { // loop over all photos, j = which page
items += "
";
}
items += "
";
$("#ds101-images").html(items);
manageControls(0);
$(".flickr-thumbnail").click(function(){
$("#ds101-highlighted-image img").attr('src', this.src.replace("_s.jpg", ".jpg"));
});
$(".arrow").bind('click', slider);
function slider() {
current_position = ($(this).hasClass('right'))
? current_position+1 : current_position-1;
manageControls(current_position);
$('#slideInner').animate({
'marginLeft': 420*(-current_position)
});
}
function manageControls(position) {
if (position == 0) {
$(".arrow.left").hide();
} else {
$(".arrow.left").show();
}
if (position >= ((photos.length / photos_per_page) - 1)) {
$(".arrow.right").hide();
} else {
$(".arrow.right").show();
}
}
makeUnselectable("main");
});
});