// JavaScript Document

var Page = {

	init: function() {		
		var self = this;
		var setId = "72157622524797016";
		var call = "http://api.flickr.com/services/rest/?format=json&jsoncallback=?&api_key=cf15bd9e04ca62ad08113853008c558f&method=flickr.photosets.getPhotos&photoset_id={setId}&extras=original_format&_1254691943379"
					.supplant( { setId:setId });
	    
		$.getJSON(call, function(r){ 
			console.log(r);
			$.each(r.photoset.photo, function() {
						console.log(this);	 
						var path = "http://farm{farm}.static.flickr.com/{server}/{id}_{secret}_b.jpg".supplant( this );	
						console.log(path);
						$(".content").prepend("<img class='homeImage' src='{path}' />".supplant( { path:path } ));
					}				 
		    ); // end each
			
			setTimeout( function() {
				$(".content img:last").fadeIn(1000);
				self.startRotation();
			},1000);
		}); // end each
	
	},
	
	startRotation: function() {
		
		    var current = 1;
			$imgs = $(".content img"); 
			var total = $imgs.length;
			setInterval( function() {
				$imgs.filter(":visible").fadeOut(2000);				 
				$($imgs.get(current)).fadeIn(2000);
				current = (current < total - 1) ? current+1 : 0;
			},5000);
	
	}
	
}
