  function draw_graph(th){
           tpid=th.attr('pid');
           $('#graph').html('<div id="graph_cont"></div><div id="graph_text"></div><i></i>');
           checklist=[];
           var graph_ok=0;
           $('.check'+tpid).each(function(){
            if($(this).attr('checked')) {checklist[$(this).attr('pid')]=1; graph_ok=1;} else
                checklist[$(this).attr('pid')]=0;
           });
          // console.log(checklist);
           if(graph_ok==0) {alert(not_selected);return false;}
           chart_title=th.attr('title');
        var ttop=(th.position().top+146);
        $('#overlay').fadeIn('fast',function(){
            $('#graph').css({top:ttop+'px'}).fadeIn(500);
        });

              var pid=th.attr('pid');
        // Square with index color
        $('.color-preview').each(function() {
            var
                $this = $(this),
                // Compute top margin
                marginTop = ($this.parent().height() - $this.height()) / 2;

            $this
                .css('background-color', '#' + $this.data('color').replace(/\"/g, ''))
                .css('margin-top', marginTop + 1);
        });

        // Tenge sign backlight on hover
        $('a.currency-link').hover(
            function() {
                $(this).find('span:first').attr('class', 'tenge-sign-hover');
            },
            function() {
                $(this).find('span:first').attr('class', 'tenge-sign');
            }
        );


        // Highcharts for indexes
        $.getJSON('/main/quotes/'+pid, function(data) {
            if (data.length > 0) {
                // Set colors
                Highcharts.setOptions({
                    /*colors: $.map(data, function(info) {
                        return '#' + info['color'];
                    }),*/
                    lang: {
                        months: $.l10n.months,
                        weekdays: $.l10n.days
                    }
                });
                $('#ttable').remove();
                ttable='<table id="ttable">';
                $.map(data, function(info) {
                        ttable+='<tr>';
                        ttable+='<td class="legend" style="background:#'+info['color']+'"></td>';
                        ttable+='<td>'+info['name']+'</td>';
                        ttable+='</tr>';
                    });
                ttable+='</table>';
              //  console.log(ttable);
                // Generate series
                var series = [];
                var i2=0;
                $.each(data, function(idx, info) {
                    var
                        changes = info['changes'],
                        origin = changes[0][1],
                        result = [];

                    for (i = 1; i < changes.length; i++) {
                        // Compute change
                        diff = origin - changes[i][1];
                        diffPct = (diff / changes[i][1]) * 100;

                        if (isNaN(diffPct) || !isFinite(diffPct)) {
                            diffPct = 0;
                        } else {
                            diffPct = Math.round(diffPct * 100) / 100;
                        }

                        origin = changes[i][1];

                        // Generate date
                        dParts = changes[i][0].split('-');
                        result.push([
                            Date.UTC(dParts[0], dParts[1] - 1, dParts[2]),
                            diffPct
                        ]);
                    }
                    if(checklist[i2]==1)
                    series.push({
                        name: info['name'],
                        data: result,
                        color:'#'+info['color']
                    });
                i2++;
                });

                // Display chart
                chart = new Highcharts.Chart({
                    chart: {
                        renderTo: 'graph_cont',
                        defaultSeriesType: 'line'
                        // alignTicks: false
                    },
                    credits: {
                        enabled: false
                    },
                    legend: {
                        enabled: false
                    },
                    plotOptions: {
                        series: {
                            lineWidth: 1,
                            pointInterval: 3600000
                        }
                    },
                    title: {
                        text: chart_title
                    },
                    xAxis: {
                        gridLineWidth: 1,
                        type : 'datetime'
                    },
                    yAxis: {
                        endOnTick: false,
                        maxPadding: 0.1,
                        // minPadding: 0,
                        title: {
                            text: ''
                        },
                        labels: {
                           enabled: true,
                           formatter: function() {
                               return this.value + '%';
                           }
                        }
                    },


                    exporting: false,
                    series: series
                });
              /*  for(i=0;i<checklist.length;i++)
                    {
                        if(checklist[i]==0) chart.series[i].hide();
                    }*/
                $("#graph_cont").after(ttable);
                var iii=0;
                $('#ttable tr').each(function(){
                    if(checklist[iii]==0) $(this).remove();
                    iii++;
                });
            }
        });
       return false; }
(function($) {
    $(document).ready(function() {
       $.l10n.init($('#localization'));
     
    });
})(jQuery);

