var WEATHER_LOADER = "./area/util/WeatherLoader?gen_behavior=";
var WEATHER_ICON_PATH = "./gis/images/icons/";
var WEATHER_VALUE_WEATHER = "weather";
var WEATHER_VALUE_RAIN = "rain";
var WEATHER_VALUE_TEMP = "temp";
var WEATHER_ACTION = "gen_action";
var WEATHER_BEHAVIOR = "gen_behavior";
var WEATHER_ACTION_VALUE_LIST = "list";

//----------------- 地域データ用 地域用定数 ----------------------//
var WEATHER_AREA_TOYOTA = 0;
var WEATHER_AREA_SHIMOYAMA = 1;
var WEATHER_AREA_ASUKE = 2;
var WEATHER_AREA_FUJIOKA = 3;
var WEATHER_AREA_OBARA = 4;
var WEATHER_AREA_ASAHI = 5;
var WEATHER_AREA_INABU = 6;

//------------------ 地域データ用時間定数 -------------//
var WEATHER_HOUR_NOW = 0;
var WEATHER_HOUR_THREE = 1;
var WEATHER_HOUR_SIX = 2;
var WEATHER_HOUR_TWELVE = 3;
var WEATHER_HOUR_TWENTYFOUR = 4;
var WEATHER_HOUR_MAX = 5;


function WeatherMetaData(){
    this.listcount;
    this.mainimg;
    this.hour;
    this.prefix;
    this.graph;
    this.weatherkind;
    this.modifydate;
    this.imgLength;
 
    this.init = function(xml){
        this.mainimg = new Array();
        this.hour = new Array();
        this.prefix = new Array();
        this.weatherkind = "";
        this.modifydate = "";
        this.listcount = 0;
        this.imgLength = 0;
        this.graph = 0;
       
        var dataObj = xml.getElementsByTagName("weathermeta");
        this.listcount = dataObj[0].childNodes.length;
        

        for (i = 0; i < this.listcount; i++){
            var child = dataObj[0].childNodes[i];

            if (child.tagName == "kind"){
                if (child.firstChild){
                    this.weatherkind = child.firstChild.nodeValue;
                 }
             }
             
             if (child.tagName == "datatime"){
                if (child.firstChild){
                    this.modifydate = child.firstChild.nodeValue;
                 }
             }

             if (child.tagName == "weatimg1"){
                if (child.firstChild){
                    this.imgLength ++;
                    this.mainimg[0] = child.firstChild.nodeValue;
                    this.hour[0] = child.getAttribute("hour");
                    this.prefix[0] = child.getAttribute("pref");
                }
             }

             if (child.tagName == "weatimg2"){
                if (child.firstChild){
                    this.imgLength ++;
                    this.mainimg[1] = child.firstChild.nodeValue;
                    this.hour[1] = child.getAttribute("hour");
                    this.prefix[1] = child.getAttribute("pref");
                }
             }

             if (child.tagName == "weatimg3"){
                if (child.firstChild){
                    this.imgLength ++;
                    this.mainimg[2] = child.firstChild.nodeValue;
                    this.hour[2] = child.getAttribute("hour");
                    this.prefix[2] = child.getAttribute("pref");
                }
             }

             if (child.tagName == "weatimg4"){
                if (child.firstChild){
                    this.imgLength ++;
                    this.mainimg[3] = child.firstChild.nodeValue;
                    this.hour[3] = child.getAttribute("hour");
                    this.prefix[3] = child.getAttribute("pref");
                }
             }

             if (child.tagName == "weatimg5"){
                if (child.firstChild){
                    this.imgLength ++;
                    this.mainimg[4] = child.firstChild.nodeValue;
                    this.hour[4] = child.getAttribute("hour");
                    this.prefix[4] = child.getAttribute("pref");
                }
             }

             if (child.tagName == "weatimg6"){
                if (child.firstChild){
                    this.imgLength ++;
                    this.mainimg[5] = child.firstChild.nodeValue;
                    this.hour[5] = child.getAttribute("hour");
                    this.prefix[5] = child.getAttribute("pref");
                }
             }

             if (child.tagName == "graph"){
                if (child.firstChild){
                    this.graph = child.firstChild.nodeValue;
                }
             }
          }//for
      }//init

      this.getListCount = function(){
        return this.listcount;
      }

      this.getImgCount = function(){
        return this.imgLength;
      }

      this.getMainImg = function(){
        return this.mainimg;
      }

      this.getWeatherKind = function(){
        return this.weatherkind;
      }

      this.getModifyDate = function(){
        return this.modifydate;
      }
      
      this.getHour = function(){
        return this.hour;
      }

      this.getGraphPath = function(){
        return this.graph;
      }
      
      this.getHourPrefix = function(){
          return this.prefix;
      }
}


