/*
Additional JavaScript functions UVSV
Author: Jeroen Dijkstra, Connectholland BV (13/01/09)
*/

/** 
 * Get a random images from the UVSV Flickr account
 * and adds it to the body background
 *
 * @revision $Revision$
 * @since Fri Mar 2009
 * @author Leonard Visser
 **/
var flickrBackground = {
	/**
	* run
	*
	* Gets the images from the Flickr account
	* 
	* @since Fri Mar 2009
	* @access public
	* @return flickrresponse
	**/
	run: function(){
		new Ajax.FlickrRequest("flickr.photosets.getPhotos", {
			parameters:{
				photoset_id: "72157613623548485",
				format: "json",
				api_key: "106a21dd2ec9587689e16aa6912b3db8",
				per_page: "100",
				page: "1",
				extras: "original_format"
			},
			onResponse: this.flickrresponse
		});
	},

	/**
	* flickrresponse
	*
	* Transfroms the response into the background image
	* 
	* @since Fri Mar 2009
	* @access public
 	* @param flickrresponse response
	* @return void
	**/
	flickrresponse: function(response){
		response.photoset.photo.sort(function() {return 0.5 - Math.random();});
		var backgrndUrl = "url('http://farm" + response.photoset.photo[0].farm + ".static.flickr.com/" + response.photoset.photo[0].server + "/" + response.photoset.photo[0].id + "_" + response.photoset.photo[0].originalsecret + "_o." + response.photoset.photo[0].originalformat + "')";
		$$('body')[0].setStyle({background: '#FFFFFF ' + backgrndUrl + ' fixed center'});
	}
}
