var g_xPieCharts = new Object();
var g_xPieChartSizes = new Object();

var g_xBarGraphs = new Object();
var g_xBarGraphSizes = new Object();

function AddPieChartItem(strPieChartId, strLabel, lData, lColor){
    var xObj = new Object();
    xObj.label = strLabel;
    xObj.data = lData;
    xObj.color = lColor;

    if( g_xPieCharts[strPieChartId] ) {
        g_xPieCharts[strPieChartId][g_xPieChartSizes[strPieChartId]] = xObj;
        g_xPieChartSizes[strPieChartId]++;
    } else {
        g_xPieCharts[strPieChartId] = new Object();
        g_xPieCharts[strPieChartId][0] = xObj;
        g_xPieChartSizes[strPieChartId] = 1;
    }
}

function SimplePieChart_Ready(strPieChartId){
    ProxySimplePieChart_Plot(g_xPieCharts[strPieChartId], strPieChartId);
}

function EmbedSmallBarGraph(strDivName, strGraphId)
{
   AC_FL_RunContent(
         'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
         'width', '218',
         'height', '120',
         'src', 'SimpleBarGraph',
         'quality', 'high',
         'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
         'align', 'middle',
         'play', 'true',
         'loop', 'true',
         'scale', 'showall',
         'wmode', 'window',
         'devicefont', 'false',
         'id', 'SimpleBarGraph' + strGraphId,
         'wmode', 'transparent',
         'bgcolor', '#545454',
         'name', 'SimpleBarGraph' + strGraphId,
         'menu', 'true',
         'allowFullScreen', 'false',
         'allowScriptAccess','sameDomain',
         'movie', '/flash/calculators/SimpleBarGraphSmall?id='+ escape(strGraphId),
         'salign', ''
         );
}

function EmbedMedianAgeBarGraph(strDivName, strGraphId)
{
   AC_FL_RunContent(
         'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
         'width', '500',
         'height', '180',
         'src', 'SimpleBarGraph',
         'quality', 'high',
         'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
         'align', 'middle',
         'play', 'true',
         'loop', 'true',
         'scale', 'showall',
         'wmode', 'window',
         'devicefont', 'false',
         'id', 'SimpleBarGraph' + strGraphId,
         'wmode', 'transparent',
         'bgcolor', '#545454',
         'name', 'SimpleBarGraph' + strGraphId,
         'menu', 'true',
         'allowFullScreen', 'false',
         'allowScriptAccess','sameDomain',
         'movie', '/flash/calculators/SimpleBarGraph?id='+ escape(strGraphId),
         'salign', ''
         );
}

function ProxySimpleBarGraphWithId_Setup( aHorizontal, aVertical, strGraphId )
{
   var pChart = window['SimpleBarGraph' + strGraphId];
   if ( !pChart && window.document ) {
      pChart = window.document['SimpleBarGraph' + strGraphId];
   }
   if ( pChart ) {
      pChart.SimpleBarGraph_Setup( aHorizontal, aVertical );
   }
   return false;
}
function ProxySimpleBarGraphWithId_Plot( aData, strGraphId )
{
   var pChart = window['SimpleBarGraph' + strGraphId];
   if ( !pChart && window.document ) {
      pChart = window.document['SimpleBarGraph' + strGraphId];
   }
   if ( pChart ) {
      pChart.SimpleBarGraph_Plot( aData );
   }
   return false;
}


function AddSmallBarGraphItem( strGraphId, strLabel, lData, lColor ){
    var xObj = new Object();
    xObj[1] = lData;
    xObj['label'] = strLabel;                   
    xObj['color'] = lColor;                   
    xObj['width'] = 40;

    if( g_xBarGraphs[strGraphId] ) {
       xObj['offset'] = g_xBarGraphSizes[strGraphId] - 1.5;
       g_xBarGraphs[strGraphId][g_xBarGraphSizes[strGraphId]] = xObj;
       g_xBarGraphSizes[strGraphId]++;
    } else {
       xObj['offset'] = 0 - 1.5;
       g_xBarGraphs[strGraphId] = new Object();
       g_xBarGraphs[strGraphId][0] = xObj;
       g_xBarGraphSizes[strGraphId] = 1;
    }
}


function SimpleBarGraph_Ready(strGraphId){
   if( strGraphId == 'dwelling') {
      processDwellingBarGraph(strGraphId);
   } else if( strGraphId == "medianage" ){
      processMedianAgeGraph(strGraphId);
   }
}

function processDwellingBarGraph(strGraphId){
    var iTotal = 0;
    var iCount = 0;
    for( var i in g_xBarGraphs[strGraphId]) {
        iTotal += g_xBarGraphs[strGraphId][i][1];
        iCount++;
    }

    var oVert = new Object();
    oVert['label_prefix'] = '$';   
    oVert['padding'] = 10;
    oVert['offset'] = 0;
    oVert['min'] = 0;
    oVert['increment'] = (iTotal / 7);
    oVert['ticks'] = 7;
    oVert['topbottom'] = true;
    oVert['showlabels'] = false;
    oVert['css'] = ".label { font-family: Arial; font-size: 1; font-weight: bold; color: #FFFFFF; text-align: right;}";

    var oHorz = new Object();
    oHorz['padding'] = 00;
    oHorz['offset'] = 00;   
    oHorz['legend'] = '';
    oHorz['min'] = 10;
    oHorz['increment'] = 213450;
    oHorz['ticks'] = iCount;
    oHorz['grid'] = false;
    oHorz['showlabels'] = false;
    oHorz['css'] = ".label { font-family: Arial; font-size: 12; font-weight: bold; color: #000000; text-align: center;}";
    ProxySimpleBarGraphWithId_Setup( oHorz, oVert, strGraphId );


    for( var i in g_xBarGraphs[strGraphId]) {
       ProxySimpleBarGraphWithId_Plot(g_xBarGraphs[strGraphId][i], strGraphId);
    }
}

function processMedianAgeGraph(strGraphId){
    var iTotal = 0;

    var oVert = new Object();
    oVert['padding'] = 10;
    oVert['offset'] = 0;
    //oVert['legend'] = '<font color="#FFFFFF" size="13" face="ARIAL"><b></b></font>';
    //oVert['label_prefix'] = '';   
    oVert['min'] = 0;
    oVert['increment'] = 300;
    oVert['ticks'] = 8;
    oVert['grid'] = true;
    oVert['showlabels'] = false;
    oVert['css'] = ".label { font-family: Arial; font-size: 12; font-weight: bold; color: #FFFFFF; text-align: right;}";

    var oHorz = new Object();
    oHorz['padding'] = 00;
    oHorz['offset'] = 00;   
    //oHorz['legend'] = '<font color="#000000" size="13" face="ARIAL"><b></b></font>';
    oHorz['legend'] = '';
    //oHorz['label_prefix'] = '';
    oHorz['min'] = 0;
    oHorz['increment'] = 0;
    oHorz['ticks'] = 18;
    oHorz['grid'] = false;
    oHorz['showlabels'] = false;
    oHorz['css'] = ".label { font-family: Arial; font-size: 12; font-weight: bold; color: #000000; text-align: center;}";
    ProxySimpleBarGraphWithId_Setup( oHorz, oVert, strGraphId );


    ProxySimpleBarGraphWithId_Plot(g_xBarGraphs[strGraphId][0], strGraphId);
}

