(function($){
	$.fn.rate = function(parms){
		$(this).each(function(){
			var _self = this;
			_self.CONFIG = {
				lShine : "l_shine",
				rShine : "r_shine",
				lGray : "l_gray",
				rGray : "r_gray",
				reAttr : "id",
				amount : 5,
				currentRate : 0,
				enableSelect : true,
				decimal : true,
				selectedCallBack:function(){},
				clickCallBack:function(){}
			};
			var len = 0;
			var cr = 0.5;
			_init = function(){
				if(_self.CONFIG.amount<0) return;
				$.extend(_self.CONFIG,parms);
				l = _self.CONFIG.amount * 2;
				if(!_self.CONFIG.decimal) cr = 1;
				for(i = 0;i < l; i++){
					if(_self.CONFIG.currentRate / cr > i){
						if(i%2 == 0){
							$(_self).append($("<span>").attr({"class":_self.CONFIG.lShine,"key":i}));
						}else{
							$(_self).append($("<span>").attr({"class":_self.CONFIG.rShine,"key":i}));
						}
					}else{
						if(i%2 == 0){
							$(_self).append($("<span>").attr({"class":_self.CONFIG.lGray,"key":i}));
						}else{
							$(_self).append($("<span>").attr({"class":_self.CONFIG.rGray,"key":i}));
						}
					}
				}
				if(_self.CONFIG.enableSelect){
					$(_self).bind("mouseover",function(event){
						_self.selected(parseInt($(event.target).attr("key")));
					}).bind("click",function(event){
						_self.CONFIG.clickCallBack((parseInt($(event.target).attr("key"))+1) * cr,$(_self).attr(_self.CONFIG.reAttr));
					}).bind("mouseout",function(event){ //ÎªÁË±ÜÃâ°ë¸öÐÇÐÇ
						if(cr==0.5)
						{
							var tmp = parseInt($(event.target).attr("key"));
							if(tmp%2 == 0)								
								_self.selected(tmp+1);
						}
					})
				}
			};
			_self.selected = function(currentRate){
				var $span = $(_self).children();
				for(i = 0;i < l; i++){
					if(currentRate >= i){
						if(i%2 == 0){
							$span.eq(i).attr("class",_self.CONFIG.lShine);
						}else{
							$span.eq(i).attr("class",_self.CONFIG.rShine);
						}
					}else{
						if(i%2 == 0){
							$span.eq(i).attr("class",_self.CONFIG.lGray);
						}else{
							$span.eq(i).attr("class",_self.CONFIG.rGray);
						}
					}
				}
				_self.CONFIG.selectedCallBack((currentRate+1) * cr,$(_self).attr(_self.CONFIG.reAttr));
			};
			_init();
		})
	}
})(jQuery)