// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function toggle_images()
{
	$('project_media', 'project_details').invoke('toggle');
	Element.removeClassName('back_toggle', 'active');
	Element.addClassName('image_toggle', 'active');
}

function toggle_details()
{
	$('project_media', 'project_details').invoke('toggle');
	Element.removeClassName('image_toggle', 'active');
	Element.addClassName('back_toggle', 'active');
}

ImageViewer = Class.create();
ImageViewer.prototype = {
	initialize: function(ids) {
		this.ids = ids;
		this.total = ids.length;
		this.loaded = 3;
		this.counter = 1;
		this.current = this.ids[this.counter - 1];
	},
	
	next: function() {
		if (this.counter + 1 > this.total) return false;
		this.update(this.counter + 1);
		this.buffer_image();
	},
	
	prev: function() {
		if (this.counter - 1 <= 0) return false;
		this.update(this.counter - 1);
	},
	
	update: function(new_value) {
		Element.hide('image_'+this.current);
		this.counter = new_value;
		this.current = this.ids[this.counter - 1];
		Element.update('current_image', this.counter.toString());
		Element.show('image_'+this.current);
	},
	
	buffer_image: function() {
		if (this.loaded >= this.total) return false;
		new Ajax.Request('/images/show/'+ this.ids[this.loaded], {
			asynchronous: true
		})
		this.loaded++;
	}	
}