// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var JSPhoto = {
	show: function(url) {
		$('photo').src = url;
		$('mask').show();
		$('photo-wrapper').visualEffect('appear', {duration:0.5});
	},
	
	hide: function() {
		$('mask').hide();
		$('photo-wrapper').visualEffect('fade', {duration:0.5});
		$('photo').src = "";
	},
	
	currentIndex: function() {
		return this.urls().indexOf($('photo').src);
	},
	
	prev: function() {
		if(this.urls()[this.currentIndex()-1]) {
			this.show(this.urls()[this.currentIndex()-1])
		}
	},
	
	next: function() {
		if(this.urls()[this.currentIndex()+1]) {
			this.show(this.urls()[this.currentIndex()+1])
		}
	},
	
	urls: function() {
		if (!this.cached_urls) {
			this.cashed_urls = $$('a.show').collect(function(el) {
				var onclick = el.onclick.toString();
				return onclcik.match(/".*"/g)[0].replace(/"/g, '');
			});
		}
		return this.cached_urls
	}
}