Ext.BLANK_IMAGE_URL = 'images/spacer.gif';//Spacer
Docs = {};

ApiPanel = function() {
    ApiPanel.superclass.constructor.call(this, {
        id:'api-tree',
        region:'west',//場所指定
        split:true,//大きさ変更ができるかどうか
        width: 250,
        minSize: 150,
        maxSize: 500,
        collapsible: true,
        margins:'0 0 5 5',
        cmargins:'0 0 0 0',
        rootVisible:false,//rootを表示するか
        lines:true,//∟
        autoScroll:true,
        animCollapse:false,
        collapseMode:'mini',//ボックスを閉じるボタンがつく
       // animate: true,//開くときのアニメーション
        
       loader: new Ext.tree.TreeLoader({
         preloadChildren: true,
         clearOnLoad: false
       }),
        root: new Ext.tree.AsyncTreeNode({
            text:'Ext JS',
            id:'root',
            expanded:true,
            children:[Docs.classData]
         })
    });
};

Ext.extend(ApiPanel, Ext.tree.TreePanel, {});
Ext.onReady(function(){
    var api = new ApiPanel();

    api.on('click', function(node, e){
       e.stopEvent();
       document.getElementById("main").src=node.attributes.href;
       
    });


    var header = new Ext.BoxComponent({
        region:'north',
	      el:'header'
    });
    
    var mainPanel= new Ext.BoxComponent({
        region:'center',
        el:'main',
        margins:'0 5 5 0',
        	
        autoScroll: true
    });
    		

    var viewport = new Ext.Viewport({
        layout:'border',
        items:[ header, api, mainPanel ]
    });

    viewport.doLayout();
	
	setTimeout(function(){
        Ext.get('loading').remove();
        Ext.get('loading-mask').fadeOut({remove:true});
    }, 250);
	
	var filter = new Ext.tree.TreeFilter(api, {
		clearBlank: true,
		autoClear: true
	});
	target = window.location.search.substring(1);
	if (target) {
		setTimeout("document.getElementById('main').src = './' + target;", 500);
		node = '/root/' + findPath(target, Docs.classData);
		api.expandPath(node);
		api.selectPath(node);
		
	} else {
    	api.expandPath('/root/default');
		api.expandAll();
	}
});


