// A class to implement a set of alternative views.
// Only one of the options provided is visible at any given time.

// Assumptions
// core.js:function id
// core.js:function set
// core.js:has.style == true

// The constructor is given a set of id names
function ViewSet(names) {
	this.names = names;
	this.selected = names[0];
}

// Define the prototype
ViewSet.prototype = {
	// Main properties
	names: new Array(),
	selected: undefined,

	// Show the currently selected view
	current : function() {
		for ( i in this.names ) {
			// Can we find the view?
			var view = id(this.names[i]);
			if ( view ) {
				if ( this.names[i] == this.selected ) {
					set(view.style, "display", ""); // Show
				} else {
					set(view.style, "display", "none"); // Hide
				}
			}
		}
		return true;
	},
	
	// Show a particular view
	show : function(view) {
		// Is the view name valid
		var found = false;
		for ( i in this.names ) {
			if ( this.names[i] == view ) found = true;
		}
		if ( ! found ) return false;

		// Set the current value to the name they want
		this.selected = view;

		// Show it
		return this.current();
	},

	// Show the "next" view
	next : function() {
		// Find the name of the "next" view
		var next = -1;
		for ( i in this.names ) {
			if ( this.names[i] == this.selected ) {
				next = i + 1;
			}
		}

		// Check the results
		if ( next < 0 ) return false;
		if ( next >= this.names.length ) next = 0;

		// Set the current to the new value
		this.selected = this.names[next];

		// Show the new view
		return this.current();
	},

	// Show none of the views
	none : function() {
		for ( i in this.names ) {
			var view = id(this.names[i]);
			if ( view ) set(view.style, "display", "none"); // Hide
		}

		return true;
	},

	// Show all the views
	all : function() {
		for ( i in this.names ) {
			var view = id(this.names[i]);
			if ( view ) set(view.style, "display", ""); //Show
		}

		return true;
	}

	// That should just about do it
}
