(function($){
    $.fn.ratingThumbs = function(options){
        var opts = $.extend({
            ip: false,
            vid: false,
            with_votes: 0,
            ajax_base_path: false
        },options);
        
        if(opts.ip === false){
            alert('provide USER IP for rating_thumbs plugin');
            return false;
        }
        
        if(opts.vid === false){
            alert('provide VIDEO ID for rating_thumbs plugin');
            return false;
        }
        
        var $rt = $(this);
        
        $rt.find('a').click(function(){
            var up = '';
            up = ($(this).hasClass('up')) ? 1 : 0;

            $.post(opts.ajax_base_path + '/includes/rating_thumbs/commit_rating.php',{thumb: up,vid: opts.vid,ip: opts.ip},function(data){
                if(data !== 'false'){
                    $rt.find('.scoreIn').css('width',data.percent);
                    $rt.find('.votes').text("("+data.votes + ")");
                    $rt.find('.up').remove();
                    $rt.find('.down').remove();
                    if(opts.with_votes == 0){
                        $("#rating-thumbs a").removeAttr('href');
                        $("#rating-thumbs a").removeClass("btn-success");
                        $("#rating-thumbs a").addClass("btn-secondary");
                    }else{
                        $("#rating-thumbs a").removeAttr('href');
                        $("#rating-thumbs a").removeClass("btn-success");
                        $("#rating-thumbs a").addClass("btn-secondary");
                    }
                }
            },"json");
            
            return false;
        });
        
        return true;
    }
})(jQuery);



