/**
* functions
*/
(function($) {

    $.fn.wqItemAbaque = function() {
        return this.each(function() {
            var opt = eval('(' + $(this).attr('rel') + ')');

            if ($(this).hasClass('classic_Abaque')) {
                function changeWidth(bloc, pourcent, widthBlocColor, heightColor) {
                    var width = parseInt((pourcent / 100) * widthBlocColor);
                    bloc.css('width', width + 'px');
                    bloc.css('height', heightColor + 'px');
                }

                $(this).css('width', opt.width + 'px');
                $(this).css('height', opt.height + 'px');
                $(this).css('marginBottom', '1px');

                changeWidth($(this).children('.wq_color_5'), opt.c5, opt.width, opt.height);
                changeWidth($(this).children('.wq_color_4'), opt.c4, opt.width, opt.height);
                changeWidth($(this).children('.wq_color_3'), opt.c3, opt.width, opt.height);
                changeWidth($(this).children('.wq_color_2'), opt.c2, opt.width, opt.height);
                changeWidth($(this).children('.wq_color_1'), opt.c1, opt.width, opt.height);
            }
            else {
                function setParam(bloc, width, heightColor) {
                    bloc.css('width', width + 'px');
                    bloc.css('height', heightColor + 'px');
                }

                $(this).css('width', opt.width + 'px');
                $(this).css('height', opt.height + 'px');
                $(this).css('marginBottom', '1px');

                var width = opt.width / 5;

                setParam($(this).children('.wq_color_5'), width, opt.height);
                setParam($(this).children('.wq_color_4'), width, opt.height);
                setParam($(this).children('.wq_color_3'), width, opt.height);
                setParam($(this).children('.wq_color_2'), width, opt.height);
                setParam($(this).children('.wq_color_1'), width, opt.height);

                var note = ((opt.c5 * 5 + opt.c4 * 4 + opt.c3 * 3 + opt.c2 * 2 + opt.c1) / 5 - 20) / 80;
                var arrowWPosition = note * opt.width - 7.5;
                var arrowHPosition = opt.height - 9;

                $(this).children('.wq_arrow_up').css('left', arrowWPosition + 'px');
                $(this).children('.wq_arrow_up').css('top', arrowHPosition + 'px');
            }
        });
    };

    $.fn.wqItemBars = function() {
        return this.each(function() {
            var opt = eval('(' + $(this).attr('rel') + ')');

            $(this).css('width', opt.width + 'px');
            $(this).css('height', opt.height + 'px');
            $(this).css('borderColor', opt.borderColor);
            $(this).css('borderWidth', '1px');
            $(this).css('borderStyle', 'solid');
            $(this).css('backgroundColor', '#FFFFFF');
            $(this).css('marginBottom', '1px');

            var wqBars = $(this).children('.wq_bars');
            var widthBars = parseInt((opt.width) * (parseInt(opt.note) / 100));
            wqBars.css('backgroundColor', opt.barsColor);
            wqBars.css('height', opt.height);
            wqBars.css('width', widthBars);
        });
    };

    $.fn.wqItemStars = function() {
        return this.each(function() {
            var opt = eval('(' + $(this).attr('rel') + ')');
            $(this).css('width', opt.width + 'px');
            $(this).css('height', opt.height + 'px');
            $(this).css('marginBottom', '1px');

            var widthStars = parseInt((opt.width - ((opt.marginLeft + opt.padding + 2) * 5)) / 5);
            $(this).wqStarsDrawLi(opt.note, opt.starsColor, widthStars, opt.marginLeft, opt.padding);
        });
    };

    $.fn.wqSetFont = function(fontFamily) {
        return this.each(function() {
            var $this = $(this).find('.wq_comments_title, .wq_first_rate, .fn, .votes, .count, .wq_tool_tip_name, .wq_tool_tip_desc, .wq_title, .wq_name, .wq_desc, .wq_nb_votes, .wq_nb_comments, .wq_btn_bckg, .wq_legend_left, .wq_legend_right, .wq_post, .wq_date_post');

            $this.css('fontFamily', fontFamily);
            $(this).find('.wq_power_by').css('fontFamily', fontFamily);
            switch (fontFamily) {
                case 'Lucida Console':
                case 'Tahoma':
                    $this.css('fontSize', '7.5pt');
                    break;

                case 'Georgia':
                case 'Verdana':
                    $this.css('fontSize', '7.5pt');
                    break;

                case 'Times New Roman':
                case 'Arial':
                case 'Comic Sans MS':
                case 'Courier New':
                default:
                    $this.css('fontSize', '8pt');
                    break;
            }

        });
    };

    $.fn.wqBarsNormal = function() {
        return this.each(function() {
            var classToolTip = 'wq_tool_tip';
            var $this = $(this);
            var optWidget = eval('(' + $this.attr('rel') + ')');
            var wqPrincipal = $this.children('.wq_principal');
            var wqContain = wqPrincipal.children('.wq_contain');
            var wqHeader = wqPrincipal.children('.wq_header');
            var wqRows = wqContain.children('.wq_rows');
            var wqRow = wqRows.children('.wq_row');
            var wqComments = $this.children('.wq_comments');
            var wqCommentsItems = wqComments.children('.wq_comments_items');
            var wqPagin = wqCommentsItems.children('.wq_pagin');
            var currentPage = 1;
            var nbCommentsByPage = 3;

            $(this).wqSetFont(optWidget.fontFamily);

            wqRow.children('.wq_name, .wq_plus').unbind();
            wqRow.children('.wq_name, .wq_plus').hover(function() {
                var parent = $(this).parent('.wq_row');
                var pos = parent.position();
                var top = pos.top;
                var name = parent.children('.wq_name').attr('title');
                var desc = parent.children('.wq_desc').html();

                wqRows.append('<div class="' + classToolTip + '"><span class="wq_tool_tip_name">' + name + '</span> : <span class="wq_tool_tip_desc">' + desc + '</span></div>');
                wqToolTip = wqRows.children('.' + classToolTip);
                wqToolTip.wqSetFont(optWidget.fontFamily);

                left = (wqPrincipal.width() - (wqToolTip.width() + 5)) / 2;
                wqToolTip.css('width', wqToolTip.width() - 6 + 'px');
                wqToolTip.css('top', top - wqToolTip.height() - 15 + 'px');
                wqToolTip.css('left', left + 'px');

                wqToolTip.show('slow');
            },
					function() {
					    var wqToolTop = wqRows.children('.' + classToolTip);
					    wqToolTop.remove();
					});

            buildBloc();
            buildRows();
            buildComments();
            resize();

            function resize() {
                if (optWidget.height != 'auto' && !wqContain.children('.wq_first_rate').length > 0) {
                    wqPrincipal.css('height', optWidget.height + 'px');
                    wqContain.css('height', optWidget.height - (wqHeader.height() + 6) + 'px');
                }
                else {
                    wqPrincipal.css('height', 'auto');
                    wqContain.css('height', 'auto');
                }

                if (optWidget.heightComment != 'auto') {
                    wqComments.css('height', parseInt(optWidget.heightComment) + 6 + 'px');
                    wqCommentsItems.css('height', (optWidget.heightComment - (wqComments.children('.wq_comments_title').height() + wqComments.children('.wq_btn').height())) + 'px');
                }
                else {
                    wqCommentsItems.css('height', 'auto');
                    wqComments.css('height', 'auto');
                }
            }

            function buildPagin() {
                var pg = wqPagin.children('.wq_bubble_current, .wq_bubble');
                pg.click(function() {
                    var index = pg.index($(this));
                    currentPage = index + 1;
                    buildComments();
                });
            }

            function buildComments() {
                var wqCommentsItem = wqCommentsItems.children('.wq_comments_item');
                var wqCommentsSeperator = wqCommentsItems.children('.wq_comments_items_separator');

                wqPagin.html('');
                wqCommentsItem.hide();
                wqCommentsSeperator.hide();

                var nbComments = wqCommentsItem.size();
                var nbPage = Math.ceil(nbComments / nbCommentsByPage);
                var start = (currentPage - 1) * nbCommentsByPage;
                var tmpEnd = (start + nbCommentsByPage) - 1;
                var end = tmpEnd >= nbComments ? nbComments - 1 : tmpEnd;
                for (var i = start; i <= end; ++i) {
                    var cmt = $(wqCommentsItem.get(i));
                    cmt.show();
                    var seperator = cmt.next('.wq_comments_items_separator');
                    if (seperator.length > 0)
                        seperator.show();
                }

                if (nbPage > 1) {
                    for (var i = 1; i <= nbPage; ++i) {
                        if (i == currentPage)
                            wqPagin.append('<span class="wq_bubble_current"></span>');
                        else
                            wqPagin.append('<span class="wq_bubble"></span>');
                    }
                    wqPagin.append('<div class="wq_clear"></div>');
                }

                buildPagin();

            }

            function buildRows() {
                var nbChar = 7;
                var nbPixelName = 20;
                var nbPixelBloc = 2;
                var maxWidth = 0;
                var wqNameWidthMin = 74;
                var wqNameWidth = wqNameWidthMin;

                wqRow.each(function() {
                    var wqName = $(this).children('.wq_name');
                    var wqNameVal = wqName.html();
                    var widthTmp = wqName.width();
                    if (widthTmp > maxWidth)
                        maxWidth = widthTmp;
                });

                if (optWidget.width >= 200) {
                    if (optWidget.width >= 320) {
                        wqNameWidth = maxWidth;
                        nbChar = 25;
                    }
                    else if (optWidget.width >= 260) {
                        wqNameWidth += 40;
                        nbChar = 10;
                    }
                }
                else if (optWidget.width < 160) {
                    wqNameWidth -= 20;
                    nbChar = 5;
                }

                var allWqName = wqRow.children('.wq_name');
                allWqName.css('width', wqNameWidth + 'px');

                var w = wqContain.width();
                var widthBlocColor = w - (wqNameWidth + 10 + ($.browser.safari ? 4 : 0));

                wqRow.each(function() {
                    var wqName = $(this).children('.wq_name');
                    var wqNameVal = wqName.html();

                    if (wqNameVal.length > nbChar) {
                        wqName.html(wqNameVal.substr(0, nbChar) + '...');
                        $(this).children('.wq_plus').html('+');
                    }

                    var opt = eval('(' + $(this).attr('rel') + ')');


                    var wqGraph = $(this).children('.wq_graph');
                    wqGraph.css('width', +widthBlocColor + 'px');

                    var wqContainRowBars = wqGraph.children('.wq_bars');
                    var widthBar = parseInt(opt.note / 100 * (widthBlocColor));

                    wqContainRowBars.css('width', widthBar + 'px');
                    wqContainRowBars.css('backgroundColor', optWidget.backgroundBars);
                });
            }

            function buildBloc() {
                var widthLegend = optWidget.width - 5;
                var widthLegendColor = widthLegend - 5;

                var powerBY = wqHeader.children('.wq_power_by');
                wqHeader.children('.wq_logo').show();
                powerBY.css('fontSize', '8pt');
                powerBY.css('height', '15px');
                powerBY.css('paddingTop', '3px');

                if (optWidget.width < 180) {
                    wqContain.children('.wq_title').hide();
                }
                if (optWidget.width < 170) {
                    wqHeader.children('.wq_logo').hide();
                    powerBY.css('fontSize', '7.5pt');
                    powerBY.css('height', '12px');
                    powerBY.css('paddingTop', '1px');
                    wqContain.children('.wq_details').hide();
                    wqComments.children('.wq_comments_title').hide();
                }

                wqPrincipal.css('width', (parseInt(optWidget.width) + ((parseInt(optWidget.borderWidth) - 1) * 2)) + 'px');

                wqContain.css('width', optWidget.width - 6 + 'px');
                wqContain.css('borderColor', optWidget.borderColor);
                wqContain.css('color', optWidget.color);
                wqContain.css('borderWidth', optWidget.borderWidth + 'px');
                wqContain.css('borderStyle', 'solid');
                wqContain.css('backgroundColor', optWidget.backgroundColor);

                wqComments.css('width', (parseInt(optWidget.width) + ((parseInt(optWidget.borderWidth) - 1) * 2)) + 'px');
                wqCommentsItems.css('borderColor', optWidget.borderColor);
                wqComments.css('color', optWidget.color);
                wqCommentsItems.css('borderWidth', optWidget.borderWidth + 'px');
                wqCommentsItems.css('borderStyle', 'solid');
                wqCommentsItems.css('backgroundColor', optWidget.backgroundColor);
                wqComments.children('.wq_btn').css('backgroundColor', optWidget.backgroundColor);
                if (optWidget.position == 'h') {
                    wqPrincipal.css('float', 'left');
                    wqComments.css('float', 'left');
                    wqComments.css('marginLeft', '5px');
                    wqComments.css('marginTop', '7px');
                    $this.append('<div class="wq_clear"></div>');
                }
                else {
                    wqPrincipal.css('float', 'none');
                    wqComments.css('float', 'none');
                    wqComments.css('marginLeft', '0');
                    wqComments.css('marginTop', '5px');
                    if ($this.children('.wq_clear').length > 0)
                        $this.children('.wq_clear').remove();
                }

                if (optWidget.widthComment != 'auto')
                    wqComments.css('width', optWidget.widthComment + 'px');
            }

        });

    };

    $.fn.wqAbaqueNormal = function() {
        return this.each(function() {
            var classToolTip = 'wq_tool_tip';
            var $this = $(this);
            var optWidget = eval('(' + $this.attr('rel') + ')');
            var wqPrincipal = $this.children('.wq_principal');
            var wqContain = wqPrincipal.children('.wq_contain');
            var wqHeader = wqPrincipal.children('.wq_header');
            var wqRows = wqContain.children('.wq_rows');
            var wqRow = wqRows.children('.wq_row');
            var wqComments = $this.children('.wq_comments');
            var wqCommentsItems = wqComments.children('.wq_comments_items');
            var wqPagin = wqCommentsItems.children('.wq_pagin');
            var currentPage = 1;
            var nbCommentsByPage = 3;

            $(this).wqSetFont(optWidget.fontFamily);

            wqRow.children('.wq_name, .wq_plus').unbind();
            wqRow.children('.wq_name, .wq_plus').hover(function() {
                var parent = $(this).parent('.wq_row');
                var pos = parent.position();
                var top = pos.top;
                var name = parent.children('.wq_name').attr('title');
                var desc = parent.children('.wq_desc').html();

                wqRows.append('<div class="' + classToolTip + '"><span class="wq_tool_tip_name">' + name + '</span> : <span class="wq_tool_tip_desc">' + desc + '</span></div>');
                wqToolTip = wqRows.children('.' + classToolTip);
                wqToolTip.wqSetFont(optWidget.fontFamily);

                left = (wqPrincipal.width() - (wqToolTip.width() + 5)) / 2;
                wqToolTip.css('width', wqToolTip.width() - 6 + 'px');
                wqToolTip.css('top', top - wqToolTip.height() - 15 + 'px');
                wqToolTip.css('left', left + 'px');

                wqToolTip.show('slow');
            },
					function() {
					    var wqToolTop = wqRows.children('.' + classToolTip);
					    wqToolTop.remove();
					});

            buildBloc();
            if (wqContain.children('.wq_details').children('.wq_nb_votes').children('.votes').length > 0)
                buildRows();
            buildComments();
            resize();

            function resize() {
                if (optWidget.height != 'auto' && !wqContain.children('.wq_first_rate').length > 0) {
                    wqPrincipal.css('height', optWidget.height + 'px');
                    wqContain.css('height', optWidget.height - (wqHeader.height() + 6) + 'px');
                }
                else {
                    wqPrincipal.css('height', 'auto');
                    wqContain.css('height', 'auto');
                }

                if (optWidget.heightComment != 'auto') {
                    wqComments.css('height', parseInt(optWidget.heightComment) + 6 + 'px');
                    wqCommentsItems.css('height', (optWidget.heightComment - (wqComments.children('.wq_comments_title').height() + wqComments.children('.wq_btn').height())) + 'px');
                }
                else {
                    wqCommentsItems.css('height', 'auto');
                    wqComments.css('height', 'auto');
                }
            }

            function buildPagin() {
                var pg = wqPagin.children('.wq_bubble_current, .wq_bubble');
                pg.click(function() {
                    var index = pg.index($(this));
                    currentPage = index + 1;
                    buildComments();
                });
            }

            function buildComments() {
                var wqCommentsItem = wqCommentsItems.children('.wq_comments_item');
                var wqCommentsSeperator = wqCommentsItems.children('.wq_comments_items_separator');

                wqPagin.html('');
                wqCommentsItem.hide();
                wqCommentsSeperator.hide();

                var nbComments = wqCommentsItem.size();

                var nbPage = Math.ceil(nbComments / nbCommentsByPage);
                var start = (currentPage - 1) * nbCommentsByPage;
                var tmpEnd = (start + nbCommentsByPage) - 1;
                var end = tmpEnd >= nbComments ? nbComments - 1 : tmpEnd;

                for (var i = start; i <= end; ++i) {
                    var cmt = $(wqCommentsItem.get(i));
                    cmt.show();
                    var seperator = cmt.next('.wq_comments_items_separator');
                    if (seperator.length > 0)
                        seperator.show();
                }

                if (nbPage > 1) {
                    for (var i = 1; i <= nbPage; ++i) {
                        if (i == currentPage)
                            wqPagin.append('<span class="wq_bubble_current"></span>');
                        else
                            wqPagin.append('<span class="wq_bubble"></span>');
                    }
                    wqPagin.append('<div class="wq_clear"></div>');
                }

                buildPagin();
            }

            function buildRows() {
                var nbChar = 9;
                var nbPixelName = 20;
                var nbPixelBloc = 2;
                var maxWidth = 0;
                var wqNameWidthMin = 74;
                var wqNameWidth = wqNameWidthMin;

                wqRow.each(function() {
                    var wqName = $(this).children('.wq_name');
                    var wqNameVal = wqName.html();
                    var widthTmp = wqName.width();
                    if (widthTmp > maxWidth)
                        maxWidth = widthTmp;
                });

                if (optWidget.width >= 200) {
                    if (optWidget.width >= 320) {
                        wqNameWidth = maxWidth;
                        nbChar = 25;
                    }
                    else if (optWidget.width >= 260) {
                        wqNameWidth += 40;
                        nbChar = 10;
                    }
                }
                else if (optWidget.width < 160) {
                    wqNameWidth -= 20;
                    nbChar = 5;
                }

                var allWqName = wqRow.children('.wq_name');
                allWqName.css('width', wqNameWidth + 'px');
                var w = wqContain.width();

                var marg = 10;
                if ($.browser.msie)
                    marg -= 2;

                var widthBlocColor = w - (wqNameWidth + marg);


                wqRow.each(function() {
                    var wqName = $(this).children('.wq_name');
                    var wqNameVal = wqName.html();


                    if (wqNameVal.length > nbChar) {
                        wqName.html(wqNameVal.substr(0, nbChar) + '...');
                        $(this).children('.wq_plus').html('+');
                    }

                    var opt = eval('(' + $(this).attr('rel') + ')');

                    var wqGraphOverFlow = $(this).children('.wq_graph_overflow');
                    if (wqGraphOverFlow.length > 0)
                        wqGraphOverFlow.width(widthBlocColor - 4);
                    else
                        wqGraphOverFlow = $(this);

                    var wqGraph = wqGraphOverFlow.children('.wq_graph');

                    var pixel = 0;
                    pixel += changeWidth(wqGraph.children('.wq_color_5'), opt.c5, widthBlocColor);
                    pixel += changeWidth(wqGraph.children('.wq_color_4'), opt.c4, widthBlocColor);
                    pixel += changeWidth(wqGraph.children('.wq_color_3'), opt.c3, widthBlocColor);
                    pixel += changeWidth(wqGraph.children('.wq_color_2'), opt.c2, widthBlocColor);
                    pixel += changeWidth(wqGraph.children('.wq_color_1'), opt.c1, widthBlocColor);

                    wqGraph.width(pixel);
                });
            }

            function changeWidth(bloc, pourcent, widthBlocColor) {
                var width = parseInt((pourcent / 100) * widthBlocColor);
                bloc.css('width', width + 'px');
                return width;
            }

            function buildBloc() {
                var widthLegend = optWidget.width - 5;
                var widthLegendColor = widthLegend - 5;
                var wqLegend = wqContain.children('.wq_legend');
                wqLegend.css('width', widthLegend + 'px');
                var wqLegendColor = wqLegend.children('.wq_legend_color, .wq_legend_texts');
                wqLegendColor.css('width', widthLegendColor + 'px');
                changeWidth(wqLegendColor.children('.wq_legend_color_5, .wq_legend_color_4, .wq_legend_color_3, .wq_legend_color_2, .wq_legend_color_1'),
							20, widthLegendColor - 10);

                var powerBY = wqHeader.children('.wq_power_by');
                wqHeader.children('.wq_logo').show();
                powerBY.css('fontSize', '8pt');
                powerBY.css('height', '15px');
                powerBY.css('paddingTop', '3px');

                if (optWidget.width < 180) {
                    wqContain.children('.wq_title').hide();
                }
                if (optWidget.width < 170) {
                    wqHeader.children('.wq_logo').hide();
                    powerBY.css('fontSize', '7.5pt');
                    powerBY.css('height', '12px');
                    powerBY.css('paddingTop', '1px');
                    wqContain.children('.wq_details').hide();
                    wqComments.children('.wq_comments_title').hide();
                }
                if (optWidget.width < 160) {
                    wqLegend.hide();
                }

                wqPrincipal.css('width', (parseInt(optWidget.width) + ((parseInt(optWidget.borderWidth) - 1) * 2)) + 'px');

                wqContain.css('width', optWidget.width - 6 + 'px');
                wqContain.css('borderColor', optWidget.borderColor);
                wqContain.css('color', optWidget.color);
                wqContain.css('borderWidth', optWidget.borderWidth + 'px');
                wqContain.css('borderStyle', 'solid');
                wqContain.css('backgroundColor', optWidget.backgroundColor);

                wqComments.css('width', (parseInt(optWidget.width) + ((parseInt(optWidget.borderWidth) - 1) * 2)) + 'px');
                wqCommentsItems.css('borderColor', optWidget.borderColor);
                wqComments.css('color', optWidget.color);
                wqCommentsItems.css('borderWidth', optWidget.borderWidth + 'px');
                wqCommentsItems.css('borderStyle', 'solid');
                wqCommentsItems.css('backgroundColor', optWidget.backgroundColor);
                wqComments.children('.wq_btn').css('backgroundColor', optWidget.backgroundColor);
                if (optWidget.position == 'h') {
                    wqPrincipal.css('float', 'left');
                    wqComments.css('float', 'left');
                    wqComments.css('marginLeft', '5px');
                    wqComments.css('marginTop', '7px');
                    $this.append('<div class="wq_clear"></div>');
                }
                else {
                    wqPrincipal.css('float', 'none');
                    wqComments.css('float', 'none');
                    wqComments.css('marginLeft', '0');
                    wqComments.css('marginTop', '5px');
                    if ($this.children('.wq_clear').length > 0)
                        $this.children('.wq_clear').remove();
                }

                if (optWidget.widthComment != 'auto')
                    wqComments.css('width', optWidget.widthComment + 'px');
            }

        });

    };

    $.fn.wqStarsNormal = function() {
        return this.each(function() {
            var classToolTip = 'wq_tool_tip';
            var $this = $(this);
            var optWidget = eval('(' + $this.attr('rel') + ')');
            var wqPrincipal = $this.children('.wq_principal');
            var wqContain = wqPrincipal.children('.wq_contain');
            var wqHeader = wqPrincipal.children('.wq_header');
            var wqRows = wqContain.children('.wq_rows');
            var wqRow = wqRows.children('.wq_row');
            var wqComments = $this.children('.wq_comments');
            var wqCommentsItems = wqComments.children('.wq_comments_items');
            var wqPagin = wqCommentsItems.children('.wq_pagin');
            var currentPage = 1;
            var nbCommentsByPage = 3;

            $(this).wqSetFont(optWidget.fontFamily);

            wqRow.children('.wq_name, .wq_plus').unbind();
            wqRow.children('.wq_name, .wq_plus').hover(function() {
                var parent = $(this).parent('.wq_row');
                var pos = parent.position();
                var top = pos.top;
                var name = parent.children('.wq_name').attr('title');
                var desc = parent.children('.wq_desc').html();

                wqRows.append('<div class="' + classToolTip + '"><span class="wq_tool_tip_name">' + name + '</span> : <span class="wq_tool_tip_desc">' + desc + '</span></div>');
                wqToolTip = wqRows.children('.' + classToolTip);
                wqToolTip.wqSetFont(optWidget.fontFamily);

                left = (wqPrincipal.width() - (wqToolTip.width() + 5)) / 2;
                wqToolTip.css('width', wqToolTip.width() - 6 + 'px');
                wqToolTip.css('top', top - wqToolTip.height() - 15 + 'px');
                wqToolTip.css('left', left + 'px');

                wqToolTip.show('slow');
            },
					function() {
					    var wqToolTop = wqRows.children('.' + classToolTip);
					    wqToolTop.remove();
					});

            buildBloc();
            if (wqContain.children('.wq_details').children('.wq_nb_votes').children('.votes').length > 0)
                buildRows();
            buildComments();
            resize();

            function resize() {
                if (optWidget.height != 'auto' && !wqContain.children('.wq_first_rate').length > 0) {
                    wqPrincipal.css('height', optWidget.height + 'px');
                    wqContain.css('height', optWidget.height - (wqHeader.height() + 6) + 'px');
                }
                else {
                    wqPrincipal.css('height', 'auto');
                    wqContain.css('height', 'auto');
                }

                if (optWidget.heightComment != 'auto') {
                    wqComments.css('height', parseInt(optWidget.heightComment) + 6 + 'px');
                    wqCommentsItems.css('height', (optWidget.heightComment - (wqComments.children('.wq_comments_title').height() + wqComments.children('.wq_btn').height())) + 'px');
                }
                else {
                    wqCommentsItems.css('height', 'auto');
                    wqComments.css('height', 'auto');
                }
            }

            function buildPagin() {
                var pg = wqPagin.children('.wq_bubble_current, .wq_bubble');
                pg.click(function() {
                    var index = pg.index($(this));
                    currentPage = index + 1;
                    buildComments();
                });
            }

            function buildComments() {
                var wqCommentsItem = wqCommentsItems.children('.wq_comments_item');
                var wqCommentsSeperator = wqCommentsItems.children('.wq_comments_items_separator');

                wqPagin.html('');
                wqCommentsItem.hide();
                wqCommentsSeperator.hide();

                var nbComments = wqCommentsItem.size();
                var nbPage = Math.ceil(nbComments / nbCommentsByPage);
                var start = (currentPage - 1) * nbCommentsByPage;
                var tmpEnd = (start + nbCommentsByPage) - 1;
                var end = tmpEnd >= nbComments ? nbComments - 1 : tmpEnd;
                for (var i = start; i <= end; ++i) {
                    var cmt = $(wqCommentsItem.get(i));
                    cmt.show();
                    var seperator = cmt.next('.wq_comments_items_separator');
                    if (seperator.length > 0)
                        seperator.show();
                }

                if (nbPage > 1) {
                    for (var i = 1; i <= nbPage; ++i) {
                        if (i == currentPage)
                            wqPagin.append('<span class="wq_bubble_current"></span>');
                        else
                            wqPagin.append('<span class="wq_bubble"></span>');
                    }
                    wqPagin.append('<div class="wq_clear"></div>');
                }

                buildPagin();

            }

            function buildRows() {
                var nbChar = 7;
                var nbPixelName = 20;
                var nbPixelBloc = 2;
                var maxWidth = 0;
                var wqNameWidthMin = 74;
                var wqNameWidth = wqNameWidthMin;

                wqRow.each(function() {
                    var wqName = $(this).children('.wq_name');
                    var wqNameVal = wqName.html();
                    var widthTmp = wqName.width();
                    if (widthTmp > maxWidth)
                        maxWidth = widthTmp;
                });

                if (optWidget.width >= 200) {
                    if (optWidget.width >= 320) {
                        wqNameWidth = maxWidth;
                        nbChar = 25;
                    }
                    else if (optWidget.width >= 260) {
                        wqNameWidth += 40;
                        nbChar = 10;
                    }
                }
                else if (optWidget.width < 170) {
                    wqNameWidth -= 20;
                    nbChar = 5;
                }

                var allWqName = wqRow.children('.wq_name');
                allWqName.css('width', wqNameWidth + 'px');

                wqRow.each(function() {
                    var wqName = $(this).children('.wq_name');
                    var wqNameVal = wqName.html();

                    if (wqNameVal.length > nbChar) {
                        wqName.html(wqNameVal.substr(0, nbChar) + '...');
                        $(this).children('.wq_plus').html('+');
                    }

                    var opt = eval('(' + $(this).attr('rel') + ')');


                    var widthStars = 22;
                    var marginLeft = 8;
                    var padding = 8;

                    if (optWidget.width <= 180) {
                        widthStars = 13;
                        marginLeft = 1;
                        padding = 0;
                    }
                    else if (optWidget.width <= 190) {
                        widthStars = 15;
                        marginLeft = 1;
                        padding = 0;
                    }
                    else if (optWidget.width <= 210) {
                        widthStars = 18;
                        marginLeft = 2;
                        padding = 0;
                    }
                    else if (optWidget.width <= 220) {
                        widthStars = 20;
                        marginLeft = 2;
                        padding = 0;
                    }
                    else if (optWidget.width <= 240) {
                        widthStars = 21;
                        marginLeft = 1;
                        padding = 2;
                    }
                    else if (optWidget.width <= 220) {
                        widthStars = 22;
                        marginLeft = 4;
                        padding = 2;
                    }
                    else if (optWidget.width <= 260) {
                        widthStars = 21;
                        marginLeft = 1;
                        padding = 2;
                    }
                    else if (optWidget.width <= 285) {
                        widthStars = 22;
                        marginLeft = 1;
                        padding = 1;
                    }
                    else if (optWidget.width <= 385) {
                        widthStars = 22;
                        marginLeft = 4;
                        padding = 4;
                    }

                    var note = opt.note;
                    $(this).children('.wq_graph').wqStarsDrawLi(note, optWidget.backgroundStars, widthStars, marginLeft, padding);
                });
            }

            function changeWidth(bloc, pourcent, widthBlocColor) {
                var width = parseInt((pourcent / 100) * widthBlocColor);
                bloc.css('width', width + 'px');
            }

            function buildBloc() {
                var widthLegend = optWidget.width - 5;
                var widthLegendColor = widthLegend - 5;
                var wqLegend = wqContain.children('.wq_legend');
                wqLegend.css('width', widthLegend + 'px');
                var wqLegendColor = wqLegend.children('.wq_legend_color, .wq_legend_texts');
                wqLegendColor.css('width', widthLegendColor + 'px');

                var powerBY = wqHeader.children('.wq_power_by');
                wqHeader.children('.wq_logo').show();
                powerBY.css('fontSize', '8pt');
                powerBY.css('height', '15px');
                powerBY.css('paddingTop', '3px');

                if (optWidget.width < 180) {
                    wqContain.children('.wq_title').hide();
                }
                if (optWidget.width < 170) {
                    wqHeader.children('.wq_logo').hide();
                    powerBY.css('fontSize', '7.5pt');
                    powerBY.css('height', '12px');
                    powerBY.css('paddingTop', '1px');
                    wqContain.children('.wq_details').hide();
                    wqComments.children('.wq_comments_title').hide();
                }
                if (optWidget.width < 160) {
                    wqLegend.hide();
                }

                wqPrincipal.css('width', (parseInt(optWidget.width) + ((parseInt(optWidget.borderWidth) - 1) * 2)) + 'px');

                wqContain.css('width', optWidget.width - 6 + 'px');
                wqContain.css('borderColor', optWidget.borderColor);
                wqContain.css('color', optWidget.color);
                wqContain.css('borderWidth', optWidget.borderWidth + 'px');
                wqContain.css('borderStyle', 'solid');
                wqContain.css('backgroundColor', optWidget.backgroundColor);

                wqComments.css('width', (parseInt(optWidget.width) + ((parseInt(optWidget.borderWidth) - 1) * 2)) + 'px');
                wqCommentsItems.css('borderColor', optWidget.borderColor);
                wqComments.css('color', optWidget.color);
                wqCommentsItems.css('borderWidth', optWidget.borderWidth + 'px');
                wqCommentsItems.css('borderStyle', 'solid');
                wqCommentsItems.css('backgroundColor', optWidget.backgroundColor);
                wqComments.children('.wq_btn').css('backgroundColor', optWidget.backgroundColor);

                if (optWidget.position == 'h') {
                    wqPrincipal.css('float', 'left');
                    wqComments.css('float', 'left');
                    wqComments.css('marginLeft', '5px');
                    wqComments.css('marginTop', '7px');
                    $this.append('<div class="wq_clear"></div>');
                }
                else {
                    wqPrincipal.css('float', 'none');
                    wqComments.css('float', 'none');
                    wqComments.css('marginLeft', '0');
                    wqComments.css('marginTop', '5px');
                    if ($this.children('.wq_clear').length > 0)
                        $this.children('.wq_clear').remove();
                }

                if (optWidget.widthComment != 'auto')
                    wqComments.css('width', optWidget.widthComment + 'px');
            }

        });

    };

    $.fn.wqRadarNormal = function() {
        return this.each(function() {
            var classToolTip = 'wq_tool_tip';
            var $this = $(this);
            var optWidget = eval('(' + $this.attr('rel') + ')');
            var wqPrincipal = $this.children('.wq_principal');
            var wqContain = wqPrincipal.children('.wq_contain');
            var wqHeader = wqPrincipal.children('.wq_header');
            var wqRows = wqContain.children('.wq_rows');
            var wqRow = wqRows.children('.wq_row');
            var wqComments = $this.children('.wq_comments');
            var wqCommentsItems = wqComments.children('.wq_comments_items');
            var wqPagin = wqCommentsItems.children('.wq_pagin');
            var currentPage = 1;
            var nbCommentsByPage = 3;
            var nbItems = wqRow.length;
            var center;
            var angleOffset = 2 * Math.PI / nbItems;
            var angleStart = -Math.PI / 2 + 2 * angleOffset;

            var colorSurface = optWidget.colorSurface;
            var colorPolygon = optWidget.colorPolygon;
            var colorBorder = optWidget.colorBorder;

            var items = new Array();

            var position = { x: 36, y: 36 };
            var rayonArc = 11;
            var listColors =
				 {
				     0: { color: '#33a939' }, 1: { color: '#97bf10' },
				     2: { color: '#fff100' }, 3: { color: '#e76a23' },
				     4: { color: '#e20020' }, length: 5
				 };

            $(this).wqSetFont(optWidget.fontFamily);

            var canvas = wqRows.children('.wq_canvas_radar');

            var r = parseInt((canvas.height() - (rayonArc * 2)) / 2);

            wqRow.children('.wq_name, .wq_plus').unbind();
            wqRow.children('.wq_name, .wq_plus').hover(function() {
                var parent = $(this).parent('.wq_row');
                var pos = parent.position();
                var top = pos.top;
                var name = parent.children('.wq_name').attr('title');
                var desc = parent.children('.wq_desc').html();

                wqRows.append('<div class="' + classToolTip + '"><span class="wq_tool_tip_name">' + name + '</span> : <span class="wq_tool_tip_desc">' + desc + '</span></div>');
                wqToolTip = wqRows.children('.' + classToolTip);
                wqToolTip.wqSetFont(optWidget.fontFamily);

                left = (wqPrincipal.width() - (wqToolTip.width() + 5)) / 2;
                wqToolTip.css('width', wqToolTip.width() - 6 + 'px');
                wqToolTip.css('top', top - wqToolTip.height() - 15 + 'px');
                wqToolTip.css('left', left + 'px');

                wqToolTip.show('slow');
            },
					function() {
					    var wqToolTop = wqRows.children('.' + classToolTip);
					    wqToolTop.remove();
					});

            buildBloc();
            if (wqContain.children('.wq_details').children('.wq_nb_votes').children('.votes').length > 0)
                drawRadar();
            buildComments();
            resize();

            function resize() {
                if (optWidget.height != 'auto' && !wqContain.children('.wq_first_rate').length > 0) {
                    wqPrincipal.css('height', optWidget.height + 'px');
                    wqContain.css('height', optWidget.height - (wqHeader.height() + 6) + 'px');
                }
                else {
                    wqPrincipal.css('height', 'auto');
                    wqContain.css('height', 'auto');
                }

                if (optWidget.heightComment != 'auto') {
                    wqComments.css('height', parseInt(optWidget.heightComment) + 6 + 'px');
                    wqCommentsItems.css('height', (optWidget.heightComment - (wqComments.children('.wq_comments_title').height() + wqComments.children('.wq_btn').height())) + 'px');
                }
                else {
                    wqCommentsItems.css('height', 'auto');
                    wqComments.css('height', 'auto');
                }
            }

            function changeWidth(bloc, pourcent, widthBlocColor) {
                var width = (pourcent / 100) * widthBlocColor;
                bloc.css('width', width + 'px');
            }

            function buildPagin() {
                var pg = wqPagin.children('.wq_bubble_current, .wq_bubble');
                pg.click(function() {
                    var index = pg.index($(this));
                    currentPage = index + 1;
                    buildComments();
                });
            }

            function buildComments() {
                var wqCommentsItem = wqCommentsItems.children('.wq_comments_item');
                var wqCommentsSeperator = wqCommentsItems.children('.wq_comments_items_separator');

                wqPagin.html('');
                wqCommentsItem.hide();
                wqCommentsSeperator.hide();

                var nbComments = wqCommentsItem.size();
                var nbPage = Math.ceil(nbComments / nbCommentsByPage);
                var start = (currentPage - 1) * nbCommentsByPage;
                var tmpEnd = (start + nbCommentsByPage) - 1;
                var end = tmpEnd >= nbComments ? nbComments - 1 : tmpEnd;
                for (var i = start; i <= end; ++i) {
                    var cmt = $(wqCommentsItem.get(i));
                    cmt.show();
                    var seperator = cmt.next('.wq_comments_items_separator');
                    if (seperator.length > 0)
                        seperator.show();
                }

                if (nbPage > 1) {
                    for (var i = 1; i <= nbPage; ++i) {
                        if (i == currentPage)
                            wqPagin.append('<span class="wq_bubble_current"></span>');
                        else
                            wqPagin.append('<span class="wq_bubble"></span>');
                    }
                    wqPagin.append('<div class="wq_clear"></div>');
                }

                buildPagin();
            }

            function buildBloc() {
                var widthLegend = optWidget.width - 5;
                var widthLegendColor = widthLegend - 5;
                var wqLegend = wqContain.children('.wq_legend');
                wqLegend.css('width', widthLegend + 'px');
                var wqLegendColor = wqLegend.children('.wq_legend_color, .wq_legend_texts');
                wqLegendColor.css('width', widthLegendColor + 'px');
                changeWidth(wqLegendColor.children('.wq_legend_color_5, .wq_legend_color_4, .wq_legend_color_3, .wq_legend_color_2, .wq_legend_color_1'),
							20, widthLegendColor - 10);

                var powerBY = wqHeader.children('.wq_power_by');
                wqHeader.children('.wq_logo').show();
                powerBY.css('fontSize', '8pt');
                powerBY.css('height', '15px');
                powerBY.css('paddingTop', '3px');

                if (optWidget.width < 180) {
                    wqContain.children('.wq_title').hide();
                }
                if (optWidget.width < 170) {
                    wqHeader.children('.wq_logo').hide();
                    powerBY.css('fontSize', '7.5pt');
                    powerBY.css('height', '12px');
                    powerBY.css('paddingTop', '1px');
                    wqContain.children('.wq_details').hide();
                    wqComments.children('.wq_comments_title').hide();
                }
                if (optWidget.width < 160) {
                    wqLegend.hide();
                }

                wqPrincipal.css('width', (parseInt(optWidget.width) + ((parseInt(optWidget.borderWidth) - 1) * 2)) + 'px');

                wqContain.css('width', optWidget.width - 6 + 'px');
                wqContain.css('borderColor', optWidget.borderColor);
                wqContain.css('color', optWidget.color);
                wqContain.css('borderWidth', optWidget.borderWidth + 'px');
                wqContain.css('borderStyle', 'solid');
                wqContain.css('backgroundColor', optWidget.backgroundColor);

                wqComments.css('width', (parseInt(optWidget.width) + ((parseInt(optWidget.borderWidth) - 1) * 2)) + 'px');
                wqCommentsItems.css('borderColor', optWidget.borderColor);
                wqComments.css('color', optWidget.color);
                wqCommentsItems.css('borderWidth', optWidget.borderWidth + 'px');
                wqCommentsItems.css('borderStyle', 'solid');
                wqCommentsItems.css('backgroundColor', optWidget.backgroundColor);
                wqComments.children('.wq_btn').css('backgroundColor', optWidget.backgroundColor);

                if (optWidget.position == 'h') {
                    wqPrincipal.css('float', 'left');
                    wqComments.css('float', 'left');
                    wqComments.css('marginLeft', '5px');
                    wqComments.css('marginTop', '7px');
                    $this.append('<div class="wq_clear"></div>');
                }
                else {
                    wqPrincipal.css('float', 'none');
                    wqComments.css('float', 'none');
                    wqComments.css('marginLeft', '0');
                    wqComments.css('marginTop', '5px');
                    if ($this.children('.wq_clear').length > 0)
                        $this.children('.wq_clear').remove();
                }

                if (optWidget.widthComment != 'auto')
                    wqComments.css('width', optWidget.widthComment + 'px');

                canvas.css('marginLeft', (wqContain.width() - canvas.width()) / 2 + 'px');
            }

            function drawRadar() {
                var rBy2 = parseInt(r / 2);
                center = { x: rBy2, y: rBy2 };


                wqRow.each(function() {
                    var opt = eval('(' + $(this).attr('rel') + ')');
                    var name = $(this).children('.wq_name').html();
                    var desc = $(this).children('.wq_desc').html();
                    items.push({ note: opt.note, name: name, desc: desc });
                });

                drawPolygon();
                drawLine();
                drawSurface();
            }

            function drawLine() {
                var ctx = canvas.get(0).getContext('2d');
                var tab = calculePolygonVertices();
                ctx.save();
                ctx.strokeStyle = this.colorBorder;
                ctx.lineWidth = 2;
                ctx.lineJoin = 'round';
                ctx.translate(position.x, position.y);
                ctx.beginPath();
                ctx.scale(1, 1);
                ctx.moveTo(tab[0].x, tab[0].y);
                for (var i = 0; i < nbItems; ++i) {
                    ctx.moveTo(tab[i].x, tab[i].y);
                    ctx.lineTo(center.x, center.y);
                }
                ctx.closePath();
                ctx.stroke();
                ctx.restore();

                for (var i = 0; i < nbItems; ++i)
                    drawArc(tab[i].x, tab[i].y,
							getColor(items[i].note), i);
            }

            function drawSurface() {
                var ctx = canvas.get(0).getContext('2d');
                ctx.save();
                var rgb = html2rgb(colorSurface);
                ctx.fillStyle = 'rgba(' + rgb[0] + ',' + rgb[1] + ',' + rgb[2] + ',0.7)';
                ctx.strokeStyle = colorBorder;
                ctx.lineWidth = 1;
                ctx.lineJoin = 'round';
                ctx.translate(position.x, position.y);
                ctx.beginPath();
                ctx.scale(1, 1);

                var pt = polar(getEchelValue(items[0].note),
								(angleOffset * 0 + angleStart) % (2 * Math.PI));

                ctx.moveTo(pt.x + center.x, pt.y + center.y);

                for (var i = 0; i < nbItems; ++i) {
                    var pt = polar(getEchelValue(items[i].note),
							(angleOffset * i + angleStart) % (2 * Math.PI));
                    ctx.lineTo(pt.x + center.x, pt.y + center.y);
                }

                ctx.closePath();
                ctx.fill();
                ctx.stroke();
                ctx.restore();

                for (var i = 0; i < nbItems; ++i) {
                    var pt = polar(getEchelValue(items[i].note),
												(angleOffset * i + angleStart) % (2 * Math.PI));
                    drawPoint(pt.x + center.x, pt.y + center.y, getColor(items[i].note), i);
                }
            }

            function getEchelValue(value) {
                return r * value / 100;
            }

            function drawPoint(x, y, color, i) {
                var e = $('<div class="wq_selector" style="position:absolute; width:10px; height:10px; left:' + (Math.round(x + 30 + ((wqContain.width() - canvas.width()) / 2))) + 'px;top:' + (Math.round(y + 30)) + 'px;"></div>');
                e.hover(function() {
                    var row = wqRows.children('.wq_row').eq(i);
                    var top = 5;
                    var name = row.children('.wq_name').attr('title');
                    var desc = row.children('.wq_desc').html();

                    wqContain.append('<div class="' + classToolTip + '"><span class="wq_tool_tip_name">' + name + '</span> : <span class="wq_tool_tip_desc">' + desc + '</span></div>');
                    wqToolTip = wqContain.children('.' + classToolTip);
                    wqToolTip.wqSetFont(optWidget.fontFamily);

                    left = (wqPrincipal.width() - (wqToolTip.width() + 5)) / 2;
                    wqToolTip.css('width', wqToolTip.width() - 6 + 'px');
                    top -= wqToolTip.height();
                    if (wqContain.children('.wq_title').css('display') != 'none')
                        top += wqContain.children('.wq_title').height();

                    wqToolTip.css('top', top - wqToolTip.height() + wqContain.children('.wq_title').height() + 'px');
                    wqToolTip.css('left', left + 'px');

                    wqToolTip.show('slow');
                },
					function() {
					    var wqToolTop = wqContain.children('.' + classToolTip);
					    wqToolTop.remove();
					});

                $(canvas).parent().append(e);

                var ctx = canvas.get(0).getContext('2d');
                ctx.save();
                ctx.fillStyle = color;
                ctx.strokeStyle = colorBorder;
                ctx.lineWidth = 1;
                ctx.lineJoin = 'round';
                ctx.translate(position.x, position.y);
                ctx.beginPath();
                ctx.scale(1, 1);
                ctx.arc(x, y, 5, 0, Math.PI * 2, true); // Outer circle
                ctx.fill();
                ctx.closePath();
                ctx.stroke();
                ctx.restore();
            }

            function drawArc(x, y, color, i) {
                var e = $('<div class="wq_selector" style="position:absolute; width:20px; height:20px; left:' + (Math.round(x + 25 + ((wqContain.width() - canvas.width()) / 2))) + 'px;top:' + (Math.round(y + 25)) + 'px;"></div>');
                e.hover(function() {
                    var row = wqRows.children('.wq_row').eq(i);
                    var top = 5;
                    var name = row.children('.wq_name').attr('title');
                    var desc = row.children('.wq_desc').html();

                    wqContain.append('<div class="' + classToolTip + '"><span class="wq_tool_tip_name">' + name + '</span> : <span class="wq_tool_tip_desc">' + desc + '</span></div>');
                    wqToolTip = wqContain.children('.' + classToolTip);
                    wqToolTip.wqSetFont(optWidget.fontFamily);

                    left = (wqPrincipal.width() - (wqToolTip.width() + 5)) / 2;
                    wqToolTip.css('width', wqToolTip.width() - 6 + 'px');
                    top -= wqToolTip.height();
                    if (wqContain.children('.wq_title').css('display') != 'none')
                        top += wqContain.children('.wq_title').height();
                    wqToolTip.css('top', top + 'px');
                    wqToolTip.css('left', left + 'px');
                    wqToolTip.show('slow');
                },
					function() {
					    var wqToolTop = wqContain.children('.' + classToolTip);
					    wqToolTop.remove();
					});

                $(canvas).parent().append(e);

                var ctx = canvas.get(0).getContext('2d');
                ctx.save();
                var rgb = html2rgb(colorSurface);
                ctx.fillStyle = 'rgba(' + rgb[0] + ',' + rgb[1] + ',' + rgb[2] + ',0.4)';
                ctx.lineWidth = 0.5;
                ctx.lineJoin = 'round';
                ctx.translate(position.x, position.y);
                ctx.beginPath();
                ctx.scale(1, 1);
                ctx.arc(x, y, rayonArc, 0, Math.PI * 2, true); // Outer circle
                ctx.fill();
                ctx.closePath();
                ctx.restore();
            }

            function drawPolygon() {
                var tab = calculePolygonVertices();
                var ctx = canvas.get(0).getContext('2d');
                ctx.save();
                ctx.fillStyle = colorPolygon;
                ctx.strokeStyle = "#00000";
                ctx.lineWidth = 1;
                ctx.lineJoin = 'round';
                ctx.translate(position.x, position.y);
                ctx.beginPath();
                ctx.scale(1, 1);
                ctx.moveTo(tab[0].x, tab[0].y);
                for (var i = 0; i < nbItems; ++i)
                    ctx.lineTo(tab[i].x, tab[i].y);
                ctx.closePath();
                ctx.fill();
                ctx.stroke();
                ctx.restore();
            }

            function calculePolygonVertices() {
                var t_val = new Array();
                for (var i = 0; i < nbItems; i++) {
                    var pt = polar(r, angleOffset * i + angleStart);
                    pt.x += center.x;
                    pt.y += center.y;
                    t_val.push(pt);
                }

                return t_val;
            }

            function getColor(value) {
                var color = '';

                if (value <= 35)
                    color = listColors[4].color;
                else if (value > 35 && value <= 50)
                    color = listColors[3].color;
                else if (value > 50 && value <= 65)
                    color = listColors[2].color;
                else if (value > 65 && value <= 80)
                    color = listColors[1].color;
                else if (value > 80 && value <= 100)
                    color = listColors[0].color;
                return color;
            }

            function polar(r, o) {
                var valX = r * Math.cos(o);
                var valY = r * Math.sin(o);
                return { x: valX, y: valY };
            }

            function carr(val) {
                return val * val;
            }

            function html2rgb(hex) {
                if (hex.charAt(0) == '#')
                    hex = hex.substr(1, hex.length - 1);

                var strlen = hex.length;
                var color;

                if (strlen == 6)
                    color = new Array(hex.charAt(0) + '' + hex.charAt(1),
									  hex.charAt(2) + '' + hex.charAt(3),
									  hex.charAt(4) + '' + hex.charAt(5));
                else if (strlen == 3)
                    color = new Array(hex.charAt(0) + '' + hex.charAt(0),
									  hex.charAt(1) + '' + hex.charAt(1),
									  hex.charAt(2) + '' + hex.charAt(2));
                else
                    return false;

                var rgb = new Array();
                for (var i = 0; i < color.length; ++i)
                    rgb.push(hexdec(color[i]));

                return rgb;
            }

            function hexdec(hex_string) {
                hex_string = (hex_string + '').replace(/[^a-f0-9]/gi, '');
                return parseInt(hex_string, 16);
            }
        });

    };

    $.fn.wqRadarMini = function() {
        return this.each(function() {
            var $this = $(this);

            var optWidget = eval('(' + $this.attr('rel') + ')');
            var wqContain = $(this).children('.wq_contain');
            var wqRows = wqContain.children('.wq_rows');
            var wqRow = wqRows.children('.wq_row');
            var wqHeader = $(this).children('.wq_header');
            var widthColor = 0;
            var nbItems = wqRow.length;
            var center;
            var angleOffset = 2 * Math.PI / nbItems;
            var angleStart = -Math.PI / 2 + 2 * angleOffset;

            var colorSurface = optWidget.colorSurface;
            var colorPolygon = optWidget.colorPolygon;
            var colorBorder = optWidget.colorBorder;

            var items = new Array();

            var position = { x: 20, y: 20 };
            var rayonArc = 8;
            var listColors =
				 {
				     0: { color: '#33a939' }, 1: { color: '#97bf10' },
				     2: { color: '#fff100' }, 3: { color: '#e76a23' },
				     4: { color: '#e20020' }, length: 5
				 };

            $(this).wqSetFont(optWidget.fontFamily);

            //top10 exception
            optWidget.width = $this.parents('.widgetQTop10').length > 0 ? 140 : optWidget.width;

            var canvas = wqContain.children('.wq_canvas_radar');

            var r = parseInt((canvas.height() - (rayonArc * 2)) / 2);

            buildBloc();
            if (wqHeader.children('.wq_nb_votes').children('.votes').length > 0)
                drawRadar();

            function buildBloc() {
                var widthContain = (optWidget.width - 20);
                if (optWidget.width < 200)
                    wqHeader.children('.wq_power_by').hide();
                if (optWidget.width < 150) {
                    wqHeader.hide();
                    widthContain = (optWidget.width - 10);
                }

                widthColor = widthContain / 5;
                wqContain.css('width', widthContain + 4 + 'px');

                $this.css('width', optWidget.width + 'px');
                $this.css('borderColor', optWidget.borderColor);
                $this.css('color', optWidget.color);
                $this.css('borderWidth', optWidget.borderWidth + 'px');
                $this.css('borderStyle', 'solid');
                $this.css('backgroundColor', optWidget.backgroundColor);

                canvas.css('marginLeft', (wqContain.width() - canvas.width()) / 2 + 'px');

            }

            function drawRadar() {
                var rBy2 = parseInt(r / 2);
                center = { x: rBy2, y: rBy2 };


                wqRow.each(function() {
                    var opt = eval('(' + $(this).attr('rel') + ')');
                    var name = $(this).children('.wq_name').html();
                    var desc = $(this).children('.wq_desc').html();
                    items.push({ note: opt.note, name: name, desc: desc });
                });

                drawPolygon();
                drawLine();
                drawSurface();
            }

            function drawLine() {
                var ctx = canvas.get(0).getContext('2d');
                var tab = calculePolygonVertices();
                ctx.save();
                ctx.strokeStyle = this.colorBorder;
                ctx.lineWidth = 2;
                ctx.lineJoin = 'round';
                ctx.translate(position.x, position.y);
                ctx.beginPath();
                ctx.scale(1, 1);
                ctx.moveTo(tab[0].x, tab[0].y);
                for (var i = 0; i < nbItems; ++i) {
                    ctx.moveTo(tab[i].x, tab[i].y);
                    ctx.lineTo(center.x, center.y);
                }
                ctx.closePath();
                ctx.stroke();
                ctx.restore();

                for (var i = 0; i < nbItems; ++i)
                    drawArc(tab[i].x, tab[i].y,
							getColor(items[i].note), i);
            }

            function drawSurface() {
                var ctx = canvas.get(0).getContext('2d');
                ctx.save();
                var rgb = html2rgb(colorSurface);
                ctx.fillStyle = 'rgba(' + rgb[0] + ',' + rgb[1] + ',' + rgb[2] + ',0.7)';
                ctx.strokeStyle = colorBorder;
                ctx.lineWidth = 1;
                ctx.lineJoin = 'round';
                ctx.translate(position.x, position.y);
                ctx.beginPath();
                ctx.scale(1, 1);

                var pt = polar(getEchelValue(items[0].note),
								(angleOffset * 0 + angleStart) % (2 * Math.PI));

                ctx.moveTo(pt.x + center.x, pt.y + center.y);

                for (var i = 0; i < nbItems; ++i) {
                    var pt = polar(getEchelValue(items[i].note),
							(angleOffset * i + angleStart) % (2 * Math.PI));
                    ctx.lineTo(pt.x + center.x, pt.y + center.y);
                }

                ctx.closePath();
                ctx.fill();
                ctx.stroke();
                ctx.restore();

                for (var i = 0; i < nbItems; ++i) {
                    var pt = polar(getEchelValue(items[i].note),
												(angleOffset * i + angleStart) % (2 * Math.PI));
                    drawPoint((pt.x + center.x), pt.y + center.y, getColor(items[i].note));
                }
            }

            function getEchelValue(value) {
                return r * value / 100;
            }

            function drawPoint(x, y, color) {
                var ctx = canvas.get(0).getContext('2d');
                ctx.save();
                ctx.fillStyle = color;
                ctx.strokeStyle = colorBorder;
                ctx.lineWidth = 1;
                ctx.lineJoin = 'round';
                ctx.translate(position.x, position.y);
                ctx.beginPath();
                ctx.scale(1, 1);
                ctx.arc(x, y, 3, 0, Math.PI * 2, true); // Outer circle
                ctx.fill();
                ctx.stroke();
                ctx.closePath();
                ctx.restore();
            }

            function drawArc(x, y, color, i) {
                var ctx = canvas.get(0).getContext('2d');
                ctx.save();
                var rgb = html2rgb(colorSurface);
                ctx.fillStyle = 'rgba(' + rgb[0] + ',' + rgb[1] + ',' + rgb[2] + ',0.4)';
                ctx.lineWidth = 0.5;
                ctx.lineJoin = 'round';
                ctx.translate(position.x, position.y);
                ctx.beginPath();
                ctx.scale(1, 1);
                ctx.arc(x, y, rayonArc, 0, Math.PI * 2, true); // Outer circle
                ctx.fill();
                ctx.closePath();
                ctx.restore();
            }

            function drawPolygon() {
                var tab = calculePolygonVertices();
                var ctx = canvas.get(0).getContext('2d');
                ctx.save();
                ctx.fillStyle = colorPolygon;
                ctx.strokeStyle = "#00000";
                ctx.lineWidth = 1;
                ctx.lineJoin = 'round';
                ctx.translate(position.x, position.y);
                ctx.beginPath();
                ctx.scale(1, 1);
                ctx.moveTo(tab[0].x, tab[0].y);
                for (var i = 0; i < nbItems; ++i)
                    ctx.lineTo(tab[i].x, tab[i].y);
                ctx.closePath();
                ctx.fill();
                ctx.stroke();
                ctx.restore();
            }

            function calculePolygonVertices() {
                var t_val = new Array();
                for (var i = 0; i < nbItems; i++) {
                    var pt = polar(r, angleOffset * i + angleStart);
                    pt.x += center.x;
                    pt.y += center.y;
                    t_val.push(pt);
                }

                return t_val;
            }

            function getColor(value) {
                var color = '';

                if (value <= 35)
                    color = listColors[4].color;
                else if (value > 35 && value <= 50)
                    color = listColors[3].color;
                else if (value > 50 && value <= 65)
                    color = listColors[2].color;
                else if (value > 65 && value <= 80)
                    color = listColors[1].color;
                else if (value > 80 && value <= 100)
                    color = listColors[0].color;
                return color;
            }

            function polar(r, o) {
                var valX = r * Math.cos(o);
                var valY = r * Math.sin(o);
                return { x: valX, y: valY };
            }

            function carr(val) {
                return val * val;
            }

            function html2rgb(hex) {
                if (hex.charAt(0) == '#')
                    hex = hex.substr(1, hex.length - 1);

                var strlen = hex.length;
                var color;

                if (strlen == 6)
                    color = new Array(hex.charAt(0) + '' + hex.charAt(1),
									  hex.charAt(2) + '' + hex.charAt(3),
									  hex.charAt(4) + '' + hex.charAt(5));
                else if (strlen == 3)
                    color = new Array(hex.charAt(0) + '' + hex.charAt(0),
									  hex.charAt(1) + '' + hex.charAt(1),
									  hex.charAt(2) + '' + hex.charAt(2));
                else
                    return false;

                var rgb = new Array();
                for (var i = 0; i < color.length; ++i)
                    rgb.push(hexdec(color[i]));

                return rgb;
            }

            function hexdec(hex_string) {
                hex_string = (hex_string + '').replace(/[^a-f0-9]/gi, '');
                return parseInt(hex_string, 16);
            }
        });
    };

    $.fn.wqAbaqueMini = function() {
        return this.each(function() {
            var $this = $(this);

            var optWidget = eval('(' + $this.attr('rel') + ')');
            var wqContain = $(this).children('.wq_contain');
            var wqHeader = $(this).children('.wq_header');
            var wqArrowUp = wqContain.children('.wq_arrow_up');
            var widthColor = 0;

            $(this).wqSetFont(optWidget.fontFamily);

            buildBloc();
            if (wqHeader.children('.wq_nb_votes').children('.votes').length > 0)
                buildCursor();

            //top10 exception
            optWidget.width = $this.parents('.widgetQTop10').length > 0 ? 140 : optWidget.width;

            function buildCursor() {
                var note = eval('(' + wqContain.attr('rel') + ')').note;

                note -= 20;
                note = note * 100 / 80;

                posLeft = note * (widthColor * 5 + 4) / 100 - 7;
                wqArrowUp.css('left', posLeft + 'px');
            }

            function buildBloc() {
                var widthContain = (optWidget.width - 20);
                if (optWidget.width < 200)
                    wqHeader.children('.wq_power_by').hide();
                if (optWidget.width < 150) {
                    wqHeader.hide();
                    widthContain = (optWidget.width - 10);
                }

                widthColor = widthContain / 5;
                wqContain.children('.wq_color_5, .wq_color_4, .wq_color_3, .wq_color_2, .wq_color_1').css('width', widthColor + 'px');
                wqContain.css('width', widthContain + 4 + 'px');

                $this.css('width', optWidget.width + 'px');
                $this.css('borderColor', optWidget.borderColor);
                $this.css('color', optWidget.color);
                $this.css('borderWidth', optWidget.borderWidth + 'px');
                $this.css('borderStyle', 'solid');
                $this.css('backgroundColor', optWidget.backgroundColor);


            }
        });
    };

    $.fn.wqStarsDrawLi = function(note, background, width, marginLeft, padding) {
        var $this = this;
        var img = wqPack.pathStarsImage;

        var center = Math.ceil(padding / 2);
        var blocSize = width + padding;

        var nbHalfStar = note / 10;
        var nbFullStar = nbHalfStar / 2;
        nbHalfStar %= 2;

        var dxImageParent = '';
        var dxImage = '';
        if ($.browser.msie && parseInt($.browser.version) < 8) {
            dxImageParent = 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + img + '\',sizingMethod=\'scale\');';
            dxImage = 'filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);';
        }

        var html = '';
        var j = 1;
        for (; j <= nbFullStar; ++j)
        { drawStars(); }

        if (nbHalfStar != 0)
        { drawStarsHalfEmpty(); ++j; }

        for (; j <= 5; ++j)
        { drawStarsEmpty(); }

        html += '<div class="wq_clear"></div>';

        $this.append(html);


        function drawStars() {

            var margin = marginLeft;
            if (j == 1)
                margin = 0;

            html += '<div style="position:relative; background-color:white; width:' + blocSize + 'px; height:' + blocSize + 'px;  float:left;margin-left:' + margin + 'px; border:1px solid #b6b6b6;">';
            html += '<div style="background-color:' + background + '; width:' + blocSize + 'px; height:' + blocSize + 'px; position:absolute; left:0; top:0; "></div>';
            html += '<div style="position:absolute; left:' + center + 'px; top:' + center + 'px; ' + dxImageParent + ' "><img src="' + img + '" width="' + width + '" style="width:' + width + 'px;' + dxImage + '"/></div>';
            html += '</div>';
        }

        function drawStarsEmpty() {
            var margin = marginLeft;
            if (j == 1)
                margin = 0;

            html += '<div style="position:relative; background-color:white; width:' + blocSize + 'px; height:' + blocSize + 'px;float:left;margin-left:' + margin + 'px; border:1px solid #b6b6b6;">';
            html += '<div style="position:absolute; left:' + center + 'px; top:' + center + 'px; ' + dxImageParent + '"><img src="' + img + '" width="' + width + '" style="width:' + width + 'px;' + dxImage + '"/></div>';
            html += '</div>';
        }

        function drawStarsHalfEmpty() {
            var margin = marginLeft;
            if (j == 1)
                margin = 0;

            html += '<div style="position:relative; background-color:white; width:' + blocSize + 'px; height:' + blocSize + 'px;  float:left;margin-left:' + margin + 'px; border:1px solid #b6b6b6;">';
            html += '<div style="background-color:' + background + ';width:' + (Math.ceil(blocSize / 2)) + 'px; height:' + blocSize + 'px; position:absolute; border-right:1px solid #b6b6b6;  left:0; top:0;"></div>';
            html += '<div style="position:absolute; left:' + center + 'px; top:' + center + 'px; ' + dxImageParent + '"><img src="' + img + '" width="' + width + '" style="width:' + width + 'px;' + dxImage + '"/></div>';
            html += '</div>';
        }
    };

    $.fn.wqStarsMini = function() {
        return this.each(function() {
            var $this = $(this);
            var optWidget = eval('(' + $this.attr('rel') + ')');
            var wqContain = $(this).children('.wq_contain');
            var wqHeader = $(this).children('.wq_header');

            $(this).wqSetFont(optWidget.fontFamily);

            var widthColor = 0;
            var widthStars = 22;
            var marginLeft = 4;
            var padding = 5;

            if (optWidget.width < 90) {
                widthStars = 12;
                marginLeft = 1;
                padding = 1;
            }
            else if (optWidget.width < 100) {
                widthStars = 14;
                marginLeft = 2;
                padding = 0;
            }
            else if (optWidget.width < 120) {
                widthStars = 16;
                marginLeft = 1;
                padding = 0;
            }
            else if (optWidget.width < 140) {
                widthStars = 19;
                marginLeft = 2;
                padding = 0;
            }
            else if (optWidget.width < 180) {
                widthStars = 21;
                marginLeft = 2;
                padding = 0;
            }
            else if (optWidget.width < 250) {
                widthStars = 22;
                marginLeft = 4;
                padding = 2;
            }

            buildBloc();
            if (wqHeader.children('.wq_nb_votes').children('.votes').length > 0)
                buildRow();


            function buildRow() {
                var note = eval('(' + wqContain.attr('rel') + ')').note;
                wqContain.wqStarsDrawLi(note, optWidget.backgroundStars, widthStars, marginLeft, padding);
            }

            function buildBloc() {
                var widthContain = ((widthStars + marginLeft + padding + 2) * 5) - marginLeft;
                if (optWidget.width < 200)
                    wqHeader.children('.wq_power_by').hide();
                if (optWidget.width < 150) {
                    wqHeader.hide();
                }

                wqContain.css('width', widthContain + 'px');

                $this.css('width', optWidget.width + 'px');
                $this.css('borderColor', optWidget.borderColor);
                $this.css('color', optWidget.color);
                $this.css('borderWidth', optWidget.borderWidth + 'px');
                $this.css('borderStyle', 'solid');
                $this.css('backgroundColor', optWidget.backgroundColor);
            }
        });
    };

    $.fn.wqBarsMini = function() {
        return this.each(function() {
            var $this = $(this);

            var optWidget = eval('(' + $this.attr('rel') + ')');
            var wqContain = $(this).children('.wq_contain');
            var wqBars = wqContain.children('.wq_bars');
            var wqHeader = $(this).children('.wq_header');
            var widthColor = 0;

            $(this).wqSetFont(optWidget.fontFamily);

            //top10 exception
            optWidget.width = $this.parents('.widgetQTop10').length > 0 ? 140 : optWidget.width;

            buildBloc();

            function buildBloc() {
                var widthContain = (optWidget.width - 20);
                if (optWidget.width < 200)
                    wqHeader.children('.wq_power_by').hide();
                if (optWidget.width < 150)
                    wqHeader.hide();

                if (wqHeader.children('.wq_nb_votes').children('.votes').length > 0) {
                    var note = eval('(' + wqContain.attr('rel') + ')').note;
                    var widthBar = parseInt(note / 100 * (widthContain + 4));

                    wqContain.css('width', widthContain + 4 + 'px');
                    wqContain.css('borderColor', optWidget.borderColor);
                    wqContain.css('borderWidth', optWidget.borderWidth + 'px');
                    wqContain.css('borderStyle', 'solid');

                    wqBars.css('width', widthBar + 'px');
                    wqBars.css('backgroundColor', optWidget.backgroundBars);
                }


                $this.css('borderColor', optWidget.borderColor);
                $this.css('borderWidth', optWidget.borderWidth + 'px');
                $this.css('borderStyle', 'solid');

                $this.css('width', optWidget.width + 'px');
                $this.css('borderColor', optWidget.borderColor);
                $this.css('color', optWidget.color);
                $this.css('borderWidth', optWidget.borderWidth + 'px');
                $this.css('borderStyle', 'solid');
                $this.css('backgroundColor', optWidget.backgroundColor);
            }
        });
    };
})(jQuery);
