(function($){

	$.fn.extend({

		vSlider:function(opt){

			if(opt===undefined)

				opt={}

			this.each(function(){

				var th=$(this),

					data=th.data('vSlider'),

					_={

						duration:800,

						easing:'linear',

						clone:true,

						cloneCl:'_clone',

						show:4,

						mousewheel:true,

						preFu:function(){

							if(_.me.css('position')=='static')

								_.me.css({position:'relative'})

							if(_.me.css('zIndex')=='auto')

								_.me.css({zIndex:1})								

							_.ul.css({position:'relative',zIndex:1})

							

							if(_.clone)

								_.li.clone().addClass(_.cloneCl).appendTo(_.ul),

								_.li=_.ul.children()

			

							_.ul.height((function(){

								var ret=0

								_.li.each(function(){

									var th=$(this)

									ret+=parseInt(th.css('marginTop'))+parseInt(th.css('marginBottom'))+th.outerHeight()

								})

								_.itmH=ret/_.li.length

								

								return ret

							})())

							

							_.me.css({

								overflow:'hidden',

								height:_.itmH*_.show

							})

						

							var tmp=Math.round(_.li.length/4),

								i=tmp

							while(i--)

								_.ul.find('li').eq(-1).prependTo(_.ul)

							_.ul

								.css({top:(_.sY=-~~tmp*_.itmH)})

							_.moving=false

						},

						moveFu:function(n){

							var eq=n<0?-1:0,

								itmH=n<0?-1*_.itmH:_.itmH,

								side=n<0?'prependTo':'appendTo'

							if(_.moving)

								return false

							_.moving=true

							_.li=$('>li',_.ul)

							_.li.eq(eq)

								[side](

									_.ul

										.stop()

										.css({top:parseInt(_.ul.css('top'))+itmH})

										.animate({

											top:_.sY

										},{

											duration:_.duration,

											easing:_.easing,

											complete:function(){

												_.moving=false

											}

										})

								)

						},

						nextFu:function(){

							_.moveFu(1)

						},

						prevFu:function(){

							_.moveFu(-1)

						},

						mousewheelFu:function(){

							_.me.mousewheel(function(e,data){

								if(data<0)

									_.nextFu()

								else

									_.prevFu()

								return false

							})

						},

						init:function(){

							_.me=this

							_.ul=$('>ul',_.me)

							_.li=$('>li',_.ul)

							_.preFu()

							

							if(_.mousewheel&&$.fn.mousewheel)

								_.mousewheelFu()

						}

					}

				if(!data)

					(typeof opt=='object'?$.extend(_,opt):_).init.call(th),

					th.data({vSlider:_}),

					data=_

				else

					_=typeof opt=='object'?$.extend(data,opt):data

				

				if(typeof opt=='string'&&(opt=='next'||opt=='prev'))

					_[opt+'Fu']()

					

			})

			return this

		}

	})

})(jQuery)
