(function($){
	$.fn.gSlider=function(o){
			this.each(function(){
				var th=$(this),
					data=th.data('gSlider'),
					_={
						duration:800,
						easing:'linear',
						clone:true,
						cloneCl:'_clone',
						show:4,
						step:1,
						mouseWheel:false,
						wInt:50,
						mouseWheelFu:function(){
							if(!_.mouseWheel)
								return false
							_.me
								.mousewheel(function(d,w){
									if(_.moving)
										return false
									w<0
										?_.nextFu(_.bl=true)
										:_.prevFu(_.bl=true)
									return false
								})
						},
						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})
							
							_.ul.width((function(){
								var ret=0
								_.li.each(function(){
									var th=$(this)
									ret+=parseInt(th.css('marginLeft'))+parseInt(th.css('marginRight'))+th.outerWidth()
								})
								_.itmW=ret/_.li.length
								return _.clone?ret*2:ret
							})())
							
							_.me.width(_.itmW*_.show)
							
							if(_.clone)
								_.li.clone().addClass(_.cloneCl).appendTo(_.ul),
								_.li=_.ul.children()
							
							var tmp=Math.round(_.li.length/4),
								i=tmp
							while(i--)
								_.ul.find('li').eq(-1).prependTo(_.ul)
							_.ul
								.css({left:(_.sX=-~~tmp*_.itmW)})
							
							_.moving=false
						},
						moveFu:function(n){
							var eq=n<0?-1*_.step:0,
								itmW=n<0?-1*_.itmW:_.itmW,
								side=n<0?'prependTo':'appendTo'
							if(_.moving)
								return false
							_.moving=true
							_.li=$('>li',_.ul)
							_.li.slice(eq,eq<0?undefined:_.step)
								[side](
									_.ul
										.stop()
										.css({left:parseInt(_.ul.css('left'))+itmW*_.step})
										.animate({
											left:_.sX
										},{
											duration:_.duration,
											easing:_.easing,
											complete:function(){
												_.moving=false
											}
										})
								)
						},
						nextFu:function(){
							_.moveFu(1)
						},
						prevFu:function(){
							_.moveFu(-1)
						},
						init:function(){
							_.ul=$('>ul',_.me)
							_.li=$('>li',_.ul)
							_.preFu()
							_.mouseWheelFu()
						}
					}
				data?_=data:th.data({gSlider:_})
				typeof o=='object'&&$.extend(_,o)
				_.me||_.init(_.me=th)
				
				typeof o=='string'&&(o=='prev'||o=='next')&&_[o+'Fu']()
			})
			return this
		}		
})(jQuery)
