
var mychartobj = null; 

document.observe("dom:loaded", function() {

  // initially hide all containers for tab content

  

  //$("instructions").hide();

  

  var mychart = new Chart(1, 63, 'chart_pane', 'hc_chart', 4);

    mychartobj = mychart;

   mychart.setJsonUrl('json_cause_age_gender.php');
   mychart.setTitleText('USA Cause of Death by Age');
   mychart.addParam ('sel', 'text', 'sel');
   mychart.addParam ('sex', 'text', 'sex');
   mychart.addParam ('country', 'text', 'country');

   mychart.addVariable ('name', 'Name', 'hc_name', 'text', false, false);
   mychart.addVariable ('r_d', 'Rnk', 'hc_rank', 'text', false, false);
   mychart.addVariable ('d', 'Deaths', 'hc_deaths_big', 'text', false, false);
   mychart.addVariable ('r_d_0_14', 'Rnk', 'hc_rank', 'text', false, false);
   mychart.addVariable ('d_0_14', 'Deaths', 'hc_deaths', 'text', false, false);
   mychart.addVariable ('r_d_15_24', 'Rnk', 'hc_rank', 'text', false, false);
   mychart.addVariable ('d_15_24', 'Deaths', 'hc_deaths', 'text', false, false);
   mychart.addVariable ('r_d_25_34', 'Rnk', 'hc_rank', 'text', false, false);
   mychart.addVariable ('d_25_34', 'Deaths', 'hc_deaths', 'text', false, false);
   mychart.addVariable ('r_d_35_44', 'Rnk', 'hc_rank', 'text', false, false);
   mychart.addVariable ('d_35_44', 'Deaths', 'hc_deaths', 'text', false, false);
   mychart.addVariable ('r_d_45_54', 'Rnk', 'hc_rank', 'text', false, false);
   mychart.addVariable ('d_45_54', 'Deaths', 'hc_deaths', 'text', false, false);
   mychart.addVariable ('r_d_55_64', 'Rnk', 'hc_rank', 'text', false, false);
   mychart.addVariable ('d_55_64', 'Deaths', 'hc_deaths', 'text', false, false);
   mychart.addVariable ('r_d_65_74', 'Rnk', 'hc_rank', 'text', false, false);
   mychart.addVariable ('d_65_74', 'Deaths', 'hc_deaths', 'text', false, false);
   mychart.addVariable ('r_d_75', 'Rnk', 'hc_rank', 'text', false, false);
   mychart.addVariable ('d_75', 'Deaths', 'hc_deaths_big', 'text', false, false);  

   
  
   mychart.createPane();
   mychart.clear();
   
   /* $$('a.instructions_button').first().observe("click", function(event)
		{
			event.stop();
			var popIt = new PopIt($('instruction_text').innerHTML, 
			{
				title: 'USA DATA GRID INSTRUCTIONS',
				height: 250,
				width: 500, 
				isMinimizable: false,
				isMaximizable: false,
				offsetTop: 200,
				offsetLeft: -90
				//className: $('themeSelect').value
			});
			//popIt.updateStatusText("Instructions for how to use this tool.");
		});*/
   
	changeColour('flash');
	setInterval('updateClock()', 1000 );
	setTimeout(startup, 2);

});

 

 function startup()

 {

	 mychartobj.updateData();

 }

 

 

 

function updateChartData(sel){

	$("sel").value = sel;
	mychartobj.updateData();
}

function changeColour(elementId) {

    var interval = 500;
    var colour1 = "#ff0000"
    var colour2 = "#000000";
    if (document.getElementById && mychartobj.animateselect ) {

        var element = document.getElementById(elementId);
        element.style.color = (element.style.color == colour1) ? colour2 : colour1;
        setTimeout("changeColour('" + elementId + "')", interval);
    }
	else{

		var element = document.getElementById(elementId);
		element.style.color =  colour1;
	}
}

 

function updateClock ( ){

  var currentTime = new Date ( );
  var currentHours = currentTime.getHours ( );
  var currentMinutes = currentTime.getMinutes ( );
  var currentSeconds = currentTime.getSeconds ( );


  // Pad the minutes and seconds with leading zeros, if required

  currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
  currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds; 

  // Choose either "AM" or "PM" as appropriate

  var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";

  // Convert the hours component to 12-hour format if needed

  currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;

 

  // Convert an hours component of "0" to "12"

  currentHours = ( currentHours == 0 ) ? 12 : currentHours;

 

  // Compose the string for display

  var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;

 

  // Update the time display

  $('time_pane').innerHTML = currentTimeString;

}

var popup_visible = false;

function open_instructions()

{

	

	if (popup_visible == false)

	{

		$("instructions").show();

		popup_visible = true

	}

	else

	{

		$("instructions").hide();

		popup_visible = false;

	}

	

	//window.open('usa_data_grid_instructions.php', 'instructions', 'scrollbars=no,width=630px,height=200px;top=100px');

}
