/*
Script: Transition.js
	Class for simple timebased transition of child elements
*/

var Transition = new Class({

	// Properties
	items:		undefined,
	item:		undefined,
	interval:	undefined,
	idx:		0,
	options: {
				// Options (for class initialisation)
				idParent: 'container',
				childTag: 'div',
				interval: 3000
	},

	// Initialze (at start)
	initialize: function(opt) {

		var parent = this;
		/*Object.each(opt, function(value, key){
			parent.options[key] = value;
		});*/
		if (typeof opt.idParent != 'undefined') this.options.idParent = opt.idParent;
		if (typeof opt.childTag != 'undefined') this.options.childTag = opt.childTag;
		if (typeof opt.interval != 'undefined') this.options.interval = opt.interval;

		this.items = $$(this.options.idParent + ' ' + this.options.childTag);
		this.item = this.items[this.idx];
		this.items.fade('hide');
	
		this.interval = window.setInterval(function(){
				parent.changeItem();
			}, this.options.interval);

		this.item.fade('in');
	},

	// Change active item
	changeItem: function() {
		this.item.fade('out');
		this.idx++;
		var nextItem = this.items[this.idx];
		if (typeof nextItem != 'undefined') {
			this.item = nextItem;
		}
		else {
			this.idx = 0;
			this.item = this.items[this.idx];
		}
		this.item.fade('in');
	}
});

