Uize.module ({name: 'ROLF'});

Uize.module ({
	name:'ROLF.Slideshow',
	superclass: 'Uize.Widget.SlideShow',
	builder:function (_superclass) {
		
		/*** Class Constructor ***/
			var _class = _superclass.subclass (
					null,
					function () {
						var _this = this,
							controls = this.getNode('index');
						controls.innerHTML = '';

						for (var id = 0, len = this.get('totalSlides'); id < len; ++ id) {
							var newNode = document.createElement('a');
							controls.appendChild(newNode);
							newNode.id = controls.id + id;
							newNode.href="javascript://";
							newNode.innerHTML = (id+1) + '';
							if (id === 0) { newNode.className = 'selected'; }
						}

					    this.wireNode(controls, 'click', function(e) {
						    var target = e.target || e.srcElement;
						    if (target && target.id) {
							    var i = parseInt(target.id.substr(controls.id.length));
							    if(!isNaN(i)) {
								    _this._isAutoShowing = false;
								    if (i !== _this.get('slideNo')) {
										_this._toggleSlides(i);
								    }
							    }
						    }
					    });

						this.updateUi ();
					}
				),
				_classPrototype = _class.prototype
			;

		/*** Private Instance Methods ***/
			_classPrototype._toggleSlides = function (newSlideNo) {
				this.getNode('index' + this.get('slideNo')).className = '';
			    this.getNode('index' + newSlideNo).className = 'selected';
				this.set('slideNo', newSlideNo);
			};

		/*** Public Instance Methods ***/
			_classPrototype.autoShow = function (isStart) {
				var _this = this;
				if (!_this._isAutoShowing) { return }
				if (isStart) {
					_this.getNode('index' + this.get('slideNo')).className = 'selected';
				} else {
					_this._toggleSlides((_this.get('slideNo') + 1) % _this.get('totalSlides'));
				}
				setTimeout(function() {_this.autoShow()}, _this._interval * 1000);
			};

		/*** Register Properties ***/

			_class.registerProperties ({
				_isAutoShowing: {
					name: 'isAutoShowing',
					value: true
				},
				_interval: 'interval'
			});

		return _class;
	}
});


