/*
author:radys
website: http://www.radys.cn
date: 2009-6-2 16:06
plugins name: rady.ui.slide
version v3.0
*/
if(typeof rady === 'undefined')
    var rady = window.rady = {};
if(typeof rady.ui === 'undefined')
    rady.ui = {};
(function($) {
    rady.ui.slide = function(options) {
        this.opts = $.extend({}, rady.ui.slide.defaults, options);

        this._container = this.opts.itemContain;
		this._showContain = this.opts.showContain;
        this._containsize = this.opts.containSize;
        this._left = this.opts.leftMove;
        this._right = this.opts.rightMove;

		this._itemCount =0;
		this._index =0;
        this._init();		
    };

    rady.ui.slide.prototype = {
        _init: function() {
            var $this = this;
			$this._itemCount = $($this._container).length;
            $this._showContain  = $($this.opts.showContain);
			$this._bindEvent();
			$this._showItems();
        },
		_bindEvent:function(){
		   	var $this = this;
			$($this._left).bind("click", function() {
                $this._moveLeft();
            });
            $($this._right).bind("click", function() {
                $this._moveRight();
            });
		},
        _moveLeft: function() {
            var $this = this;
			if($this._index >= 0)
			{$this._index-=1;}
			else
			{$this._index=11;}
			$this._showItems();
        },		
        _moveRight: function() {
            var $this = this;
            if($this._index <= $this._itemCount)
			{$this._index+=1;}
			else
			{$this._index=0;}
            $this._showItems();
        } ,
		_showItems:function(){
		  var $this = this;
		  $this._showContain.empty();
			for(i=$this._index;i<$this._index+$this._containsize;i++)
			{
			    $this._showContain.append($($this._container).eq(i>9?i%9:i).clone());
			}
		}
    };

    //设计选项默认值
    rady.ui.slide.defaults = {
		showContain:"#thumblist",
        itemContain: ".thumblist a",
        containSize: 4, //盒子大小
        leftMove: "#leftarrow",
        rightMove: "#rightarrow"
    };
})(jQuery)
