
/*
	picasaViewer v1.0 - mooTools script to embed a picasa gallery in your website
	Lennart Pilon (http://pilon.nl)	


window.addEvent('domready', function() {
//picasateam
	var username	= 'ashfordjutsukai';

	
	//The following values are valid for the thumbsize and imgmax query parameters and are embeddable on a webpage. 
	//These images are available as both cropped(c) and uncropped(u) sizes by appending c or u to the size. As an 
	//example, to retrieve a 72 pixel image that is cropped, you would specify 72c, while to retrieve the uncropped 
	//image, you would specify 72u for the thumbsize or imgmax query parameter values.

	//32, 48, 64, 72, 144, 160
	
	var thumbsize	= '72c';
	
	
	//The following values are valid for the thumbsize and imgmax query parameters and are embeddable on a webpage. 
	//These images are available as only uncropped(u) sizes by appending u to the size or just passing the size 
	//value without appending anything.

	//200, 288, 320, 400, 512, 576, 640, 720, 800

	
	var imgmax = '640';
	var albumid ='5436177884429985489';
	var url = 'http://picasaweb.google.com/data/feed/base/user/'+ username +'/albumid/'+ albumid +'?category=photo&alt=json&callback=viewPhotoList&thumbsize=' + thumbsize +'&imgmax='+imgmax;
	new Element('script', {'src': url}).inject($('photo-slide'));	
	


});
 
*/

function viewPhotoList(list) {
	
	var album = list.feed.title.$t;

	list.feed.entry.each(function(item, size) {

		var title	= item.title.$t;
		var link	= item.media$group.media$content[0].url;
		size		= item.media$group.media$content[0].width;
		var thumb	= item.media$group.media$thumbnail[0].url;
		
		id_begin	= item.id.$t.indexOf('albumid/')+8;
		id_end		= item.id.$t.indexOf('?');
		var id		= item.id.$t.slice(id_begin, id_end);
		
		$('photo-slide').adopt(new Element('span').adopt(new Element('a', {'href': link, 'title': title, 'class': 'lightbox', 'rel': 'lightbox[abc]'}).adopt(new Element('img', {'src': thumb, 'alt': title}))));
		Mediabox.scanPage();
	});
	
		var i_count = Math.ceil($$('#photo-slide span').length*4)
		var i_arr = new Array (i_count );
		
		var nS1 = new noobSlide({
		box: $('photo-slide'),
		items: i_arr,
		size: 41,
		interval: 1500,
		fxOptions: {
				duration: 1500,
				transition: Fx.Transitions.linear,
				wait: false
			},
		autoPlay: true
	});
}



var noobSlide = new Class({
    
	initialize: function(params){
		this.items = params.items;
		this.mode = params.mode || 'horizontal';
		this.modes = {horizontal:['left','width'], vertical:['top','height']};
		this.size = params.size || 240;
		this.box = params.box.setStyle(this.modes[this.mode][1],(this.size*this.items.length)+'px');
		this.button_event = params.button_event || 'click';
		this.handle_event = params.handle_event || 'click';
		this.onWalk = params.onWalk || null;
		this.currentIndex = null;
		this.previousIndex = null;
		this.nextIndex = null;
		this.interval = params.interval || 5000;
		this.autoPlay = params.autoPlay || false;
		this._play = null;
		this.handles = params.handles || null;
		
		if(this.handles){
			this.addHandleButtons(this.handles);
		}
		this.buttons = {
			previous: [],
			next: [],
			play: [],
			playback: [],
			stop: []
		};
		if(params.addButtons){
			for(var action in params.addButtons){
				this.addActionButtons(action, $type(params.addButtons[action])=='array' ? params.addButtons[action] : [params.addButtons[action]]);
			}
		}
		this.fx = new Fx.Tween(this.box,$extend((params.fxOptions||{duration:500,wait:false}),{property:this.modes[this.mode][0]}));
		this.walk((params.startItem||0),true,true);
	},

	addHandleButtons: function(handles){
		for(var i=0;i<handles.length;i++){
			handles[i].addEvent(this.handle_event,this.walk.bind(this,[i,true]));
		}
	},

	addActionButtons: function(action,buttons){
		for(var i=0; i<buttons.length; i++){
			switch(action){
				case 'previous': buttons[i].addEvent(this.button_event,this.previous.bind(this,[true])); break;
				case 'next': buttons[i].addEvent(this.button_event,this.next.bind(this,[true])); break;
				case 'play': buttons[i].addEvent(this.button_event,this.play.bind(this,[this.interval,'next',false])); break;
				case 'playback': buttons[i].addEvent(this.button_event,this.play.bind(this,[this.interval,'previous',false])); break;
				case 'stop': buttons[i].addEvent(this.button_event,this.stop.bind(this)); break;
			}
			this.buttons[action].push(buttons[i]);
		}
	},

	previous: function(manual){
		this.walk((this.currentIndex>0 ? this.currentIndex-1 : this.items.length-1),manual);
	},

	next: function(manual){
		this.walk((this.currentIndex<this.items.length-1 ? this.currentIndex+1 : 0),manual);
	},

	play: function(interval,direction,wait){
		this.stop();
		if(!wait){
			this[direction](false);
		}
		this._play = this[direction].periodical(interval,this,[false]);
	},

	stop: function(){
		$clear(this._play);
	},

	walk: function(item,manual,noFx){
		if(item!=this.currentIndex){
			this.currentIndex=item;
			this.previousIndex = this.currentIndex + (this.currentIndex>0 ? -1 : this.items.length-1);
			this.nextIndex = this.currentIndex + (this.currentIndex<this.items.length-1 ? 1 : 1-this.items.length);
			if(manual){
				this.stop();
			}
			if(noFx){
				this.fx.cancel().set((this.size*-this.currentIndex)+'px');
			}else{
				this.fx.start(this.size*-this.currentIndex);
			}
			if(manual && this.autoPlay){
				this.play(this.interval,'next',true);
			}
			if(this.onWalk){
				this.onWalk((this.items[this.currentIndex] || null), (this.handles && this.handles[this.currentIndex] ? this.handles[this.currentIndex] : null));
			}
		}
	}
	
});
