jQuery.fn.rater = function(url, options) {
    if (url == null) return; var settings = { url: url, maxvalue: 5, curvalue: 0, readOnly: 'false' }; if (options) { jQuery.extend(settings, options); }; jQuery.extend(settings, { cancel: (settings.maxvalue > 1) ? true : false }); var container = jQuery(this); jQuery.extend(container, { averageRating: settings.curvalue, url: settings.url }); if (!settings.style || settings.style == null || settings.style == 'basic') { var raterwidth = settings.maxvalue * 25; var ratingparent = '<ul class="star-rating" style="width:' + raterwidth + 'px">'; }
    if (settings.style == 'small') { var raterwidth = settings.maxvalue * 10; var ratingparent = '<ul class="star-rating small-star" style="width:' + raterwidth + 'px">'; }
    if (settings.style == 'inline') { var raterwidth = settings.maxvalue * 10; var ratingparent = '<span class="inline-rating"><ul class="star-rating small-star" style="width:' + raterwidth + 'px">'; }
    container.append(ratingparent); var starWidth, starIndex, listitems = ''; var curvalueWidth = Math.floor(100 / settings.maxvalue * settings.curvalue); for (var i = 0; i <= settings.maxvalue; i++) {
        if (i == 0) { listitems += '<li class="current-rating" style="width:' + curvalueWidth + '%;">' + settings.curvalue + '/' + settings.maxvalue + '</li>'; } else {
            starWidth = Math.floor(100 / settings.maxvalue * i); starIndex = (settings.maxvalue - i) + 2; if (settings.readOnly == 'true') { listitems += '<li class="star"><span  title="' + getArabicRate(i) + '" style="width:' + starWidth + '%;z-index:' + starIndex + '"></span></li>'; }
            else { listitems += '<li class="star"><a href="#' + i + '" title="' + getArabicRate(i) + '" style="width:' + starWidth + '%;z-index:' + starIndex + '">' + i + '</a></li>'; } 
        } 
    }
    container.find('.star-rating').append(listitems); if (settings.maxvalue > 1)
    { container.append('<span class="star-rating-result"></span>'); }
    var stars = jQuery(container).find('.star-rating').children('.star'); stars.click(function() {
        if (settings.readOnly != 'true') {
            if (settings.maxvalue == 1)
            { settings.curvalue = (settings.curvalue == 0) ? 1 : 0; jQuery(container).find('.star-rating').children('.current-rating').css({ width: (settings.curvalue * 100) + '%' }); jQuery.post(container.url, { "rating": settings.curvalue }); return false; }
            else { settings.curvalue = stars.index(this) + 1; raterValue = jQuery(this).children('a')[0].href.split('#')[1]; jQuery.post(container.url, { "rating": raterValue }, function(response) { container.children('.star-rating-result').html(response) }); return false; } 
        }
        return true;
    }); return this;
}
function getArabicRate(rate) { switch (rate) { case 1: return " 1/5 (سىء)"; break; case 2: return " 2/5 (عادى)"; break; case 3: default: return " 3/5 (جيد)"; break; case 4: return " 4/5 (جيد جدا)"; break; case 5: return " 5/5 (ممتاز)"; break; } }