function findPath(target, src) {
	if (src.id == target.replace(/\//g, '_')) {
		return src.id;
	} else {
		for (i in src.children) {
			ret = findPath(target, src.children[i]);
			if (ret != '') {
				return src.id + '/' + ret;
			}
		}
	}
	return '';
}
function retNode(title, href, state, children) {
	cls = 'none';
	if (state == 'draft') {
		cls = 'draft';
	} else if (state == 'done') {
		cls = 'done';
	}
	icon_cls = 'icon-' + cls;
	if (children) {
		return {"id":href.replace(/\//g, '_'),"href":href,"iconCls":icon_cls, "text":title,"isClass":true,"cls":cls,"leaf":false, "children":children};
	} else {
		return {"id":href.replace(/\//g, '_'),"href":href,"text":title,"isClass":true,"iconCls":icon_cls, "cls":cls,"leaf":true};
	}
}
		
//retNode("", "", "draft"),
Docs.classData =
{"id":"default","text":"Androidドキュメント","href":"fast.html","singleClickExpand":true,
"children":[
	retNode("Getting Started", "intro/index.html", "draft",[
		retNode("Installing the SDK", "intro/installing.html", "none"),
		retNode("Hello Android", "intro/hello-android.html", "none"),
		retNode("Anatomy of an App", "intro/anatomy.html", "none"),
		retNode("Tutorial", "intro/tutorial.html", "none"),
		retNode("開発用ツール", "intro/tools.html", "draft"),
		retNode("Application Lifecycle", "intro/lifecycle.html", "none")
	]),
	retNode("アプリケーション開発", "devel/index.html", "draft",[
		retNode("UIを構築する", "devel/implementing-ui.html", "draft",[
			retNode("画面要素の階層構造", "devel/ui/hierarchy.html", "draft"),
			retNode("一般的なレイアウトオブジェクト", "devel/ui/layout.html", "draft"),
			retNode("アダプタビューを使う(データのバインディング)", "devel/ui/binding.html", "draft"),
			retNode("画面をXMLで設計する", "devel/ui/xml.html", "draft"),
			retNode("Hooking into a Screen Element", "devel/ui/hooking.html", "draft"),
			retNode("Listening for UI Notifications", "devel/ui/notifications.html", "draft"),
			retNode("アプリケーションにテーマを適用する", "devel/ui/applying-themes.html", "draft"),
			retNode("UI Elements and Concepts Glossary", "devel/ui/glossary.html", "draft")
		]),
		retNode("Building Blocks", "devel/building-blocks.html", "draft",[
			retNode("AndroidManifest.xmlファイル", "devel/bblocks-manifest.html", "draft")
		]),
		retNode("データの読み書きと公開", "devel/data.html", "draft",[
			retNode("Preferences", "devel/data/preferences.html", "draft"),
			retNode("ファイルの読み書き", "devel/data/files.html", "draft"),
			retNode("SQLiteデータベースの利用", "devel/data/databases.html", "draft"),
			retNode("Content Providerの利用", "devel/data/contentproviders.html", "draft"),
			retNode("ネットワークアクセス", "devel/data/network.html", "draft")
		]),
		retNode("セキュリティモデル", "devel/security.html", "draft"),
		retNode("Resources and i18n", "devel/resources-i18n.html", "none")
	]),
	retNode("Developer Toolbox", "toolbox/index.html", "draft",[
		retNode("Design Philosophy", "toolbox/philosophy.html", "draft",[
			retNode("効率的なAndroid用コードを書くには", "toolbox/performance.html", "draft"),
			retNode("応答性が良いアプリケーション開発のために", "toolbox/responsiveness.html", "draft"),
			retNode("システムに溶け込むために", "toolbox/seamlessness.html", "draft")
		]),
		retNode("Building Custom Components", "toolbox/custom-components.html", "draft"),
		retNode("Optional APIs", "toolbox/optional-apis.html", "draft",[
			retNode("an introduction to the Android LBS APIs", "toolbox/apis/lbs.html", "draft"),
			retNode("an introduction to the Android Media APIs", "toolbox/apis/media.html", "draft"),
			retNode("an introduction to the Android OpenGL API", "toolbox/apis/opengl.html", "draft")
		]),
		retNode("Google APIs and Services", "toolbox/google-apis.html", "draft")
	]),
	retNode("Reference Information", "reference/index.html", "none",[
		retNode("Package Index", "reference/packages.html", "none"),
		retNode("Class Index", "reference/classes.html", "none"),
		retNode("Class Hierarchy", "reference/hierarchy.html", "none"),
		retNode("List of Views", "reference/view-gallery.html", "none"),
		retNode("List of Intents", "reference/available-intents.html", "none"),
		retNode("List of Permissions", "reference/android/Manifest.permission.html", "none"),
		retNode("List of Resource Types", "reference/available-resources.html", "none"),
		retNode("Android IDL", "reference/aidl.html", "none"),
		retNode("Glossary", "reference/glossary.html", "none"),
		retNode("Index", "reference/keywords.html", "none")
	]),
	retNode("Sample Code", "samples/index.html", "none",[
		retNode("API Demos", "samples/ApiDemos/index.html", "none"),
		retNode("Lunar Lander", "samples/LunarLander/index.html", "none"),
		retNode("Note Pad", "samples/NotePad/index.html", "none")
	]),
	retNode("FAQs", "kb/index.html", "draft",[
		retNode("General", "kb/general.html", "draft"),
		retNode("Common Tasks", "kb/commontasks.html", "none"),
		retNode("Troubleshooting", "kb/troubleshooting.html", "draft"),
		retNode("Open Source Licensing", "kb/licensingandoss.html", "draft")
	])
]};