﻿(function($) {
    $.fn.WBMVotty = function(rateboxCls, overallCls, ratebarCls, rateArr) {
		
		return $(this).each(function(){
			var widgetContainer = $(this),
				rateLinks = widgetContainer.find(rateboxCls)
					.first()
					//['.r1','.r2','.r3','.r4','.r5']
					.find(rateArr.join(','));
			
			rateLinks.bind('click.WBMRate', function(e){
				var $this = $(this),
					href = this.href;
				
				$.get(href, function(data) {
					var wc = widgetContainer,
						ratebar = [];
					
					ratebar[0] = '<span class="ratebar r';
					ratebar[1] = data;
					ratebar[2] = '"></span>';
					
					wc.find(overallCls).html(ratebar.join(''));
					
					ratebar[1] = $this.index()+1;
					$this.parent().html(ratebar.join(''));
				});
				
				e.preventDefault();
				return false;
			});
			
			
		});
    }
}) (jQuery);
