var Chart = Class.create({
  
    initialize: function(ColomnCount, RowCount, Parent, Id, InsertCount) {
        this.hcParamArray = new Array();
        this.hcParamTypeArray = new Array();
        this.hcParamElementArray = new Array();
        this.hcInsertCount = InsertCount;
        this.hcInsertCounter = 1;
        this.hcColomnCount  = ColomnCount;
        this.hcRowCount = RowCount;
        this.hcParent = Parent ;
        this.hcId = Id;
        this.chVariableArray = new Array();
        this.chVariableLabelArray = new Array();
        this.chVariableClassArray = new Array();
        this.chVariableTypeArray = new Array();
        this.chVariableUpperArray = new Array();
        this.chVariableCombineArray = new Array();
        this.hcElement = null;
        this.chartdata = null;
        this.inprogress = false;
        this.ajaxobg = null;
        this.animI = 0;
        this.animJ = 0;
        this.animM = 0;
        this.hcStaticValue = new Array();
        this.hcJsonUrl = "json_static.php";
        this.CountMinArray = null;
        this.CountMaxArray = null;
        this.minValuesArray = Array();
        this.maxValuesArray = Array();
	
        this.useNoData = false;
        this.chartColored = false;
        this.primaryVariable = 'value';
        this.displayVariable = 'name';
        this.CountryCounter = 0;
        this.selColomnEl = "sel";
        this.hRowPopMale = null;
        this.hRowPopFemale = null;
        this.hRowPopBoth = null;
        this.isFirst = true;
        this.fillNext = true;
        this.Quie = false;
        this.TitleText = "";
        this.selColorArray = new Array('#00FF00', '#00FF00', '#00FF00');
        this.selectedColor = 1;
        this.animateselect =  true;
        this.updatePops = false;
        this.ColorBlack="#000000";
        this.ColorWhite="#ffffff";
        this.ColorGray="#333333";
        this.ColorDarkGray ="#222222";
        this.GenderButtonColor = "#b4b5b5";
  
        this.highlights = ['Poisonings', 'Road Traffic Accidents'];
        this.highlights_col = null;
        this.highlights_color = '#FFFF00';
        this.highlights_color_ = '#000000';
        this.highlights_color_text = '#000000';
        this.highlights_color_text_ = '#FFFFFF';
	
        this.useCommas = false;

	
    },
	
    addCommas:function (nStr)
    {
        nStr += '';
        x = nStr.split('.');
        x1 = x[0];
        x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        return x1 + x2;
    },
	
    setCommas:function (useCommas)
    {
        this.useCommas = useCommas;
    },
	
    setHighlights:function(highlights_col, highlights_color, highlights_color_, highlights_color__, highlights_color_text, highlights_color_text_, highlights_color_text__)
    {
        this.highlights_col = highlights_col;
        this.highlights_color = highlights_color;
        this.highlights_color_ = highlights_color_;
        this.highlights_color__ = highlights_color__;
        this.highlights_color_text = highlights_color_text;
        this.highlights_color_text_ = highlights_color_text_;
        this.highlights_color_text__ = highlights_color_text__;
		
    },
  
    setTitleText : function (TitleText)
    {
        this.TitleText = TitleText;
    },
  
    setSelColomn : function (selColomnEl)
    {
        this.selColomnEl = selColomnEl;
    },
    setJsonUrl : function (Url){
        this.hcJsonUrl = Url;
    },
    addVariable : function ( Variable, VariableLabel, VariableClass, VariableType, VariableUpper, VariableCombine) {
        this.chVariableArray.push(Variable);
        this.chVariableLabelArray.push(VariableLabel);  
        this.chVariableClassArray.push(VariableClass);  
        this.chVariableTypeArray.push(VariableType);  
        this.chVariableUpperArray.push(VariableUpper); 
        this.chVariableCombineArray.push(VariableCombine); 
	
	
    },
    createPane : function() {
	  
        var headcounter = 0;
        var tbl = document.createElement('table');
        tbl.id = 'hc_table';
        tbl.border = 0;
        tbl.cellSpacing =0;
        tbl.borderColor = "Black";
        $(this.hcParent).appendChild(tbl);
	
	
	
        var tblbody = document.createElement('TBODY');
        //tblbody.id = this.Id;
        tbl.appendChild (tblbody);
        this.hcElement = tblbody;
	
	
        var tblhead = document.createElement('THEAD');
        tbl.appendChild (tblhead);
        this.tblHead = tblhead;

        var tblfoot = document.createElement('TFOOT');
        tbl.appendChild (tblfoot);
        this.tblFoot = tblfoot;

        var hrow001 = tblhead.insertRow(headcounter);
        headcounter++
	
        var col001 = hrow001.insertCell(0);
        col001.style.width = 173;
        col001.className = 'hc_header_instructions';
        col001.colSpan = 2;
        var currentTime = new Date()
        var month = currentTime.getMonth() + 1
        var day = currentTime.getDate()
        var year = currentTime.getFullYear()

        col001.innerHTML  = month + "/" + day + "/" + year;
        var col002 = hrow001.insertCell(1);
        col002.colSpan = 18;
        col002.innerHTML  = "TOTAL DEATHS BY AGE AND GENDER";
        col002.className = 'hc_header_title';	
	
        var hrow0 = tblhead.insertRow(headcounter);
        headcounter++
        var col01 = hrow0.insertCell(0);
	
        col01.innerHTML  = "&nbsp";
        col01.id  = "time_pane";
        col01.style.width = 173;
        col01.className = 'header_cause_top';
        col01.colSpan = 2;
        var col02 = hrow0.insertCell(1);
        col02.colSpan = 18;
        col02.innerHTML  = "<div style='padding:2px 0px 4px 0px;'><span style='font-size:11px;' >Choose gender select age</span>&nbsp;&nbsp;&nbsp;&nbsp;<a id='btn_sex_female' class='btn_green btn_green_sel' href='javascript:mychartobj.gender_response_female();' >Female</a> <a id='btn_sex_male' class='btn_green' href='javascript:mychartobj.gender_response_male();' >Male</a> <a id='btn_sex_both' class='btn_green' href='javascript:mychartobj.gender_response_both();' >Both</a>&nbsp;&nbsp;&nbsp;&nbsp;<span style='font-size:11px;' >Choose gender select age</span></div>";
        col02.className = 'header_cause_top_right';
	
        var hrow1 = tblhead.insertRow(headcounter);
        headcounter++;
        var coll1 = hrow1.insertCell(0);
        coll1.rowSpan = 2;
        coll1.colSpan = 2;
        coll1.innerHTML  = "CAUSE OF DEATH <br>RANKING";
        coll1.style.color = '#00FF00';
        coll1.className = 'header_cause';
	
        var collr_d = hrow1.insertCell(1);
        collr_d.innerHTML = "<a href=\"javascript:updateChartData('d')\">All Ages</a>";
        collr_d.colSpan = 2;
        collr_d.className = "header_ages";
	
        var collr_d_0_14 = hrow1.insertCell(2);
        collr_d_0_14.innerHTML = "<a href=\"javascript:updateChartData('d_0_14')\">0 - 14</a>";
        collr_d_0_14.colSpan = 2;
        collr_d_0_14.className = "header_ages";
	
        var collr_d_15_24 = hrow1.insertCell(3);
        collr_d_15_24.innerHTML = "<a href=\"javascript:updateChartData('d_15_24')\">15 - 24</a>";
        collr_d_15_24.colSpan = 2;
        collr_d_15_24.className = "header_ages";
	
        var collr_d_25_34 = hrow1.insertCell(4);
        collr_d_25_34.innerHTML = "<a href=\"javascript:updateChartData('d_25_34')\">25 - 34</a>";
        collr_d_25_34.colSpan = 2;
        collr_d_25_34.className = "header_ages";	
	
        var collr_d_35_44 = hrow1.insertCell(5);
        collr_d_35_44.innerHTML = "<a href=\"javascript:updateChartData('d_35_44')\">35 - 44</a>";
        collr_d_35_44.colSpan = 2;
        collr_d_35_44.className = "header_ages";	
	
        var collr_d_45_54 = hrow1.insertCell(6);
        collr_d_45_54.innerHTML = "<a href=\"javascript:updateChartData('d_45_54')\">45 - 54</a>";
        collr_d_45_54.colSpan = 2;
        collr_d_45_54.className = "header_ages";	
	
        var collr_d_55_64 = hrow1.insertCell(7);
        collr_d_55_64.innerHTML = "<a href=\"javascript:updateChartData('d_55_64')\">55 - 64</a>";
        collr_d_55_64.colSpan = 2;
        collr_d_55_64.className = "header_ages";	
	
        var collr_d_65_74 = hrow1.insertCell(8);
        collr_d_65_74.innerHTML = "<a href=\"javascript:updateChartData('d_65_74')\">65 - 74</a>";
        collr_d_65_74.colSpan = 2;
        collr_d_65_74.className = "header_ages";	
	
        var collr_d_75 = hrow1.insertCell(9);
        collr_d_75.innerHTML = "<a href=\"javascript:updateChartData('d_75')\">75 +</a>";
        collr_d_75.colSpan = 2;
        collr_d_75.className = "header_ages";	
	
	
	
        footcounter = 0;
	
        var hrow1 = tblfoot.insertRow(footcounter);
        footcounter++;
        var coll1 = hrow1.insertCell(0);
        //coll1.rowSpan = 2;
        coll1.colSpan = 2;
        coll1.innerHTML  = this.TitleText;
        coll1.style.color = '#00FF00';
        coll1.className = 'header_cause';
	
        var collr_d = hrow1.insertCell(1);
        collr_d.innerHTML = "<a href=\"javascript:updateChartData('d')\">All Ages</a>";
        collr_d.colSpan = 2;
        collr_d.className = "header_ages_red";
	
        var collr_d_0_14 = hrow1.insertCell(2);
        collr_d_0_14.innerHTML = "<a href=\"javascript:updateChartData('d_0_14')\">0 - 14</a>";
        collr_d_0_14.colSpan = 2;
        collr_d_0_14.className = "header_ages_red";
	
        var collr_d_15_24 = hrow1.insertCell(3);
        collr_d_15_24.innerHTML = "<a href=\"javascript:updateChartData('d_15_24')\">15 - 24</a>";
        collr_d_15_24.colSpan = 2;
        collr_d_15_24.className = "header_ages_red";
	
        var collr_d_25_34 = hrow1.insertCell(4);
        collr_d_25_34.innerHTML = "<a href=\"javascript:updateChartData('d_25_34')\">25 - 34</a>";
        collr_d_25_34.colSpan = 2;
        collr_d_25_34.className = "header_ages_red";	
	
        var collr_d_35_44 = hrow1.insertCell(5);
        collr_d_35_44.innerHTML = "<a href=\"javascript:updateChartData('d_35_44')\">35 - 44</a>";
        collr_d_35_44.colSpan = 2;
        collr_d_35_44.className = "header_ages_red";	
	
        var collr_d_45_54 = hrow1.insertCell(6);
        collr_d_45_54.innerHTML = "<a href=\"javascript:updateChartData('d_45_54')\">45 - 54</a>";
        collr_d_45_54.colSpan = 2;
        collr_d_45_54.className = "header_ages_red";	
	
        var collr_d_55_64 = hrow1.insertCell(7);
        collr_d_55_64.innerHTML = "<a href=\"javascript:updateChartData('d_55_64')\">55 - 64</a>";
        collr_d_55_64.colSpan = 2;
        collr_d_55_64.className = "header_ages_red";	
	
        var collr_d_65_74 = hrow1.insertCell(8);
        collr_d_65_74.innerHTML = "<a href=\"javascript:updateChartData('d_65_74')\">65 - 74</a>";
        collr_d_65_74.colSpan = 2;
        collr_d_65_74.className = "header_ages_red";	
	
        var collr_d_75 = hrow1.insertCell(9);
        collr_d_75.innerHTML = "<a href=\"javascript:updateChartData('d_75')\">75 +</a>";
        collr_d_75.colSpan = 2;
        collr_d_75.className = "header_ages_red";
	






        var hrowFemale = tblfoot.insertRow(footcounter);
        hrowFemale.className = 'hc_head_sex';
        this.hRowPopFemale = hrowFemale;
        footcounter++;	
        hrowFemale.insertCell(0);
        hrowFemale.insertCell(1);

        for (var i = 2;i< 11;i++)
        {
            var hrowMale_ = hrowFemale.insertCell(i);
            hrowMale_.colSpan = 2;
        }
	
        var hrowMale = tblfoot.insertRow(footcounter);
        hrowMale.className = 'hc_head_sex';

        this.hRowPopMale = hrowMale;
        footcounter++;	
        hrowMale.insertCell(0);
        hrowMale.insertCell(1);
	
        for (var i = 2;i< 11;i++)
        {
            var hrowMale_ = hrowMale.insertCell(i);
            hrowMale_.colSpan = 2;
        }
	
	
	
        var hrowBoth = tblfoot.insertRow(footcounter);
        hrowBoth.className = 'hc_head_sex';
        this.hRowPopBoth = hrowBoth;
        footcounter++;	
        hrowBoth.insertCell(0);
        hrowBoth.insertCell(1);
        for (var i = 2;i< 11;i++)
        {
            var hrowMale_ = hrowBoth.insertCell(i);
            hrowMale_.colSpan = 2;
        }




	
	
        var hrow = tblhead.insertRow(headcounter);
        headcounter++
        var counter = 0;
	
        for (var m =0;m< this.hcColomnCount;m++)
        {
            for (var l=0;l<this.chVariableArray.length;l++)
            {
                if (l == 0 && m == 0)
                {
                }
                else
                {
                    //col = hrow.insertCell(m*this.chVariableArray.length+l);
				
                    if (!this.chVariableCombineArray[l-1])
                    {
					
                        col = hrow.insertCell(counter);
                        col.className = 'hc_header';
                        if (this.chVariableLabelArray[l] != '')
                        {
                            col.innerHTML = this.chVariableLabelArray[l];	
                        }
                        else
                        {
                            col.innerHTML = "";
                        }
					
                        if (this.chVariableCombineArray[l] )
                        {
						
                            col.colSpan = 2;
                        }
                        counter ++ ;
					
					
                    }
				
                }
            }
        }

        var row = null;
        var col = null;
        for (var i = 0; i< this.hcRowCount;i++)
        {
		
            row = tblbody.insertRow(i);
            for (var j =0;j< this.hcColomnCount;j++)
            {
			
                for (var k=0;k<this.chVariableArray.length;k++)
                {
                    col = row.insertCell(j*this.chVariableArray.length+k);
                    col.className = this.chVariableClassArray[k];
                    if (k == 0 && j == 0)
                    {
                        col.className += " , hc_first_hor";
                    }
                    if (k == 0)
                    {
                        col.colSpan = 2;
                    }
				
                    col = null;
                }
            }
            row = null;
        }
	
	
    },
  
    clear : function ()
    {
        for (var i = 0; i< this.hcRowCount;i++)
        {
		
            for (var j =0;j< this.hcColomnCount;j++)
            {
                for (k =0;k<this.chVariableArray.length;k++)
                {
			
                    this.hcElement.rows[i].cells[j*this.chVariableArray.length+k].innerHTML = "&nbsp";
                    this.hcElement.rows[i].cells[j*this.chVariableArray.length+k].style.backgroundColor = this.ColorBlack;
                    this.hcElement.rows[i].cells[j*this.chVariableArray.length+k].className = this.chVariableClassArray[k]; 
				
                    this.hcElement.rows[i].cells[j*this.chVariableArray.length+k].style.borderColor = this.ColorGray;
                    if (k>0)
                    {
                        this.hcElement.rows[i].cells[j*this.chVariableArray.length+k].style.color = this.ColorWhite;	
                        this.hcElement.rows[i].cells[j*this.chVariableArray.length+k].style.fontWeight = 'normal';
                    }
				
				
                }
            }	
        }
    },
  
    addParam : function (Param, ParamType, ParamElement){
        this.hcParamArray.push(Param);
        this.hcParamTypeArray.push(ParamType);
        this.hcParamElementArray.push(ParamElement);
    },
  
    updateData : function ()
    {
	
        if (!this.inprogress)
        {
		
            this.clear();
            this.inprogress = true;
            var tmp_params = "";
		 
		
            for (var i=0;i<this.hcParamArray.length;i++)
            {
			
                if (this.hcParamTypeArray[i] == 'combo')
                {
                    tmp_params += this.hcParamArray[i]+"="+$(this.hcParamElementArray[i]).options[$(this.hcParamElementArray[i]).selectedIndex].value+"&";
                    this.hcStaticValue[this.hcParamArray[i]] = $(this.hcParamElementArray[i]).options[$(this.hcParamElementArray[i]).selectedIndex].value;
                }
                if (this.hcParamTypeArray[i] == 'text')
                {
				
                    tmp_params += this.hcParamArray[i]+"="+$(this.hcParamElementArray[i]).value+"&";
                    this.hcStaticValue[this.hcParamArray[i]] = $(this.hcParamElementArray[i]).value;
                }
            }

            this.ajaxobg = new Ajax.Request(this.hcJsonUrl, {
                method:'get',
                parameters: tmp_params,
                onSuccess: function(transport){
                    var json = transport.responseText.evalJSON();
                    this.chartdata = json;
				
                    this.dataLoadCompleate();
                }.bind(this),
                onException: function(transport,e){
                    alert(e.message+ e.name);
                }
   
            }); 
        }
        else
        {
            this.Quie = true;
        //alert("Wait Data Loading ...");
        }
    },
  
    dataLoadCompleate : function (){
	
        this.drawPane();
	
    },

    drawPane : function (){
	 
        this.animI = 0;
        this.animJ = 0;
        this.animM = 0;
        this.CountryCounter = 0;
        if (this.isFirst)
        {
            this.addPops();
            this.isFirst = false;
        }
        if (this.updatePops)
        {
            this.addPops();
            this.updatePops = false;
        }
	
        this.drawItem();
    },
  
    gender_response_male : function ( )
    {
        mychartobj.selectedColor = 1;
		  
        $('sex').value = 'male';
        $('hc_head_sex_male').firstChild.style.backgroundColor = mychartobj.selColorArray[mychartobj.selectedColor];
        $('hc_head_sex_female').firstChild.style.backgroundColor = mychartobj.GenderButtonColor;
        $('hc_head_sex_both').firstChild.style.backgroundColor = mychartobj.GenderButtonColor;
		  
        mychartobj.hRowPopMale.style.backgroundColor = mychartobj.selColorArray[mychartobj.selectedColor];
        mychartobj.hRowPopMale.style.color  =  mychartobj.ColorBlack;
        mychartobj.hRowPopMale.style.fontWeight  =  'bold';
		  
        mychartobj.hRowPopFemale.style.backgroundColor = mychartobj.ColorBlack;
        mychartobj.hRowPopFemale.style.color  =  mychartobj.ColorWhite;
        mychartobj.hRowPopFemale.style.fontWeight  =  'normal';
		  
        mychartobj.hRowPopBoth.style.backgroundColor = mychartobj.ColorBlack;
        mychartobj.hRowPopBoth.style.color  =  mychartobj.ColorWhite;
        mychartobj.hRowPopBoth.style.fontWeight  =  'normal';
		  
        mychartobj.animateselect = false;
		  
        update_buttons('male');
        mychartobj.updateData();
    },
    gender_response_female : function ( )
    {
        mychartobj.selectedColor = 2;
		 
        $('sex').value = 'female';
        $('hc_head_sex_female').firstChild.style.backgroundColor = mychartobj.selColorArray[mychartobj.selectedColor];
        $('hc_head_sex_male').firstChild.style.backgroundColor = mychartobj.GenderButtonColor;
        $('hc_head_sex_both').firstChild.style.backgroundColor = mychartobj.GenderButtonColor;

        mychartobj.hRowPopFemale.style.backgroundColor = mychartobj.selColorArray[mychartobj.selectedColor];
        mychartobj.hRowPopFemale.style.color  =  mychartobj.ColorBlack;
        mychartobj.hRowPopFemale.style.fontWeight  =  'bold';
		  
        mychartobj.hRowPopMale.style.backgroundColor = mychartobj.ColorBlack;
        mychartobj.hRowPopMale.style.color  =  mychartobj.ColorWhite;
        mychartobj.hRowPopMale.style.fontWeight  =  'normal';
		  
		  
        mychartobj.hRowPopBoth.style.backgroundColor = mychartobj.ColorBlack;
        mychartobj.hRowPopBoth.style.color  =  mychartobj.ColorWhite;
        mychartobj.hRowPopBoth.style.fontWeight  =  'normal';
		  
        mychartobj.animateselect = false;
		  
        update_buttons('female');
        mychartobj.updateData();
    },
    gender_response_both : function ( )
    {
        mychartobj.selectedColor = 0;
		 
        $('sex').value = 'both';
        $('hc_head_sex_both').firstChild.style.backgroundColor = mychartobj.selColorArray[mychartobj.selectedColor];
        $('hc_head_sex_female').firstChild.style.backgroundColor = mychartobj.GenderButtonColor;
        $('hc_head_sex_male').firstChild.style.backgroundColor = mychartobj.GenderButtonColor;

        mychartobj.hRowPopBoth.style.backgroundColor = mychartobj.selColorArray[mychartobj.selectedColor];
        mychartobj.hRowPopBoth.style.color  =  mychartobj.ColorBlack;
        mychartobj.hRowPopBoth.style.fontWeight  =  'bold';
		  
		  
        mychartobj.hRowPopMale.style.backgroundColor = mychartobj.ColorBlack;
        mychartobj.hRowPopMale.style.color  =  mychartobj.ColorWhite;
        mychartobj.hRowPopMale.style.fontWeight  =  'normal';
		  
		  
        mychartobj.hRowPopFemale.style.backgroundColor = mychartobj.ColorBlack;
        mychartobj.hRowPopFemale.style.color  =  mychartobj.ColorWhite;
        mychartobj.hRowPopFemale.style.fontWeight  =  'normal';
		  
        mychartobj.animateselect = false;
		  
        update_buttons('both');
        mychartobj.updateData();
    },
    addPops : function ()
    {
	  
        var pops = this.chartdata.chart.pops.popitem[0];
        this.hRowPopMale.id = 'hc_head_sex_male';
        this.hRowPopMale.className = 'hc_head_sex';
        this.hRowPopMale.cells[0].innerHTML = pops.name;
        this.hRowPopMale.cells[0].onclick = this.gender_response_male;
        this.hRowPopMale.cells[0].className = 'gray_bg';
        this.hRowPopMale.cells[0].style.backgroundColor = this.GenderButtonColor;//this.selColorArray[1];
        this.hRowPopMale.cells[1].innerHTML = 'POPULATION'; 
        this.hRowPopMale.cells[1].style.textAlign = 'center';
        this.hRowPopMale.cells[2].innerHTML = pops.p; 
        this.hRowPopMale.cells[3].innerHTML = pops.p_0_14;
        this.hRowPopMale.cells[4].innerHTML = pops.p_15_24;
        this.hRowPopMale.cells[5].innerHTML = pops.p_25_34;
        this.hRowPopMale.cells[6].innerHTML = pops.p_35_44;
        this.hRowPopMale.cells[7].innerHTML = pops.p_45_54;
        this.hRowPopMale.cells[8].innerHTML = pops.p_55_64;
        this.hRowPopMale.cells[9].innerHTML = pops.p_65_74;
        this.hRowPopMale.cells[10].innerHTML = pops.p_75;
        pops = this.chartdata.chart.pops.popitem[1];
        this.hRowPopFemale.id = 'hc_head_sex_female';
        this.hRowPopFemale.className = 'hc_head_sex';
        this.hRowPopFemale.cells[0].innerHTML = pops.name; 
	    
		
        this.hRowPopFemale.cells[0].onclick = this.gender_response_female;
        this.hRowPopFemale.cells[0].className = 'gray_bg';
        this.hRowPopFemale.cells[0].style.backgroundColor = "#0F0";//this.GenderButtonColor;//this.selColorArray[2];
	  
        this.hRowPopFemale.cells[1].innerHTML = 'POPULATION'; 
        this.hRowPopFemale.cells[1].style.textAlign = 'center';
        this.hRowPopFemale.cells[2].innerHTML = pops.p; 
        this.hRowPopFemale.cells[3].innerHTML = pops.p_0_14;
        this.hRowPopFemale.cells[4].innerHTML = pops.p_15_24;
        this.hRowPopFemale.cells[5].innerHTML = pops.p_25_34;
        this.hRowPopFemale.cells[6].innerHTML = pops.p_35_44;
        this.hRowPopFemale.cells[7].innerHTML = pops.p_45_54;
        this.hRowPopFemale.cells[8].innerHTML = pops.p_55_64;
        this.hRowPopFemale.cells[9].innerHTML = pops.p_65_74;
        this.hRowPopFemale.cells[10].innerHTML = pops.p_75;
        pops = this.chartdata.chart.pops.popitem[2];
        this.hRowPopBoth.id = 'hc_head_sex_both';
        this.hRowPopBoth.className = 'hc_head_sex_sel';
        this.hRowPopBoth.cells[0].innerHTML = pops.name; 
	    
		
        this.hRowPopBoth.cells[0].onclick = this.gender_response_both;
        this.hRowPopBoth.cells[0].className = 'gray_bg';
        this.hRowPopBoth.cells[0].style.backgroundColor = this.GenderButtonColor;//this.selColorArray[0];

	  
        this.hRowPopBoth.cells[1].innerHTML = 'POPULATION'; 
        this.hRowPopBoth.cells[1].style.textAlign = 'center';
        this.hRowPopBoth.cells[2].innerHTML = pops.p; 
        this.hRowPopBoth.cells[3].innerHTML = pops.p_0_14;
        this.hRowPopBoth.cells[4].innerHTML = pops.p_15_24;
        this.hRowPopBoth.cells[5].innerHTML = pops.p_25_34;
        this.hRowPopBoth.cells[6].innerHTML = pops.p_35_44;
        this.hRowPopBoth.cells[7].innerHTML = pops.p_45_54;
        this.hRowPopBoth.cells[8].innerHTML = pops.p_55_64;
        this.hRowPopBoth.cells[9].innerHTML = pops.p_65_74;
        this.hRowPopBoth.cells[10].innerHTML = pops.p_75;
	  
        if (this.isFirst)
        {
            this.hRowPopFemale.style.backgroundColor = this.selColorArray[this.selectedColor];
            this.hRowPopFemale.style.color  =  this.ColorBlack;
            this.hRowPopFemale.style.fontWeight  =  'bold';
		  
        }	  
    },
  
  
    itemClicked:function (event)
    {
        var args = $A(arguments);
        var is_in = false;
        this.highlights.each(function(item) {
            if  (item == args[0].name)
            {
                is_in  = true;
            }
        });
        if (is_in)
        {
            var td = args[1];
            td.setStyle({
                backgroundColor: this.highlights_color_.toString() ,
                color : this.highlights_color_text_.toString() 
            });
            for (i=0;i<18;i++)
            {
                td = td.next();
                if (td.getStyle('background-color') != 'rgb(0, 255, 0)' &&  td.getStyle('background-color') != 'rgb(51, 51, 51)' && td.style.backgroundColor != '#00ff00' && td.style.backgroundColor != '#333333' )
                {
                    td.setStyle({
                        backgroundColor: this.highlights_color__.toString() ,
                        color : this.highlights_color_text__.toString() 
                    });
                }
            }
            this.highlights = this.highlights.without(args[0].name);
        }
        else
        {
            this.highlights.push(args[0].name);
            var td = args[1];
            td.setStyle({
                backgroundColor: this.highlights_color.toString() ,
                color : this.highlights_color_text.toString() 
            });
            for (i=0;i<18;i++)
            {
                                                                    
                td = td.next();
                if (td.getStyle('background-color') != 'rgb(0, 255, 0)' &&  td.getStyle('background-color') != 'rgb(51, 51, 51)' && td.style.backgroundColor != '#00ff00' && td.style.backgroundColor != '#333333' )
                {
                    td.setStyle({
                        backgroundColor: '#222222' ,
                        color : '#FFFFFF' 
                    });
                }
            }                                                                
        }
    },
  
    drawItem : function (){
	  
        var country_item = this.chartdata.chart.countries.countryitem[this.animI];
        var img = null;
	
	
        var counterr = this.chVariableArray.length;
        var i = 1;
	
        if (!this.fillNext)
        {
            counterr = 1;
            i = 0;
        }
        for (i; i<counterr;i++)
        {

            if (this.chVariableArray[i] == $(this.selColomnEl).value )
            {
                this.hcElement.rows[this.animM].cells[this.animJ+i].style.backgroundColor = this.ColorGray;
                this.hcElement.rows[this.animM].cells[this.animJ+i].style.borderColor = this.ColorBlack;
                this.hcElement.rows[this.animM].cells[this.animJ+i].style.fontWeight = 'bold';
                this.hcElement.rows[this.animM].cells[this.animJ+i].style.color  = this.ColorWhite;
			
            }
            if (this.chVariableArray[i] == "r_"+$(this.selColomnEl).value )
            {
                this.hcElement.rows[this.animM].cells[this.animJ+i].style.backgroundColor = this.selColorArray[this.selectedColor];
                this.hcElement.rows[this.animM].cells[this.animJ+i].style.borderColor = this.ColorBlack;
                this.hcElement.rows[this.animM].cells[this.animJ+i].style.color = this.ColorBlack;
                this.hcElement.rows[this.animM].cells[this.animJ+i].style.fontWeight = 'bold';
            }
		
		
            if (i ==0)
            {
                this.hcElement.rows[this.animM].cells[this.animJ+i].style.borderColor = this.ColorBlack;
                this.hcElement.rows[this.animM].cells[this.animJ+i].style.backgroundColor = this.ColorDarkGray;
                this.hcElement.rows[this.animM].cells[this.animJ+i].style.color = this.ColorWhite;

            }
		
            if (this.chVariableTypeArray[i] == 'img')
            {
                this.hcElement.rows[this.animM].cells[this.animJ+i].innerHTML = "<img src='images/flags/"+country_item[this.chVariableArray[i]]+".png' width='16px' heigth='16px' >";
            }
            else if (this.chVariableTypeArray[i] == 'text')
            {
                if (country_item[this.chVariableArray[i]])
                {
                    if (this.chVariableUpperArray[i])
                    {
                        this.hcElement.rows[this.animM].cells[this.animJ+i].innerHTML = country_item[this.chVariableArray[i]].toUpperCase();
                    }
                    else
                    {
                        this.hcElement.rows[this.animM].cells[this.animJ+i].innerHTML = country_item[this.chVariableArray[i]];
                    }
                }
                        
                if  (this.highlights_col != null)
                {
					
                                        
                    var coll = this.hcElement.rows[this.animM].cells[this.animJ+i];
						
                    if  (this.highlights_col == i )
                    {
							
                        coll.style.cursor = 'pointer';
                        Event.stopObserving(coll);
                        Event.observe (coll , "click", this.itemClicked.bind(this,  country_item , coll));
							
                        var is_in = false;
                        this.highlights.each(function(item) {
                            if  (item == country_item.name)
                            {
                                is_in  = true;
                            }
                        });
							
                        if (is_in)
                        {
                            var td = coll;
												
                            td.setStyle({
                                backgroundColor: this.highlights_color.toString(),
                                color : this.highlights_color_text.toString() 
															
                            });
                                                                                                        
                            for (i=0;i<18;i++)
                            {
                                td = td.next();
                                if (td.getStyle('background-color') != 'rgb(0, 255, 0)' &&  td.getStyle('background-color') != 'rgb(51, 51, 51)' && td.style.backgroundColor != '#00ff00' && td.style.backgroundColor != '#333333' )
                                {
                                    td.setStyle({
                                        backgroundColor: '#222222' ,
                                        color : '#FFFFFF' 
                                    });
                                }
                            }
                        }
                        else
                        {
                                                                                                        
                        }
                    }
                }
					
					
                if (this.useCommas)
                {
                    this.hcElement.rows[this.animM].cells[this.animJ+i].innerHTML= this.addCommas (country_item[this.chVariableArray[i]]);
                }
                else
                {
                    this.hcElement.rows[this.animM].cells[this.animJ+i].innerHTML= country_item[this.chVariableArray[i]];
                }
                        
			
            }
            else if (this.chVariableTypeArray[i] == 'static')
            {
                this.hcElement.rows[this.animM].cells[this.animJ+i].innerHTML  = this.hcStaticValue[this.chVariableArray[i]];
            }
        }
	
        if (this.animM == this.hcRowCount-1)
        {
            this.animM = 0;
            this.animJ = this.animJ+this.chVariableArray.length;
        }
        else
        {
            this.animM++;
        }
        this.animI ++;
		
        this.CountryCounter ++;
        this.checkLatest();
    },
  
  
    checkLatest : function (){
	  
        if (this.Quie)
        {
            this.Quie = false;
            this.inprogress = false;	
            this.fillNext = true;
            this.updateData();
        }
        else
        {
	  
            if ( this.animI != this.chartdata.chart.countries.countryitem.length )
            {
					
                if (this.hcInsertCounter == this.hcInsertCount )
                {
                    this.hcInsertCounter = 1;
                    setTimeout(this.drawItem.bind(this, null), 1);
                }
                else
                {
                    this.hcInsertCounter ++;
                    this.drawItem();
                }
					
					
            }
            else
            {
                if (this.fillNext)
                {
                    this.fillNext = false;
						
                    this.drawPane();
						
                }
                else
                {
                    this.fillNext = true;
                    this.inprogress = false;	
                }
            }
        }
    }
  

}); 
