if ( typeof( IPG ) == 'undefined' ) IPG = {};
IPG.EpgConfig = function( url ){
    //IPG.Utility.debugOut( '[Load ConfigXML Start]' , "debug" , "blue" );
    this.version = "0.1";
    
    this.url = url;
    if( !this.url ) return;
    
    return this.createData();
};
IPG.EpgConfig.prototype.createData = function(){
    var ajaxOpt = {
        'method': 'get',
        'asynchronous': false
    };
    var xhrObj = new Ajax.Request( this.url , ajaxOpt );
    if( xhrObj && xhrObj._complete ){
        this.xml_data = xhrObj.transport.responseXML.documentElement;
    }else{
        // コンフィグファイルロード失敗時にはエラーを書くべき、ノードも無い。
        // 有ったとしても出力する画像のパスはコンフィグファイルの中に…。
    }
    return this.parseData();
};
IPG.EpgConfig.prototype.parseData = function(){
    if( !this.xml_data ) return;
    var data = {};
    
    var imgPath = this.xml_data.getElementsByTagName("img_path")[0];
    if( imgPath && imgPath.childNodes && imgPath.childNodes.length ){
        for( var i = 0 , len = imgPath.childNodes.length; i < len; i++ ){
            var child = imgPath.childNodes[i];
            if( !data.img_path ) data.img_path = {};
            if( child.firstChild.nodeType == Node.TEXT_NODE ){
                data.img_path[child.nodeName] = child.firstChild.nodeValue;
            }
        }
        child = null;
    }
    imgPath = null;
    
    var apiURL = this.xml_data.getElementsByTagName("api_url")[0];
    if( apiURL && apiURL.childNodes && apiURL.childNodes.length ){
        for( var i = 0 , len = apiURL.childNodes.length; i < len; i++ ){
            var child = apiURL.childNodes[i];
            if( !data.api_url ) data.api_url = {};
            if( child.firstChild.nodeType == Node.TEXT_NODE ){
                data.api_url[child.nodeName] = child.firstChild.nodeValue;
            }
        }
        child = null;
    }
    apiURL = null;
    
    var epgInfo = this.xml_data.getElementsByTagName("epg_info")[0];
    if( epgInfo && epgInfo.childNodes && epgInfo.childNodes.length ){
        for( var i = 0 , len = epgInfo.childNodes.length; i < len; i++ ){
            var child = epgInfo.childNodes[i];
            if( !data.epg_info ) data.epg_info = {};
            if( child.firstChild.nodeType == Node.TEXT_NODE ){
                data.epg_info[child.nodeName] = eval( child.firstChild.nodeValue );
            }
        }
        child = null;
    }
    epgInfo = null;
    
    var scrollbarInfo = this.xml_data.getElementsByTagName("scrollbar_info")[0];
    if( scrollbarInfo && scrollbarInfo.childNodes && scrollbarInfo.childNodes.length ){
        for( var i = 0 , sbinfo_len = scrollbarInfo.childNodes.length; i < sbinfo_len; i++ ){
            var sbinfo_child = scrollbarInfo.childNodes[i];
            if( sbinfo_child.nodeType == Node.ELEMENT_NODE ){
                if( !data.scrollbar_info ) data.scrollbar_info = {};
                var sb_name = sbinfo_child.nodeName;
                for( var j = 0 , sbchild_len = sbinfo_child.childNodes.length; j < sbchild_len; j++ ){
                    if( !data.scrollbar_info[sb_name] ) data.scrollbar_info[sb_name] = {};
                    var sbInfoObj = data.scrollbar_info[sb_name];
                    var sb_child = sbinfo_child.childNodes[j];
                    if( sb_child.firstChild.nodeType == Node.TEXT_NODE ){
                        sbInfoObj[sb_child.nodeName] = eval( sb_child.firstChild.nodeValue );
                    }
                }
                sbInfoObj = null;
                sb_child = null;
            }
            sb_name = null;
        }
        sbinfo_child = null;
    }
    scrollbarInfo = null;
    
    var color_info = this.xml_data.getElementsByTagName("color_info")[0];
    if( color_info && color_info.childNodes && color_info.childNodes.length ){
        for( var i = 0 , color_info_length = color_info.childNodes.length; i < color_info_length; i++ ){
            if( !data.color_info ) data.color_info = {};
            var colorinfo_child = color_info.childNodes[i];
            if( !colorinfo_child || !colorinfo_child.childNodes || !colorinfo_child.childNodes.length ) continue;
            for( var j = 0 , colorinfo_child_length = colorinfo_child.childNodes.length; j < colorinfo_child_length; j++ ){
                var child = colorinfo_child.childNodes[j];
                if( colorinfo_child.nodeName == "color_default" ){
                    if( !data.color_info['color_default'] ) data.color_info['color_default'] = {};
                    if( child.firstChild.nodeType == Node.TEXT_NODE ){
                        data.color_info.color_default[child.nodeName] = child.firstChild.nodeValue;
                    }
                }else{
                    if( !data.color_info["color_palette"] ) data.color_info["color_palette"] = [];
                    var color = child.firstChild;
                    while( color ){
                        if( !data.color_info.color_palette[j] ) data.color_info.color_palette[j] = {};
                        data.color_info.color_palette[j][color.nodeName] = color.firstChild.nodeValue;
                        color = color.nextSibling;
                    }
                    var color = null;
                }
            }
            child = null;
        }
        colorinfo_child = null;
    }
    color_info = null;
    
    //IPG.Utility.debugOut( '[Load ConfigXML Done]' , "debug" , "blue" );
    return data;
};