var Chart = {
  "main":''
  ,"rows":23
  ,"cells":23
  ,"chartBody":''
  
  ,"tip_object":null
  ,"tip_country":null
  ,"tip_nickname":null
  ,"tip_content":null
  ,"init":function() {
  
    this.tip_object   = document.getElementById("tip_object");
    this.tip_country  = document.getElementById("tip_country");
    this.tip_nickname = document.getElementById("tip_nickname");
    this.tip_content  = document.getElementById("tip_content");




    var table = document.getElementById("chart");

    var tbody = document.createElement("tbody");

    tbody.id = "chartBody";
    table.insertBefore(tbody, null);

    for (var i=0; i < this.rows; i++) {
      var tr = this.addRow(i);
      tbody.insertBefore(tr, null);
    }

    this.chartTbody = document.getElementById("chartBody");
    ChartXY.init();

    this.initMouseMove();  //鼠标移动事件
  }

  ,"addRow":function(y) {
    var tr = document.createElement("tr");
    for (var i=0; i < this.cells; i++) {
      var td = this.addCell(y, i);
      tr.appendChild(td);
    }
    return tr;
  }

  ,"addCell":function(y, x) {
    var td = document.createElement("td");
    var bgColor = "#ECDFD7";
    if (x%2 + y%2==1) {
      bgColor = "#ffffff";
    }
    
    td.style.backgroundColor = bgColor;
    td.id = "chartTd_"+y+"_"+x;
    td.width  = "20";
    td.height = "20";

    td.onclick = function(e) {
      Chart.openCard(this.autoid, this.state);
    }
    td.onmouseover = function(e) {


      try {
        Chart.show(e, this.y, this.x);
      }
      catch(e) {}
    };
    return td;
  }

  ,"setState":function(y, x, state, autoid) {

    var td = this.chartTbody.rows[y].cells[x];

    td.x = x ;
    td.y = y;
    td.state = state;
    td.autoid = autoid;


    if (state == "prearrange") { 
      //预定
      td.style.backgroundColor = "#0000FF";
    }
    else if (state == "already") {  
      //已经认捐
      //td.style.backgroundColor = "";
      td.style.background="url(http://211.100.33.24:8080/cgi-bin/cms/image_view.cgi?db_name=GSPS_Project_16&datetime=2006-09-01&file=16_3_2789_103_17_20060901182218.jpg)";
      td.style.cursor = "hand";
    }
  }

  ,"initMouseMove":function(){
    document.getElementById("chart").onmouseout = function(e) {
      Chart.show(e, -1, -1);
    };
  }


  ,"show":function(e, y, x) {
    var mouse = this.getMouse(e);

    
    var cell;
    try {
    	cell = ChartXY.data[y][x];
    }
    catch (e) {
      Chart.tip_object.style.display = "none";
      return;
    }
    
    Chart.tip_country.innerHTML = cell["country"];
    Chart.tip_nickname.innerHTML = cell["nickname"];
    Chart.tip_content.innerHTML = cell["content"];

    Chart.tip_object.style.display = "";
    Chart.tip_object.style.left = (mouse.x+5) + "px";
    Chart.tip_object.style.top  = (mouse.y+5) + "px";
  }
  ,"openCard":function(autoid, state) {
    if (typeof(autoid) == "undefined" || state!="already") {
      return;
    }
    window.open("http://group.mop.com//HomePage.do?commno=157100");
  }
  ,"getMouse":function(e){
    var x,y;
    if(!document.all){
      x = e.pageX; 
      y = e.pageY;
    }
    else{
      x = document.body.scrollLeft+event.clientX;
      y = document.body.scrollTop+event.clientY; 
    }
    return {
      x:x, y:y
    }
  }


}
