// -----------------------------------------------------------------------------------
// 
// This page coded by Scott Upton
// http://www.uptonic.com | http://www.couloir.org
//
// This work is licensed under a Creative Commons License
// Attribution-ShareAlike 2.0
// http://creativecommons.org/licenses/by-sa/2.0/
//
// Associated frameworks copyright their respective owners
//
//
// REQUIRES: Mootools 1.1 or higher
//
// -----------------------------------------------------------------------------------
// --- version date: 07/30/2007 ------------------------------------------------------

// Static script ID counter
var sCounter = 1;


/* MooPix Class
------------------------------------------------------------*/
var MooPix = new Class({
    initialize: function(type, format){
		// You must supply your own API key to use Flickr Services
		this.fApiKey		= 'b9f85505f22d42d6f1e849d28024c794';
			
		// You'll probably want to leave these alone
		this.fBaseUrl		= 'http://www.flickr.com/services/';
		this.fType			= (!type)?'rest':type;
		this.fFormat		= (!format)?'json':format;
		this.fArgs			= {};
		this.scriptId		= 'mpID' + sCounter++;
    },
	setFlickrUrl: function(args){		
		// Be sure to pass api key and request format in arguments
		// Also includes a random "nocache" parameter for IE compatibility
		this.fArgs.api_key	= this.fApiKey;
	    this.fArgs.format	= this.fFormat;
		this.fArgs.nocache	= (new Date()).getTime();
			
		// Combine args in this call with those in the object instance already
		Object.extend(this.fArgs, args);
		
		// Build final, signed URL
		this.fUrl = this.fBaseUrl+this.fType+'/?'+Object.toQueryString(this.fArgs);
		
		return this.fUrl;
	},
	callFlickrUrl: function(args){
		new Asset.javascript(this.setFlickrUrl(args), {
			id: this.scriptId,
			type: 'text/javascript',
			charset: 'utf-8'
		});
	}
});