jQuery.fn.xVote = function(config) {
    config = config || {};
    var defaults = {
        activeImageSrc: "http://www.marro.ws/js/active_star.gif",
	passiveImageSrc: "http://www.marro.ws/js/passive_star.gif",
	maxScore: 5,
	fn: new Function(),
	messages: [
	    "Your vote have been saved.",
	    "Very bad",
	    "Bad",
	    "Good, but could be better",
	    "Good enough",
	    "Very good"
	]
    };   
    
    config = jQuery.extend(defaults, config);
    
  
    
    return this.each(function() {
        var $container = jQuery(this);
	
	for (var i = 0, num = config.maxScore * 2; i < num; ++i) {
	    jQuery("<img />").appendTo($container);    
	}
	
	jQuery("<span />").appendTo($container);
	
	$container.find("img:even").
	attr("src", config.passiveImageSrc).
	css({display: "inline"}).
	bind("mouseover", function(e) {	    
	    var len = $container.find("img:even").index(e.target) + 1;
	    
	    $container.find("img:even").slice(0, len).css({display: "none"});
	    
	    $container.find("img:odd").slice(0, len).css({display: "inline"});
	    
	    $container.find("span").text(config.messages[len]);
	    
	    
	}).
	end().
	find("img:odd").
	attr("src", config.activeImageSrc).
	css({display: "none"}).
	bind("mouseout", function(e) {

	    var len = $container.find("img:odd").
	    index(e.target) + 1;

	    $container.find("img:odd")
	    .slice(0, len).
	    css({display: "none"});
	    $container.find("img:even").
	    slice(0,  len).
	    css({display: "inline"});
	    
	    $container.find("span").
	    text("");
	    
	        
	}).
	bind("click", function(e) {
	    $container.find("img").
	    unbind("mouseover").
	    unbind("mouseout").
	    unbind("click");
	    $container.find("span").
	    text(config.messages[0]);
	    config.fn.call(this, e, $container.find("img:odd").index(e.target) + 1);
	});
    });
};

//jquery delay
jQuery.fn.delay = function(time,func){
	this.each(function(){
		setTimeout(func,time);
	});
	
	return this;
};

