// -----------------------------------------------------------------------------------
// 
// 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: 06/10/2007 ------------------------------------------------------


/* MooPix Class
------------------------------------------------------------*/

var MooPix = new Class({
    initialize: function(type, format){
		// You must supply your own API key to use Flickr Services
		this.fApiKey		= '92437448ff6c6cf6e8bfee2549fdee63';
		
		// 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			= {};
    },
	setFlickrUrl: function(args){
		// Be sure to pass api key and request format in arguments
		this.fArgs.api_key = this.fApiKey;
	    this.fArgs.format = this.fFormat;
	
		// Combine args in this call with those in the object instance already
		$extend(this.fArgs, args);
		
		// Build final, signed URL
		this.fUrl = this.fBaseUrl+this.fType+'/?'+Hash.toQueryString(this.fArgs);
		return this.fUrl;
	},
	callFlickrUrl: function(args){
		// The following code seems problematic on IE, the inserted script tag is not getting evaluated
		//var script = new Element('script');
		//script.setProperties({type: 'text/javascript', src: this.setFlickrUrl(args)});
		//script.injectInside(document.getElement('head'));
		
		// New code to get Flickr data via an Ajax JSON call, do this via a local proxy
		// (ajaxproxy.php) as XMLHttpRequest fails on remote hosts in Firefox.
		var proxyurl = document.location.protocol + '\/\/' + document.location.host + '\/includes\/ajaxproxy.php?';
		var jsonRequest = new Request.JSON({url: proxyurl, 
					onComplete: function(json, text){
						if(json == null) eval(text);
					} });
		jsonRequest.get({'ajax': this.setFlickrUrl(args)});
	}
});
