var WspGraph = {
  meal : {
    area_size: 416,
    set_bg : function(key, min, center, max) {
      center = center - 0;
      if(center > 0) {
	px = WspGraph.meal.area_size / (center * 2);
	if(min == '') {
	  min = 0;
	} else {
	  min = px * min - 0;
	}
	element_id = 'gm_bg_'+key+'_left';
	if($(element_id) != null) {
	  min = parseInt(min);
	  $(element_id).style.width = String(min) + 'px';
	}
	if(max == '' || max > center * 2) {
	  max = px * center * 2;
	} else {
	  max = px * max - 0;
	}
	element_id = 'gm_bg_'+key+'_center';
	if($(element_id) != null) {
	  max = parseInt(max);
	  $(element_id).style.width = String(max - min)+'px';
	}
      }
    },
    
    set_fg : function(key, center, total, osake, okashi, supple) {
      center = center - 0;
      over = 0;
      if(center > 0) {
	px = WspGraph.meal.area_size / (center * 2);
	total = total - 0;
	osake = osake - 0;
	okashi = okashi - 0;
	supple = supple - 0;
	normal = total - osake - okashi - supple;
	element_id = 'gm_fg_'+key+'_normal';
	sum = 0;
	if($(element_id) != null) {
	  normal = parseInt(px * normal);
	  if(normal < 0)
	    normal = 0;
	  sum += normal;
	  if(normal > WspGraph.meal.area_size) {
	    normal = WspGraph.meal.area_size;
	    over = 1;
	  }
	  $(element_id).style.width = String(normal)+'px';
	}
	element_id = 'gm_fg_'+key+'_osake';
	if(over == 0 &&
	   $(element_id) != null) {
	  osake = parseInt(px * osake);
	  sum += osake;
	  if(sum > WspGraph.meal.area_size) {
	    osake = WspGraph.meal.area_size - normal;
	    over = 1;
	  }
	  $(element_id).style.width = String(osake)+'px';
	}
	element_id = 'gm_fg_'+key+'_okashi';
	if(over == 0 &&
	   $(element_id) != null) {
	  okashi = parseInt(px * okashi);
	  sum += okashi;
	  if(sum > WspGraph.meal.area_size) {
	    okashi = WspGraph.meal.area_size - normal - osake;
	    over = 1;
	  }
	  $(element_id).style.width = String(okashi) + 'px';
	}
	element_id = 'gm_fg_'+key+'_supple';
	if(over == 0 &&
	   $(element_id) != null) {
	  supple = parseInt(px * supple);
	  sum += supple;
	  if(sum > WspGraph.meal.area_size) {
	    supple = WspGraph.meal.area_size - normal - osake -okashi;
	    over = 1;
	  }
	  $(element_id).style.width = String(supple) + 'px';
	}
      }
    }
  },

  exer : {
    area_size: 534,
    max_exer: 23,
    set_width: function(normal, move) {
      px = WspGraph.exer.area_size / WspGraph.exer.max_exer;
      normal = normal - 0;
      move = move - 0;
      over = 0;
      if($('ge_normal') != null) {
	normal = parseInt(px * normal);
	if(normal > WspGraph.exer.area_size) {
	  normal = WspGraph.exer.area_size;
	  over = 1;
	}
	$('ge_normal').style.width = String(normal) + 'px';
      }
      if(over == 0 &&
	 $('ge_move') != null) {
	move = parseInt(px * move);
	sum = normal + move;
	if(sum > WspGraph.exer.area_size) {
	  move = WspGraph.exer.area_size - normal;
	  over = 1;
	}
	$('ge_move').style.width = String(move) + 'px';
      } else {
	if($('ge_move') != null) {
	  $('ge_move').style.width = '0px';
	}
	  
      }
    }
  },

  exer_e : {
    area_size: 647,
    set_width: function(cal, target) {
      max_energy = 0;
      cal = parseInt(cal);
      target = parseInt(target);
      if(cal <= target) {
	max_energy = target;
      } else {
	max_energy = cal;
      }

      if(max_energy == 0) {
	/** 何もしない **/
	return false;
      }
      px = WspGraph.exer_e.area_size / max_energy;
      if($('eef') != null) {
	if(cal == 0)
	  $('eef').style.visibility = 'hidden';
	$('eef').style.width = String(parseInt(px * cal))+'px';
      }
      if($('eeb') != null) {
	if(target == 0)
	  $('eeb').style.visibility = 'hidden';
	$('eeb').style.width = String(parseInt(px * target)) + 'px';
      }
    }
  }
}
