/* 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
		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){
		// Create script element and append to DOM
		var script = new Element('script');
		script.setProperties({type: 'text/javascript', src: this.setFlickrUrl(args)});
		script.injectInside($E('head'));
	}
});

var ShowPix = new Class({
	initialize: function(rsp){
		this.photoNum	= rsp.photos.photo.length;
		this.photoInfo	= {};
		this.rsp 		= rsp;
		this.imagenes   = '';
		// Loop through to build object with each photo's info
		for (var i=0; i<this.photoNum; i++){
			this.photoInfo[i] = {
				'id': rsp.photos.photo[i].id,
				'owner': rsp.photos.photo[i].owner,
				'src': 'http://static.flickr.com/'+rsp.photos.photo[i].server+'/'+rsp.photos.photo[i].id+'_'+rsp.photos.photo[i].secret+'_m.jpg',
				'src_max': 'http://static.flickr.com/'+rsp.photos.photo[i].server+'/'+rsp.photos.photo[i].id+'_'+rsp.photos.photo[i].secret+'.jpg',
				'title': rsp.photos.photo[i].title
			}
			this.imagenes = this.imagenes + '<li><div align="center"><span id="captionflickr"><a target="_blank" href="http://www.flickr.com/photos/bancoguayaquil/'+ rsp.photos.photo[i].id +'" title="<b>'+ this.photoInfo[i].title +'</b>" class="highslide" >'+ this.photoInfo[i].title +'</a></span></div><a target="_blank" href="http://www.flickr.com/photos/bancoguayaquil/'+ rsp.photos.photo[i].id +'" title="<b>'+ this.photoInfo[i].title +'</b>" class="highslide"><img src="'+ this.photoInfo[i].src +'" alt="'+ this.photoInfo[i].title +'" width="180" /></a><br /></li>';		  
		}
		//agrego el contenedor higllide para las ampliaciones de imagen
		//this.imagenes = this.imagenes + '<div id="controlbar" class="highslide-overlay controlbar"><a href="#" class="previous" onclick="return hs.previous(this)" title="Previous (left arrow key)"></a><a href="#" class="next" onclick="return hs.next(this)" title="Next (right arrow key)"></a><a href="#" class="highslide-move" onclick="return false" title="Click and drag to move"></a><a href="#" class="close" onclick="return hs.close(this)" title="Close"></a></div>';
	    this.imagenes = this.imagenes + '<div id="controlbar" class="highslide-overlay controlbar"><a href="#" class="highslide-move" onclick="return false" title="Click and drag to move"></a><a href="#" class="close" onclick="return hs.close(this)" title="Close"></a></div>';

		$('carousel').setHTML(this.imagenes)
	}
});

function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}