(function($){
	$.fn.rating = function( Conf ){

		var selected = 0;
		var options = {'default': 0, zeroStarsHl: false};
		$.extend( options, Conf );

		function starHover()
		{
			if ( options.zeroStarsHl && selected ) {
				return;
			}
			else {
				$(this).parent().children().removeClass('hl-on');
				$(this).prevAll().addClass('hl-on');
				$(this).addClass('hl-on');
			}
		}

		function starClick()
		{
			$(this).parent().children().removeClass('on');
			$(this).parent().children().addClass('off');
			$(this).prevAll().addClass('on');
			$(this).prevAll().removeClass('off');
			$(this).addClass('on');
			$(this).removeClass('off');
			selected = $(this).prevAll().length + 1;
			if ( Conf.click ) {
				Conf.click.apply( this, [selected] );
			}
		}

		function starOut()
		{
			$(this).parent().children().removeClass('hl-on');
		}

		var i = 0;
		$( this ).children().each(function(){
			$(this).click( starClick )
				.mouseover( starHover )
				.mouseout( starOut );
			if ( i >= options['default'] ) {
				$(this).addClass('off').removeClass('on');
			}
			else {
				$(this).addClass('on').removeClass('off');
			}
			i++;
		});
	}
})(jQuery)


