/*
 * jQuery ixcore rotator 1.0.1
 *
 * Copyright (c) 2009 ixcore.corp.
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * jQuery ixcore Utilities
 *
 * Depends:
 *	ixcore.rotator.js
 */
 (function($){

	$.fn.rotator = function(options){
	 return this.each(function(){
		 new Jx.Rotator(this, options).show(this);
	 });
	};

	var Jx = {};
	Jx.ImageButton = function(options){
		this.options = $.extend({}, Jx.ImageButton.defaults, options || {});
		this.init();
	};
	Jx.ImageButton.jx = '0.1';
	Jx.ImageButton.State = {
		Disabled: 'disabled',
		Out: 'out',
		Over: 'over',
		Selected: 'selected',
		Unselected: 'unselected'};

	Jx.ImageButton.defaults = {
		res: {path: '/js/jquery/resource/rotator/images/imagebutton/',
			  disabled: 'disabled.gif',
			  selected: 'selected.gif',
			  unselected: 'unselected.gif'},
		alt: '',
		css: {},
		checkOnClick: false,
		checked: false,
		unit: 'em',
		size: {width: 1.1, height: 1.1},
		state: Jx.ImageButton.State.Unselected,
		act: {click: function(){}, stateChanged: function(newState, oldState, caller){}}
	};

	$.extend(Jx.ImageButton.prototype, {
		init: function(){
			var _self = this;
			var _tabindex = (this.options.tabindex)? ' tabindex="' + this.options.tabindex + '"' : '' ;
			this.$element = $('<img src="" class="jx-imgbtn"' + _tabindex + ' alt="' + this.options.alt + '" title="' + this.options.alt + '" />');

			this.setState(this.getState(), 'init');

			if(!!_self.options.checkOnClick && !!!this.isDisabled()){
				this.setState(!!this.isChecked() ? Jx.ImageButton.State.Selected : Jx.ImageButton.State.Unselected, 'init');
			}
			this.$element.data('jx', this);
			this.$element.css({width: this.options.size.width + this.options.unit});
			this.$element.css({height: this.options.size.height + this.options.unit});
			this.$element.css(this.options.css);
			this.$element.bind('click', function(e){
				if(!!!_self.isDisabled()){
					_self.options.act.click(e);
				}
			});
			this.$element.bind('mousedown', function(e){
				if(!!!_self.isDisabled()){
					_self.setState(Jx.ImageButton.State.Selected, 'mousedown');
				}
			});
			this.$element.bind('mouseup', function(e){
				if(!!!_self.isDisabled()){
					if(!!_self.options.checkOnClick){
						_self.toggleChecked();
					}else{
						_self.setState(Jx.ImageButton.State.Unselected, 'mouseup');
					}
				}
			});
			this.$element.bind('mouseover', function(e){
				if(!!!_self.isDisabled()){
					_self.oldState = _self.getState();
					_self.setState(Jx.ImageButton.State.Over, 'mouseover');
				}
			});
			this.$element.bind('mouseout', function(e){
				if(!!!_self.isDisabled()){
					_self.setState(_self.oldState, 'mouseout');
					//if(!!_self.options.checkOnClick){
					//	_self.setState(!!_self.isChecked() ? Jx.ImageButton.State.Selected : Jx.ImageButton.State.Unselected, 'mouseout');
					//}else{
					//	_self.setState(Jx.ImageButton.State.Unselected, 'mouseout');
					//}
				}
			});
			this.$element.bind('keydown', function(e){
				if(!!!_self.isDisabled()){
					if(e.keyCode == 13 || e.which == 13){
						_self.options.act.click(e);
						e.preventDefault();
						e.stopPropagation();
					}
				}
			});
		},
		toggleChecked: function(){
			this.options.checked = !!!this.options.checked;
			this.setState(!!this.isChecked() ? Jx.ImageButton.State.Selected : Jx.ImageButton.State.Unselected, 'toggleChecked');
		},
		setChecked: function(flag){
			this.options.checked = flag;
			this.setState(this.isChecked() ? Jx.ImageButton.State.Selected : Jx.ImageButton.State.Unselected, 'setChecked');
		},
		isChecked: function(){
			return !!this.options.checked;
		},
		setDisable: function(flag){
			if(flag == true && this.isDisabled() == false){
				this.setState(Jx.ImageButton.State.Disabled, 'setdisable');
			}else if(flag == false && this.isDisabled() == true){
				this.setState(this.isChecked() ? Jx.ImageButton.State.Selected : Jx.ImageButton.State.Unselected, 'setdisable');
			}
		},
		isDisabled: function(){
			return this.getState() == Jx.ImageButton.State.Disabled;
		},
		setState: function(state, caller){
			if(!state) throw new Error('state is required.');
			if(typeof state != 'string') throw new Error('state must be string');
			var _check = false;
			for(var _prop in Jx.ImageButton.State){
				if(Jx.ImageButton.State[_prop] == state){
					_check = true;
					break;
				}
			}
			if(!!!_check)
				throw new Error('state[' + state + '] is invalid.');
			this.options.oldState = this.options.state;
			this.options.state = state;
			
			this.$element.attr('src', this.getFileName(state)).css({cursor: (state == Jx.ImageButton.State.Disabled) ? 'default' : 'pointer'});
			this.options.act.stateChanged(state, this.options.oldState, caller);

		},
		getState: function(){
			return this.options.state;
		},
		getFileExtension: function(){
			return '';
			//return '.' + Jx.getImageExtension();
		},
		getFileName: function(state){
			if(!state) throw new Error('state is required.');
			if(typeof state != 'string') throw new Error('state must be string');
			var _fname = '';
			switch(state){
				case Jx.ImageButton.State.Over:
					_fname = this.options.res[state] || this.options.res['selected'];
					break;
				case Jx.ImageButton.State.Out:
					_fname = this.options.res[state] || this.options.res['unselected'];
					break;
				default:
					_fname = this.options.res[state];
					break;
			}
			return this.options.res.path + _fname + this.getFileExtension();
		},
		show: function(container){
			if(!container) throw new Error('container is required.');
			if(typeof container != 'string') throw new Error('container must be string');
			$(container).append(this.$element);
			return this;
		},
		appendTo: function(o){
			if(!o) throw new Error('arguments[0] is required.');
			if(typeof o == 'string') o = $(o);
			if(o.jquery){
				this.$element.appendTo(o);
			}else if(o.jx){
				this.$element.appendTo(o.$element);
			}
		}
	});

	/*
		Rotator Object Defined
	 */
	Jx.Rotator = function(items, options){
		this.options = $.extend({}, Jx.Rotator.defaults, options || {});
		this.currentNumber = this.options.startNumber || 1; // start one base
		this.tabindex = this.options.tabIndex || 9000;
		this.extractItems(items);
		this.init();
	};
	Jx.Rotator.jx = '0.3';
	Jx.Rotator.State = {
		Play: 'play',
		Stop: 'stop'};

	Jx.Rotator.defaults = {
		res: {path: '/js/jquery/resource/rotator/images/rotator/'},
		unit: 'em',
		css: {},
		interval: 3000,
		startNumber: 1, // start one base
		cmdIconSize: {width: 1.1, height: 1.1, margin: 0.1},
		state: Jx.Rotator.State.Stop,
		commands: {pos1: 'top', pos2: 'left'},
		numbers: {pos1: 'top', pos2: 'right'},
		effect: {mode: 'fade', speed: 'normal'},
		showcase: {width: 19.1, height: 18.1, margin: 0.1},
		rows: 1,
		cols: 1,
		correction: 0
	};

	$.extend(Jx.Rotator.prototype, {
		init: function(){
			var _self = this;
			this.setCommands();
			this.setNumbers();
			this.setLayout();
			this.appendEvent();
			this.$element.css(this.options.css);
			this.$element.data('jx', this);
		},
		extractTabindex: function(){
			var _self = this;
			this.$items.each(function(){
				$('[tabindex]', $(this)).each(function(i, e){ 
					var _ti = parseInt($(this).attr('tabindex')); 
					if(!isNaN(_ti)){_self.tabindex = Math.min((_ti < 1) ? _self.tabindex : _ti, _self.tabindex);} });
			});
		},
		extractItems: function(ele){
			if(!ele) throw new Error('ele is required.');
			//if(typeof ele != 'string') throw new Error('ele must be string');
			var _self = this;
			// start zero base
			this.$items = $('a:has(img)', $(ele)).wrap('<div class="jx-rotator-item"></div>').parent();
			this.$items.css({width: this.options.showcase.width + this.options.unit,
							 height: this.options.showcase.height + this.options.unit,
							 margin: this.options.showcase.margin + this.options.unit});

			this.extractTabindex();
	 
			this.itemGroup = [];
			var _$temp = $('<div></div>');
			this.$items.each(function(i, e){
				if(i == 0) {
					_$temp.empty().append('<div class="jx-rotator-item-group"></div>');
				}else if((i % (_self.options.rows * _self.options.cols)) == 0) {
					_self.itemGroup.push($(_$temp.html()));
					_$temp.empty().append('<div class="jx-rotator-item-group"></div>');
				}
				$('.jx-rotator-item-group', _$temp).append($(this));
				if(i == _self.$items.length -1) {
					for(var _i = (_self.options.rows * _self.options.cols) - _self.getRemain(); _i > 0 ; _i--){
						var _$html = $(_self.options.emptyHtml || '<div class="jx-rotator-item"></div>');
						_$html.css({width: _self.options.showcase.width + _self.options.unit,
									height: _self.options.showcase.height + _self.options.unit,
									margin: _self.options.showcase.margin + _self.options.unit});
						$('.jx-rotator-item-group', _$temp).append(_$html);
					}
					_self.itemGroup.push($(_$temp.html()));
				}

			});

		},
		getHeightStep: function(){
			return (this.options.showcase.height + (this.options.showcase.margin * 2)) + this.options.unit;
		},
		getWidthStep: function(){
			return (this.options.showcase.width + (this.options.showcase.margin * 2)) + this.options.unit;
		},
		getLimit: function(){
			return Math.ceil(this.$items.length / (this.options.rows * this.options.cols));
		},
		getRemain: function(){
			return this.$items.length % (this.options.rows * this.options.cols);
		},
		setNumbers: function(){
			var _self = this;
			var _limit = this.getLimit();
			this.numbers = []; // start zero base
			for(var _i = 0; _i < _limit; _i++){
				this.numbers.push(new Jx.ImageButton({
				res: {path: this.options.res.path,
					  disabled: 'num' + (_i+1) + '_disabled.gif',
					  selected: 'num' + (_i+1) + '_selected.gif',
					  unselected: 'num' + (_i+1) + '_unselected.gif'},
				css: {margin: '1px'},
				tabindex: this.tabindex,
				checkOnClick: false,
				checked: false,
				size: this.options.cmdIconSize,
				state: Jx.ImageButton.State.Unselected,
				act: {click: _func(_i + 1),
					  stateChanged: function(newState, oldState, caller){}}
				}));
			}
			function _func(n){
				return function(){ var _temp = _self.options.state; _self.stop(); _self.options.state = _temp; _self.moveTo(n);};
			}
		},
		appendNumbers: function(jquery){
			for(var _i=0; _i<this.numbers.length; _i++){
				this.numbers[_i].appendTo(jquery);
			}
		},
		setCommands: function(){
			var _self = this;
			this.btnPlay = new Jx.ImageButton({
				res: {path: this.options.res.path,
					  disabled: 'play_disabled.gif',
					  selected: 'play_selected.gif',
					  unselected: 'play_unselected.gif'},
				alt: 'play',
				css: {margin: '1px'},
				tabindex: this.tabindex,
				checkOnClick: true,
				checked: true,
				size: this.options.cmdIconSize,
				state: Jx.ImageButton.State.Selected,
				act: {click: function(e){ if(_self.options.state != Jx.Rotator.State.Play){ _self.play(); } },
					  stateChanged: function(newState, oldState, caller){}}
			});
			this.btnStop = new Jx.ImageButton({
				res: {path: this.options.res.path,
					  disabled: 'stop_disabled.gif',
					  selected: 'stop_selected.gif',
					  unselected: 'stop_unselected.gif'},
				alt: 'stop',
				css: {margin: '1px'},
				tabindex: this.tabindex,
				checkOnClick: true,
				checked: true,
				size: this.options.cmdIconSize,
				state: Jx.ImageButton.State.Unselected,
				act: {click: function(e){ if(_self.options.state != Jx.Rotator.State.Stop){ _self.stop(); } },
					  stateChanged: function(newState, oldState, caller){ /*if(caller == 'init' alert(newState + ':' + caller);)*/}}
			});
			this.btnPrev = new Jx.ImageButton({
				res: {path: this.options.res.path,
					  disabled: 'prev_disabled.gif',
					  selected: 'prev_selected.gif',
					  unselected: 'prev_unselected.gif'},
				alt: 'prev',
				css: {margin: '1px'},
				tabindex: this.tabindex,
				checkOnClick: false,
				checked: false,
				size: this.options.cmdIconSize,
				state: Jx.ImageButton.State.Unselected,
				act: {click: function(e){ _self.prev(); },
					  stateChanged: function(newState, oldState, caller){}}
			});
			this.btnNext = new Jx.ImageButton({
				res: {path: this.options.res.path,
					  disabled: 'next_disabled.gif',
					  selected: 'next_selected.gif',
					  unselected: 'next_unselected.gif'},
				alt: 'next',
				css: {margin: '1px'},
				tabindex: this.tabindex,
				checkOnClick: false,
				checked: false,
				size: this.options.cmdIconSize,
				state: Jx.ImageButton.State.Unselected,
				act: {click: function(e){ _self.next(); },
					  stateChanged: function(newState, oldState, caller){}}
			});
		},
		appendCommands: function(jquery){
			this.btnPrev.appendTo(jquery);
			this.btnPlay.appendTo(jquery);
			this.btnStop.appendTo(jquery);
			this.btnNext.appendTo(jquery);
		},
		appendEvent: function(){
			var _self = this;
			this.$displayPanel.bind('mouseover', function(e){
				_self.stateCache = _self.options.state;
				_self.stop();
			});
			this.$displayPanel.bind('mouseout', function(e){
				if(_self.stateCache == Jx.Rotator.State.Play){
					_self.play();
				}
				_self.stateCeche = '';
			});
		},
		setLayout: function(){
			this.$element = $('<div class="jx-rotator" ></div>');
			var _cmdPos1 = this.options.commands.pos1, _cmdPos2 = this.options.commands.pos2;
			var _numPos1 = this.options.numbers.pos1, _numPos2 = this.options.numbers.pos2;

			var _btnWidth = this.options.cmdIconSize.width + (this.options.cmdIconSize.margin * 2);
			var _btnHeight = this.options.cmdIconSize.height + (this.options.cmdIconSize.margin * 2);
			var _scWidth = (this.options.showcase.width + (this.options.showcase.margin * 2)) * this.options.cols + this.options.correction;
			var _scHeight = (this.options.showcase.height + (this.options.showcase.margin * 2)) * this.options.rows;
			var _width = _scWidth, _height = _scHeight;
			var _bodyWidth = _scWidth, _bodyHeight = _scHeight;

			if(_cmdPos1 == 'top' || _numPos1 == 'top')_height += _btnHeight;
			if(_cmdPos1 == 'left' || _numPos1 == 'left'){_width += _btnWidth; _bodyWidth += _btnWidth;}
			if(_cmdPos1 == 'right' || _numPos1 == 'right'){_width += _btnWidth; _bodyWidth += _btnWidth;}
			if(_cmdPos1 == 'bottom' || _numPos1 == 'bottom')_height += _btnHeight;

			this.$element.css({width: _width + this.options.unit,
							   height: _height + this.options.unit});

			// top
			if(_cmdPos1 == 'top' || _numPos1 == 'top'){
				this.$topCtrlPanel = $('<div class="jx-rotator-control-panel jx-rotator-control-panel-top"></div>');
				this.$topCtrlPanel.css({width: _width + this.options.unit,
										height: _btnHeight + this.options.unit});

				this.$element.append(this.$topCtrlPanel);
				if((_cmdPos1 == 'top' && _cmdPos2 == 'left') || (_numPos1 == 'top' && _numPos2 == 'left')){
					this.$topCtrlPanel.append('<div class="jx-rotator-control-subpanel jx-rotator-control-subpanel-left"></div>');
					if((_cmdPos1 == 'top' && _cmdPos2 == 'left')){
						this.appendCommands($('.jx-rotator-control-subpanel-left', this.$topCtrlPanel));
					}
					if((_numPos1 == 'top' && _numPos2 == 'left')){
						this.appendNumbers($('.jx-rotator-control-subpanel-left', this.$topCtrlPanel));
					}
				}
				if((_cmdPos1 == 'top' && _cmdPos2 == 'right') || (_numPos1 == 'top' && _numPos2 == 'right')){
					this.$topCtrlPanel.append('<div class="jx-rotator-control-subpanel jx-rotator-control-subpanel-right"></div>');
					if((_cmdPos1 == 'top' && _cmdPos2 == 'right')){
						this.appendCommands($('.jx-rotator-control-subpanel-right', this.$topCtrlPanel));
					}
					if((_numPos1 == 'top' && _numPos2 == 'right')){
						this.appendNumbers($('.jx-rotator-control-subpanel-right', this.$topCtrlPanel));
					}
				}
			}

			// body
			this.$bodyPanel = $('<div class="jx-rotator-body"></div>');
			this.$element.append(this.$bodyPanel);
			// left
			if(_cmdPos1 == 'left' || _numPos1 == 'left'){
				this.$leftCtrlPanel = $('<div class="jx-rotator-control-panel jx-rotator-control-panel-left"></div>');
				this.$leftCtrlPanel.css({width: _btnWidth + this.options.unit,
										 height: _scHeight + this.options.unit});
				this.$bodyPanel.append(this.$leftCtrlPanel);
				if((_cmdPos1 == 'left' && _cmdPos2 == 'top') || (_numPos1 == 'left' && _numPos2 == 'top')){
					this.$leftCtrlPanel.append('<div class="jx-rotator-control-subpanel jx-rotator-control-subpanel-top"></div>');
					if((_cmdPos1 == 'left' && _cmdPos2 == 'top')){
						this.appendCommands($('.jx-rotator-control-subpanel-top', this.$leftCtrlPanel));
					}
					if((_numPos1 == 'left' && _numPos2 == 'top')){
						this.appendNumbers($('.jx-rotator-control-subpanel-top', this.$leftCtrlPanel));
					}
				}
				if((_cmdPos1 == 'left' && _cmdPos2 == 'bottom') || (_numPos1 == 'left' && _numPos2 == 'bottom')){
					this.$leftCtrlPanel.append('<div class="jx-rotator-control-subpanel jx-rotator-control-subpanel-bottom"></div>');
					if((_cmdPos1 == 'left' && _cmdPos2 == 'bottom')){
						this.appendCommands($('.jx-rotator-control-subpanel-bottom', this.$leftCtrlPanel));
					}
					if((_numPos1 == 'left' && _numPos2 == 'bottom')){
						this.appendNumbers($('.jx-rotator-control-subpanel-bottom', this.$leftCtrlPanel));
					}
				}
			}

			this.$actionPanel = $('<div class="jx-rotator-body-action"></div>');
			this.$bodyPanel.append(this.$actionPanel);
			this.$displayPanel = $('<div class="jx-rotator-body-action-display"></div>');
			this.$actionPanel.append(this.$displayPanel);

			this.$actionPanel.css({width: _scWidth + this.options.unit,
								   height: _scHeight + this.options.unit});
			this.$displayPanel.css({width: _scWidth + this.options.unit});


			// right
			if(_cmdPos1 == 'right' || _numPos1 == 'right'){
				this.$rightCtrlPanel = $('<div class="jx-rotator-control-panel jx-rotator-control-panel-right"></div>');
				this.$rightCtrlPanel.css({width: _btnWidth + this.options.unit,
										  height: _scHeight + this.options.unit});
				this.$bodyPanel.append(this.$rightCtrlPanel);
				if((_cmdPos1 == 'right' && _cmdPos2 == 'top') || (_numPos1 == 'right' && _numPos2 == 'top')){
					this.$rightCtrlPanel.append('<div class="jx-rotator-control-subpanel jx-rotator-control-subpanel-top"></div>');
					if((_cmdPos1 == 'right' && _cmdPos2 == 'top')){
						this.appendCommands($('.jx-rotator-control-subpanel-top', this.$rightCtrlPanel));
					}
					if((_numPos1 == 'right' && _numPos2 == 'top')){
						this.appendNumbers($('.jx-rotator-control-subpanel-top', this.$rightCtrlPanel));
					}
				}
				if((_cmdPos1 == 'right' && _cmdPos2 == 'bottom') || (_numPos1 == 'right' && _numPos2 == 'bottom')){
					this.$rightCtrlPanel.append('<div class="jx-rotator-control-subpanel jx-rotator-control-subpanel-bottom"></div>');
					if((_cmdPos1 == 'right' && _cmdPos2 == 'bottom')){
						this.appendCommands($('.jx-rotator-control-subpanel-bottom', this.$rightCtrlPanel));
					}
					if((_numPos1 == 'right' && _numPos2 == 'bottom')){
						this.appendNumbers($('.jx-rotator-control-subpanel-bottom', this.$rightCtrlPanel));
					}
				}
			}
			this.$bodyPanel.css({width: _bodyWidth + this.options.unit,
								 height: _bodyHeight + this.options.unit});

			// bottom
			if(_cmdPos1 == 'bottom' || _numPos1 == 'bottom'){
				this.$bottomCtrlPanel = $('<div class="jx-rotator-control-panel jx-rotator-control-panel-bottom"></div>');
				this.$bottomCtrlPanel.css({width: _width + this.options.unit,
										   height: _btnHeight + this.options.unit});
				this.$element.append(this.$bottomCtrlPanel);
				if((_cmdPos1 == 'bottom' && _cmdPos2 == 'left') || (_numPos1 == 'bottom' && _numPos2 == 'left')){
					this.$bottomCtrlPanel.append('<div class="jx-rotator-control-subpanel jx-rotator-control-subpanel-left"></div>');
					if((_cmdPos1 == 'bottom' && _cmdPos2 == 'left')){
						this.appendCommands($('.jx-rotator-control-subpanel-left', this.$bottomCtrlPanel));
					}
					if((_numPos1 == 'bottom' && _numPos2 == 'left')){
						this.appendNumbers($('.jx-rotator-control-subpanel-left', this.$bottomCtrlPanel));
					}
				}
				if((_cmdPos1 == 'bottom' && _cmdPos2 == 'right') || (_numPos1 == 'bottom' && _numPos2 == 'right')){
					this.$bottomCtrlPanel.append('<div class="jx-rotator-control-subpanel jx-rotator-control-subpanel-right"></div>');
					if((_cmdPos1 == 'bottom' && _cmdPos2 == 'right')){
						this.appendCommands($('.jx-rotator-control-subpanel-right', this.$bottomCtrlPanel));
					}
					if((_numPos1 == 'bottom' && _numPos2 == 'right')){
						this.appendNumbers($('.jx-rotator-control-subpanel-right', this.$bottomCtrlPanel));
					}
				}
			}

		},
		display: function(n){
			if(this.itemGroup.length < 1) return;
			if(!n) n = this.currentNumber; // start one base
			if(n <= 0 || n > this.itemGroup.length)n = 1;
			this.$displayPanel.empty().append(this.itemGroup[n-1]);
			for(var _i=0; _i<this.numbers.length; _i++){
				this.numbers[_i].setState(Jx.ImageButton.State.Unselected);
			}
			this.numbers[n-1].setState(Jx.ImageButton.State.Selected);
			this.currentNumber = n;
			
		},
		show: function(container){
			if(!container) throw new Error('container is required.');
			//if(typeof container != 'string') throw new Error('container must be string');
			this.display(); this.$displayPanel.show();
			$(container).empty().append(this.$element);
			if(this.options.state == Jx.Rotator.State.Play){
				this.play();
			}else{
				this.stop();
			}
			return this;
		},
		fadeTo: function(n){
			if(this.itemGroup.length < 1) return;
			if(n == undefined || n.constructor != Number) n = (this.currentNumber + 1);
			if(n < 1) n = 5;
			else if(n > this.itemGroup.length) n = 1;
			if(n > 0 && n <= this.itemGroup.length){
				var _self = this;
				this.$displayPanel.fadeOut(this.options.effect.speed, function(){
					_self.display(n);
				});
				this.$displayPanel.fadeIn(this.options.effect.speed, function(){
					if(_self.options.state == Jx.Rotator.State.Play){
						_self.play();
					}else{
						_self.stop();
					}
				});
			}
		},
		slideLeft: function(n){
		},
		moveTo: function(n){
			switch(this.options.effect.mode){
				case 'fade':
					this.fadeTo(n);
					break;
			}
		},
		play: function(){
			var _self = this;
			_self.options.state = Jx.Rotator.State.Play;
			this.btnPlay.setDisable(true);
			this.btnStop.setDisable(false);
			this.timer = window.setTimeout(function(){_self.moveTo(_self.currentNumber + 1);}, this.options.interval);
		},
		stop: function(){
			var _self = this;
			_self.options.state = Jx.Rotator.State.Stop;
			this.btnPlay.setDisable(false);
			this.btnStop.setDisable(true);
			window.clearTimeout(this.timer);
			this.timer = null;
		},
		prev: function(){
			this.stop();
			this.moveTo(this.currentNumber - 1);
		},
		next: function(){
			this.stop();
			this.moveTo(this.currentNumber + 1);
		},
		go: function(n){
			this.stop();
			this.moveTo(n);
		} 
	});


 })(jQuery);