/*
 * Convert this div element to column chart
 */
function wsbs_columnchartify() {
	chart_id = $(this).attr('id');
	chart_file = $(this).attr('rel');
	chart_width = $(this).attr('w') || 520;
	chart_height = $(this).attr('h') || 380;
	// alert('columnchart:'+$(this).attr('id')+':'+$(this).attr('rel'));

	var so = new SWFObject("/scripts/amcharts/amcolumn.swf", "amcolumn", chart_width, chart_height, "8", "#FFFFFF");
	so.addVariable("path", "/scripts/amcharts/");
	so.addVariable("settings_file", encodeURIComponent("/scripts/amcharts/amcolumn_settings.xml"));
	so.addVariable("data_file", encodeURIComponent( chart_file ));
	so.write( this );
}


/*
 * Convert this div element to pie chart
 */
function wsbs_piechartify() {
	chart_id = $(this).attr('id');
	chart_file = $(this).attr('rel');
	chart_width = $(this).attr('w') || 520;
	chart_height = $(this).attr('h') || 380;
	// alert('piechart:'+$(this).attr('id')+':'+$(this).attr('rel'));

	var so = new SWFObject("/scripts/amcharts/ampie.swf", "ampie", chart_width, chart_height, "8", "#FFFFFF");
	so.addVariable("path", "/scripts/amcharts/");
	so.addVariable("settings_file", encodeURIComponent("/scripts/amcharts/ampie_settings.xml"));
	so.addVariable("data_file", encodeURIComponent( chart_file ));
	so.write( this );
}

/*
 * Convert this div element to line chart
 */
function wsbs_linechartify() {
	chart_id = $(this).attr('id');
	chart_file = $(this).attr('rel');
	chart_width = $(this).attr('w') || 520;
	chart_height = $(this).attr('h') || 380;
	// alert('piechart:'+$(this).attr('id')+':'+$(this).attr('rel'));

	var so = new SWFObject("/scripts/amcharts/amline.swf", "amline", chart_width, chart_height, "8", "#FFFFFF");
	so.addVariable("path", "/scripts/amcharts/");
	so.addVariable("settings_file", encodeURIComponent("/scripts/amcharts/amline_settings.xml"));
	so.addVariable("data_file", encodeURIComponent( chart_file ));
	so.write( this );
}

$( function() {
	$('.piechart').each( wsbs_piechartify );
	$('.linechart').each( wsbs_linechartify );
	$('.columnchart').each( wsbs_columnchartify );
});