Ext.ns('DJIndexes.Commodity');

DJIndexes.Commodity.Overview = function() {
	
	function _init() {
		intraday();
		autoLinks();
		overviewTabs();
		aboutTabs();
		indexDataTabs();
		contactUs();
		handbookRequest();
		literatureCenter();		
	}
	
	function intraday() {
		if (Ext.get('intraday')) {
			new DJIndexes.widget.Intraday2('intraday',{
				familyId: 'UBS',
				height: 665,
				title: 'Dow Jones-UBS Commodity Indexes',
				numberFormat: '0.0000'
			});
		}
	}
	
	function autoLinks() {
		
		var autoLinkSelector = '.djiubs-terms';
		if ( Ext.select(autoLinkSelector).getCount() ) {
			new DJIndexes.widget.InfoWindow({
				autoLinkCls: autoLinkSelector,
				title: 'DJI-UBS Terms of Agreement',
				width: 750,
				height: 480,
				autoLoad: 'terms.html',
				autoShow: false
			});
		}
		
	}

	function overviewTabs() {
		var tabContainer = 'overview-tabs';
		var tabContent = [
			{ title: 'Broad Market Indexes',  contentEl: 'broad-market' },
			{ title: 'Subindexes',  contentEl: 'subindexes' },
            { title: 'Ex Subindexes',  contentEl: 'ex-subindexes' },
			{ title: 'Specialty Indexes', contentEl: 'specialty' },
			{ title: 'Forward Indexes', contentEl: 'forward' }
		];
		
		var tabContentEl = Ext.get(tabContainer);
		if (tabContentEl) {
			new DJIndexes.widget.InfoTabs(tabContentEl,{
				tabs: tabContent
			});
		}
	}
	
	function aboutTabs() {
		var tabContainer = 'about-tabs';
		var tabContent = [
			{ title: 'Summary',  contentEl: 'summary' },
			{ title: 'Methodology',  contentEl: 'methodology' },
			{ title: 'Economic Significance', contentEl: 'economic' },
			{ title: 'Diversification',  contentEl: 'diversification' },
			{ title: 'Continuity',  contentEl: 'continuity' },
			{ title: 'Rebalancing and Reweighting', contentEl: 'rebalancing' }
		];
		
		var tabContentEl = Ext.get(tabContainer);
		if (tabContentEl) {
			new DJIndexes.widget.InfoTabs(tabContentEl,{
				tabs: tabContent
			});
		}
	}
	
	function indexDataTabs() {
		var tabContainer = 'index-data-tabs';
		var tabContent = [
			{ title: 'Index Values',  contentEl: 'index-values' },
			{ title: 'Weightings',  contentEl: 'weightings' }
		];
		
		var tabContentEl = Ext.get(tabContainer);
		if (tabContentEl) {
			new DJIndexes.widget.InfoTabs(tabContentEl,{
				tabs: tabContent
			});
		}
	}
	
	function contactUs() {
            var tabContainer, container, form, params, subject;
                  
            tabContainer = 'contact-form';
            container = Ext.get(tabContainer);
            if ( Ext.get(container) ) {
                  form = new DJIndexes.widget.ContactForm(container,{
                        showBusinessUnit: true,
                        additionalParams: [
                              { name: '00N60000001N3cm', value: 'DJ-UBS Contact Form' }
                        ]
                  });               
                  if(Ext.getDom('index-data-referer')){ // || DJIndexes.Utils.getQueryParams('ref')
                        params = '00N60000001N3cm=DJ-UBS Index Data Contact Form|';                   
                        form.find('name','params')[0].setValue(params);
                        form.find('name','description')[0].label.dom.innerHTML = '<span class="x-required">Use of data <br />(e.g. internal research, benchmarking, redistribution, etc.)</span>:';
						subject = form.find('name', 'subject')[0];
						subject.hide();
						subject.setValue('DJ-UBS Index Data Contact Form');
                  }
            }
            
    }
	
	function handbookRequest() {
		var tabContainer = 'handbook-request-form';
		var container = Ext.get(tabContainer);
		if ( Ext.get(container) ) {
			new DJIndexes.Commodity.HandbookForm(container);
		}
	}

	function literatureCenter(){
		
		var container = "literaturecenter";
        if (Ext.get(container)) {
            new DJIndexes.widget.LiteratureSimpleView(container);
			//DJIndexes.PdfOpener.init(container);
        }
		
	}
	
	return {
		init: _init
	}
	
}();
Ext.onReady(DJIndexes.Commodity.Overview.init,DJIndexes.Commodity.Overview);
