/*
 * Ext JS Library 3.0 RC1
 * Copyright(c) 2006-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

SamplePanel = Ext.extend(Ext.DataView, {
    autoHeight: true,
    frame:true,
    cls:'demos',
    itemSelector: 'dd',
    overClass: 'over',
    
    tpl : new Ext.XTemplate(
        '<div id="sample-ct">',
            '<tpl for=".">',
            '<div><div></div>',
            //'<div><a name="{id}"></a><h2><div>{title}</div></h2>',
			'<dl>',
                '<tpl for="samples">',
                    '<dd ext:url="{url}"><img src="../../resources/images/system/case/{icon}"/>',
                        '<div><h4>{text}',
                            '<tpl if="values.isNew"><span class="new-sample"> (New)</span></tpl>',
                            '<tpl if="values.isUpdated"><span class="updated-sample"> (Updated)</span></tpl>',
                        '</h4><p>{desc}</p></div>',
                    '</dd>',
                '</tpl>',
            '<div style="clear:left"></div></dl></div>',
            '</tpl>',
        '</div>'
    ),

    onClick : function(e){
        var group = e.getTarget('h2', 3, true);
        if(group){
            group.up('div').toggleClass('collapsed');
        }else {
            var t = e.getTarget('dd', 5, true);
            if(t && !e.getTarget('a', 2)){
                var url = t.getAttributeNS('ext', 'url');
                window.open(url);
            }
        }
        return SamplePanel.superclass.onClick.apply(this, arguments);
    }
});


Ext.EventManager.on(window, 'load', function(){

    var catalog = [{
        //title: '開閉',
        samples: [{
            text: 'ポータルサイト',
            url: 'portal.html',
            icon: 'portal.jpg',
            desc: '今までのポータルサイト構築ノウハウを活かし、お客様のご要望に添った機能を実装・カスタマイズいたします。'
		},{
            text: '学校用管理システム',
            url: 'school.html',
            icon: 'school.jpg',
            desc: '学校用管理システムでは、先生方が管理者となり、生徒の情報や学校の情報を管理していきます。'
        },{
            text: 'ECショッピングシステム',
            url: 'ec.html',
            icon: 'ec.jpg',
            desc: 'ECという言葉が定着してきた現在、ECショッピングシステムを構築する様々なパッケージやサービスが世の中に普及してきました。'
        
        }]
    }];

    for(var i = 0, c; c = catalog[i]; i++){
        c.id = 'sample-' + i;
    }

    var store = new Ext.data.JsonStore({
        idProperty: 'id',
        fields: ['id', 'title', 'samples'],
        data: catalog
    });

    new Ext.Panel({
        autoHeight: true,
        collapsible: true,
        frame: true,
        title: '構築 サンプル',
        items: new SamplePanel({
            store: store
        })
    }).render('all-demos');

    var tpl = new Ext.XTemplate(
        '<tpl for="."><li><a href="#{id}">{title:stripTags}</a></li></tpl>'
    );
    //tpl.overwrite('sample-menu', catalog);

    Ext.select('#sample-spacer').remove();

    /*setTimeout(function(){
        Ext.get('loading').remove();
        Ext.fly('loading-mask').fadeOut({
			remove:true,
			callback : function() {
				var cp = new Ext.state.CookieProvider();

				if(window.console && window.console.firebug && ! cp.get('hideFBWarning')){
					var tpl = new Ext.Template(
						'<div style="border: 1px solid #FF0000; background-color:#FFAAAA; display:none; padding:15px; color:#000000;"><b>Warning: </b> Firebug is known to cause performance issues with Ext JS. <a href="#" id="hideWarning">[ Hide ]</a></div>'			   
					);
					var newEl = tpl.insertFirst('all-demos');
					
					Ext.fly('hideWarning').on('click', function() {
						Ext.fly(newEl).slideOut('t',{remove:true});
						cp.set('hideFBWarning', true);	
					});
					Ext.fly(newEl).slideIn();
				}
				
				
			}
		
		
		});
    }, 250);*/
});
