/*
 * jQuery tsign rotator
 */
(function($) {
$.widget('tsign.rotator', {

	_init: function() {
		this.textBox = $("#" + this.options.textContainerId);
		this.textBoxElements = this.textBox.children();
		this.itemBox = this.element;
		this.itemBoxElements = this.itemBox.children();
		this.currentId = parseInt(this.options.start);
		var self = this;
		$(this.itemBox).children().each(function(e){
			if(e != self.currentId) {
				$(self.itemBoxElements[e]).hide();
				$(self.textBoxElements[e]).hide();
			}
		});
		
	},
	
	previous: function() {
		var item = ((this.currentId - 1) < 0) ? (this.textBoxElements.size() - 1) : this.currentId - 1;
		this.setItem(item);
	},
	
	next: function() {
		var item = ((this.currentId + 1) >= this.textBoxElements.size()) ? 0 : this.currentId + 1;
		this.setItem(item);
	},
	
	setItem: function(id) {
		var self = this;
		var id = id;
		$(this.itemBoxElements[this.currentId]).fadeOut(700, function() {
			$(self.itemBoxElements[id]).fadeIn(300);
		});
		$(this.textBoxElements[this.currentId]).fadeOut(700, function() {
			$(self.textBoxElements[id]).fadeIn(300);
		});	
		
		this.currentId = id;
		
	}
});
rotator = $.extend($.tsign.rotator, {
	version: '1.10',
	getter: 'value',
	defaults: {
		start: 0
	}
});

})(jQuery);