function WeatherArea(){
    this.listcount;
    this.childcount;
    this.areaname;
    this.weatherimg;
    this.rain;
    this.temp;
    this.arraySize = 6;
    
    this.init = function(xml){
        this.listcount = 0;
        this.childcount = new Array();
        this.areaname = new Array();
        this.weatherimg = new Array();
        this.rain = new Array();
        this.temp = new Array();


        var obj = xml.getElementsByTagName("datainfo");
        this.listcount = obj.length;
        
        for (i = 0; i < this.listcount; i++){
            if (obj[i].hasChildNodes()){
                this.weatherimg[i] = new Array();
                this.rain[i] = new Array();
                this.temp[i] = new Array();
                var childSize = 0;

                for (j = 0; j < obj.item(i).childNodes.length; j++){
                    var child = obj[i].childNodes[j];

                    if (child.tagName == "name"){
                        if (child.firstChild){
                            childSize ++;
                            this.areaname[i] = child.firstChild.nodeValue;
                        }
                    }
                    //----------------------------- icon ----------------------------//
                    if (child.tagName == "weatherimg0"){
                        if (child.firstChild){
                            childSize ++;
                            this.weatherimg[i][0] = child.firstChild.nodeValue;
                         }
                     }

                     if (child.tagName == "weatherimg1"){
                        if (child.firstChild){
                            childSize ++;
                            this.weatherimg[i][1] = child.firstChild.nodeValue;
                         }
                     }

                     if (child.tagName == "weatherimg2"){
                        if (child.firstChild){
                            childSize ++;
                            this.weatherimg[i][2] = child.firstChild.nodeValue;
                         }
                     }

                     if (child.tagName == "weatherimg3"){
                        if (child.firstChild){
                            childSize ++;
                            this.weatherimg[i][3] = child.firstChild.nodeValue;
                         }
                     }

                     if (child.tagName == "weatherimg4"){
                        if (child.firstChild){
                            childSize ++;
                            this.weatherimg[i][4] = child.firstChild.nodeValue;
                         }
                     }
        
                     if (child.tagName == "weatherimg5"){
                        if (child.firstChild){
                            childSize ++;
                            this.weatherimg[i][5] = child.firstChild.nodeValue;
                         }
                     }

                     //-------------------------------- temp ---------------------------------//
                     if (child.tagName == "rain0"){
                        if (child.firstChild){
                            childSize ++;
                            this.rain[i][0] = child.firstChild.nodeValue;
                         }
                     }

                     if (child.tagName == "rain1"){
                        if (child.firstChild){
                            childSize ++;
                            this.rain[i][1] = child.firstChild.nodeValue;
                         }
                     }

                     if (child.tagName == "rain2"){
                        if (child.firstChild){
                            childSize ++;
                            this.rain[i][2] = child.firstChild.nodeValue;
                         }
                     }

                     if (child.tagName == "rain3"){
                        if (child.firstChild){
                            childSize ++;
                            this.rain[i][3] = child.firstChild.nodeValue;
                         }
                     }

                     if (child.tagName == "rain4"){
                        if (child.firstChild){
                            childSize ++;
                            this.rain[i][4] = child.firstChild.nodeValue;
                         }
                     }
        
                     if (child.tagName == "rain5"){
                        if (child.firstChild){
                            childSize ++;
                            this.rain[i][5] = child.firstChild.nodeValue;
                         }
                     }

                     //----------------------- 降水 ----------------------------------//
                     if (child.tagName == "temp0"){
                        if (child.firstChild){
                            childSize ++;
                            this.temp[i][0] = child.firstChild.nodeValue;
                         }
                     }

                     if (child.tagName == "temp1"){
                        if (child.firstChild){
                            childSize ++;
                            this.temp[i][1] = child.firstChild.nodeValue;
                         }
                     }

                     if (child.tagName == "temp2"){
                        if (child.firstChild){
                            childSize ++;
                            this.temp[i][2] = child.firstChild.nodeValue;
                         }
                     }

                     if (child.tagName == "temp3"){
                        if (child.firstChild){
                            childSize ++;
                            this.temp[i][3] = child.firstChild.nodeValue;
                         }
                     }

                     if (child.tagName == "temp4"){
                        if (child.firstChild){
                            childSize ++;
                            this.temp[i][4] = child.firstChild.nodeValue;
                         }
                     }
        
                     if (child.tagName == "temp5"){
                        if (child.firstChild){
                            childSize ++;
                            this.temp[i][5] = child.firstChild.nodeValue;
                         }
                     }
                 }//for
                 this.childcount[i] = childSize;//datainfo
             }//if
        }//for  
    }//init

    //datainfo
    this.getListCount = function(){
        return this.listcount;
    }
    //datainfo
    this.getChildCount = function(){
        return this.childcount;
    }
 
    this.getArraySize = function(){
        return this.arraySize;
    }

    this.getAreaName = function(){
        return this.areaname;
    }

    this.getWeatherIcon = function(){
        return this.weatherimg;
    }

    this.getRainData = function(){
        return this.rain;
    }

    this.getTempData = function(){
        return this.temp;
    }
}
