if (!DJIndexes) {
	Ext.ns("DJIndexes");
}
// this application ns
DJIndexes.mediaApp = {};
/*
DJIndexes.mediaApp.Tabs = function () {
	return {
		init:function () {
			
			
		}
	};
}();
*/
DJIndexes.mediaApp.WebinarPanels = function () {
	return {
		init:function() {
			if (Ext.get('webinarPanels')) {
				var AccPanels = new Ext.Panel({
					layout: 'accordion',
					renderTo: 'webinarPanels',
					width: 973,
					autoHeight: true,
					defaults: {
						autoHeight: true
					},
					layoutConfig: {
						fill: true,
						collapseFirst: true,
						animate: true,
						titleCollapse: true
					},
					items: [{
						contentEl: 'pane1',
						title: 'Will Volatile Markets and Inflation Unravel the Best Laid Retirement Plans? How to Protect DC Asssets',
						iconCls: 'accordionpanel-icons'
					}]
				});
			}		
		}
	};
}();
Ext.onReady(DJIndexes.mediaApp.WebinarPanels.init);		

DJIndexes.mediaApp.AudioPanels = function () {
	return {
		init:function() {
			if (Ext.get('audioPanels')) {
				var AccPanels = new Ext.Panel({
					layout: 'accordion',
					renderTo: 'audioPanels',
					width: 973,
					autoHeight: true,
					defaults: {
						autoHeight: true
					},
					layoutConfig: {
						fillt: true,
						collapseFirst: true,
						animate: true,
						titleCollapse: true
					},
					
					items: [{
						contentEl: 'pane2',
						title: 'Audio',
						iconCls: 'accordionpanel-icons'
					}]
				});
			}
		}
	};
}();
Ext.onReady(DJIndexes.mediaApp.AudioPanels.init);		


DJIndexes.mediaApp.AudioPlayer = function () {
	var config = {
		container: {
			audio_re: "[@class='audio-link']"
		}
		
	};

	function setClickAttribs(fly) {
		fly.on('click', DJIndexes.mediaApp.AudioPlayer.handleClick, this, {
			stopPropagation: true,
			preventDefault: true
		});
	}
	
	return {
		init: function(){
			audio_href = Ext.select(config.container.audio_re);
			
			setClickAttribs(audio_href);
		},
		
		handleClick: function(evt,t,o) {
			// using Ext.getDom('#') instead of Ext.get('#').dom as it returns a lighter object
			Ext.getDom('video-frame').src = t.href;
		}
		
	};
}();
Ext.onReady(DJIndexes.mediaApp.AudioPlayer.init);


function onTemplateLoaded(experienceID) {
	DJIndexes.mediaApp.VideoSelection.setAPI(experienceID);
}

DJIndexes.mediaApp.VideoSelection = function() {
	var API;
	
	function getAPI() {
		return API;
	}
	
	function setAPI(id) {
		// localize API
		var experience = window.brightcove.getExperience(id);
		API = {
			player: experience.getModule(APIModules.VIDEO_PLAYER),
			content: experience.getModule(APIModules.CONTENT)
		};
		
		// add listener(s)
		API.content.addEventListener(window.BCContentEvent.VIDEO_LOAD, function(e){
			API.player.loadVideo(e.video.id);
		});
	}
	
	return {
		
		init: function() {
			// attach listeners for in page links.
			Ext.select('[@class="video-link"]').on('click',function(e,target,options){
				e.preventDefault();
				// load video
				
				getAPI().content.getVideoAsynch(target.id);
			});
		},
		
		setAPI: function(id) {
			setAPI(id);
		}
		
	}
	
}();
Ext.onReady(DJIndexes.mediaApp.VideoSelection.init,DJIndexes.mediaApp.VideoSelection);



DJIndexes.DisclaimerDialog = function(){
	
		var DialogWin = new Ext.Window({
			title: 'Disclaimer',
			modal:true,
			frame:true,
			top:0,
			width: 535,
			height: 300,
			shadow: true,
			closeAction:'hide',
			listeners:{
				 hide:function() {Ext.get('video-frame').dom.style.display = "block";}
			},
			
			contentEl:'disclaimer-text',
			autoScroll:true,
			animateTarget: 'disclaimer-text',
			buttons: [
				{
				text: 'OK',
				handler: function(){
					Ext.get('video-frame').dom.style.display = "block";
					DialogWin.hide();
				}
			}]
		});
	
	
	var handleClick = function() {DialogWin.show();Ext.get('video-frame').dom.style.display = "none";};

	return {
		init:function () {
			if (Ext.get('popup-disclaimer'))
			{
				Ext.get('popup-disclaimer').on("click", handleClick, scope = this, options = {stopPropagation: true,preventDefault: true});
			}
			

		}
	}
}();
Ext.onReady(DJIndexes.DisclaimerDialog.init);