/**
 * class	SILO_MiniGallery
 * author	Paul Kruijt
 */
var SILO_MiniGallery = new Class({
	
	/**
	 * initialize
	 * @param	string	root_node_id
	 * @return	void
	 */
	initialize: function(root_node_id)
	{
		// nodes
		this.document_node	= document.getElement('body');
		this.root_node		= $(root_node_id);
		
		// classes
		this.arrow_left_class	= 'arrow_left';
		this.arrow_right_class	= 'arrow_right';
	},
	
	/**
	 * start
	 * @return	void
	 */
	start: function()
	{
		if (this.root_node)
		{
			this.image_nodes		= this.root_node.getElements('a');
			this.total_image_nodes	= this.image_nodes.length;
			
			if (this.total_image_nodes > 0)
			{
				// set first image as active
				this.active_image_node = this.image_nodes[0];
				this.active_image_node.setStyle('display', 'block');
				
				// set events
				this.setEvents();
			}
		}
	},
	
	/**
	 * set events
	 * @return	void
	 */
	setEvents: function()
	{
		var _this				= this;
		var arrow_left_node		= this.root_node.getElement('.'+this.arrow_left_class);
		var arrow_right_node	= this.root_node.getElement('.'+this.arrow_right_class);
		
		if (arrow_left_node)
		{
			arrow_left_node.removeEvents();
			arrow_left_node.addEvents(
			{
				'click' : function()
				{
					_this.showImage(1);
				}
			});
		}
		
		if (arrow_right_node)
		{
			arrow_right_node.removeEvents();
			arrow_right_node.addEvents(
			{
				'click' : function()
				{
					_this.showImage(2);
				}
			});
		}
	},
	
	/**
	 * show image
	 * @param	integer	nav_type
	 * @return	void
	 */
	showImage: function(nav_type)
	{
		// left
		if (nav_type == 1)
		{
			var next_image = this.active_image_node.getPrevious('a');
			
			if (!next_image) next_image = this.image_nodes[this.total_image_nodes - 1];
		}
		
		// right
		else if (nav_type == 2)
		{
			var next_image = this.active_image_node.getNext('a');
			
			if (!next_image) next_image = this.image_nodes[0];
		}
		
		if (next_image)
		{
			this.active_image_node.setStyle('display', 'none');
			next_image.setStyle('display', 'block');
			
			this.active_image_node = next_image;
		}
	}
});
