function loadTotalGraph(psurl){
	script_load( "/data/counts/" + psurl );
}
/*
 * 読み出し結果は個別に設定する。
 */
function counts_daily(json){
	setTotalGraph2(json, 'today');
}
/*
 * 読み出し結果は個別に設定する。
 */
function counts_recent(json){
	setTotalGraph2(json, 'now');
}
/*
 * 読み出し結果は個別に設定する。
 */
function counts_weekly(json){
	setTotalGraph2(json, 'week');
}
/*
 * 読み出し結果は個別に設定する。
 */
function counts_monthly(json){
	setTotalGraph2(json, 'month');
}
/*
 * 読み出し結果は個別に設定する。
 */
function counts_yearly(json){
	setTotalGraph2(json, 'year');
}
function setTotalGraph2(json, ptype){
	var item = json["countsList"];
	var html = "", item_g;
	var rows, rows2, m, m2 = 0;
	if ($("#lupdate").size() > 0) {
		$('#lupdate').html( formatLastUpd(json["lastUpdate"],false,true,true,true,true) );
	}
	if ($("#spTime").size() > 0) {
		$('#spTime').html( formatDate(json["lastUpdate"],true,true,true,true,true) );
	}
	if ($("#pulldown").size() > 0) {
		$('#pulldown').html( putPulldown() );
	}
	
	$('#tFreq').html( addFigure(json.sumOfTotal) );
	$('#pFreq').html( addFigure(json.sumOfPositive) );
	$('#nFreq').html( addFigure(json.sumOfNegative) );
	
	var urlBase = 'http://chart.apis.google.com/chart?chs=400x80&cht=lc&chco=FF9AB3,84BBEA,ff9933&chxt=x,y&chls=3|2|2&chxs=0,505050,9,0,lt|1N\*s\*,505050,9,1';
	var t_now = new Date( item[0].date );
	var t_year = t_now.getYear();
	var t_mon  = t_now.getMonth() + 1;
	rows2 = setRows(t_year,t_mon, ptype);
	rows = item.length;

	
	// 表示データと軸データを設定する。
	var chdString = '';
	var totalValue = '';
	var negativeValue = '';
	var positiveValue = '';
	var totalMaxValue = -1;
	var negaMaxValue = -1;
	var posiMaxValue = -1;
	// Y軸表示のためにデータMAX値を取得する。
	for( var i=0; i<rows; i++ ){
		if (totalMaxValue < item[i].total) {
			totalMaxValue = item[i].total;
		}
		if (negaMaxValue < item[i].negative) {
			negaMaxValue = item[i].negative;
		}
		if (posiMaxValue < item[i].positive) {
			posiMaxValue = item[i].positive;
		}
	}
	var valueLength = 10 * totalMaxValue.toString();
	var chxlValue = '';
	for( var i=0; i<rows; i++ ){
		// グラフ線を描くためのデータを設定する。
		if (i != 0) {
			totalValue = totalValue + ',';
			negativeValue = negativeValue + ',';
			positiveValue = positiveValue + ',';
		}
		var value = (item[i].total / totalMaxValue) * 100;
		totalValue = totalValue + value.toFixed(2);
		value = (item[i].negative / totalMaxValue) * 100;
		negativeValue = negativeValue + value.toFixed(2);
		value = (item[i].positive / totalMaxValue) * 100;
		positiveValue = positiveValue + value.toFixed(2);

		// X軸表示のための値を設定する。
		if (chxlValue != '') {
			chxlValue = chxlValue + '|';
		}
		
		if (ptype == 'week' || ptype == 'year' || ptype == '2011ranking') {
			chxlValue = chxlValue + setDispDate(ptype,item[i].date);
		}
		else if (ptype == 'month') {
			if( i%3 == 0 ) {
				chxlValue = chxlValue + setDispDate(ptype,item[i].date);
			}
		}
		else {
			if( i%2 == 0 ) {
				chxlValue = chxlValue + setDispDate(ptype,item[i].date);
			}
		} 
		m = item[i].total;
		if( m > m2 ) m2 = m;
	}
	if (rows < rows2) {
		for( var j=i; j<rows2; j++ ){
			totalValue = totalValue + ',-1';
			negativeValue = negativeValue + ',-1';
			positiveValue = positiveValue + ',-1';

			// X軸表示のための値を設定する。
			if (chxlValue != '') {
				chxlValue = chxlValue + '|';
			}

			if (ptype == 'week' || ptype == 'year' || ptype == '2011ranking') {
				chxlValue = chxlValue + supplementationX(ptype,j,item[0].date);
			}
			else if (ptype == 'month') {
				if( j%3 == 0 ) {
					chxlValue = chxlValue + supplementationX(ptype,j,item[0].date);
				}
			}
			else {
				if( j%2 == 0 ) {
					chxlValue = chxlValue + supplementationX(ptype,j,item[0].date);
				}
			} 
		}
	}
	var url = urlBase + '&chd=t:' + totalValue + '|' + negativeValue + '|' + positiveValue;
	
	url = url + '&chxl=0:|' + chxlValue + '&chxr=1,0,' + totalMaxValue;

	document.getElementById('topGraph').innerHTML = '<img src=\"' + url + '\">';
}

