	Ext.namespace('DJIndexes');

DJIndexes.Promo = function() {
	
	var styleGroup = 'promo'; //this is the class used by all related links
	var config = {
		spain1 : { type: 'image', path: '../images/tournament/spain1.jpg', width: 500, height: 375, title: 'Sensei Rob Accepting Medal' },
		spain2 : { type: 'image', path: '../images/tournament/spain2.jpg', width: 500, height: 606, title: 'Sensei Rob With Medal' },		
		d_200704 : { type: 'image', path: '../images/tournament/SoleburyDragons_200704.gif', width: 195, height: 260, title: 'Little Dragons' },
		a_200704 : { type: 'image', path: '../images/tournament/SoleburyTeam200704.gif', width: 346, height: 260, title: 'Advanced Team' },
		compteam : { type: 'image', path: '../images/tournament/compteam.jpg', width: 320, height: 213, title: 'National Competition' },	
		soleburyclubcompteam : { type: 'image', path: '../images/tournament/soleburyclubcompteam.jpg', width: 639, height: 351, title: 'Solebury Club National Competition' },
		sweep : { type: 'image', path: '../images/sweep.gif', width: 600, height: 500, title: 'Rob Sweeps Opponent' },		
		KarateEvents : { type: 'pdf', path: '../pdf/karateEvents.pdf', width: 600, height: 600,  title: 'PDF File' },
		KarateSchedule : { type: 'pdf', path: '../pdf/ShotokanKarateSchedule2007.pdf', width: 500, height: 500,  title: 'PDF File' },
		
        kihon : { type: 'page', path: '../popups/kihon_pop.htm', width: 750, height: 190, title: 'Kihon Information'  },
		kata : { type: 'page', path: '../popups/kata_pop.htm', width: 750, height: 225, title: 'Kata Information'  },	
		kumite : { type: 'page', path: '../popups/kumite_pop.htm', width: 750, height: 190, title: 'Kumite Information'  },	
		little_dragons : { type: 'page', path: '../popups/little_dragons_pop.htm', width: 750, height: 160, title: 'Little Dragons Information'  },
		level_one : { type: 'page', path: '../popups/level_one_pop.htm', width: 750, height: 90, title: 'Level One Information'  },	
		level_two : { type: 'page', path: '../popups/level_two_pop.htm', width: 750, height: 90, title: 'Level Two Information'  },	
		level_three : { type: 'page', path: '../popups/level_three_pop.htm', width: 750, height: 150, title: 'Level Three Information'  },	
		
		physical : { type: 'page', path: '../popups/physical_pop.htm', width: 750, height: 90, title: 'Physical aspects of a Black Belt'  },	
		mental : { type: 'page', path: '../popups/mental_pop.htm', width: 750, height: 170, title: 'Mental aspects of a Black Belt'  },
		
		karate_character : { type: 'page', path: '../popups/karate_character_pop.htm', width: 750, height: 165, title: 'Karate Character'  },		
		karate_selfdefense : { type: 'page', path: '../popups/karate_selfdefense_pop.htm', width: 750, height: 150, title: 'Karate Self-Defense'  },
		karate_physical : { type: 'page', path: '../popups/karate_physical_pop.htm', width: 750, height: 185, title: 'Karate - Physical Exercise'  },
		karate_wwsport : { type: 'page', path: '../popups/karate_wwsport_pop.htm', width: 750, height: 190, title: 'Karate as a World Wide Sport'  },
				
	gichin : { type: 'page', path: '../popups/gichin_history_pop.htm', width: 750, height: 330, title: 'Master Gichin Funakoshi - Founder of Shotokan'  },	
	lessons20 : { type: 'page', path: '../popups/lessons20_pop.htm', width: 750, height: 400, title: 'Philosopy Lessons'  },
	
	guidingprinciples : { type: 'page', path: '../popups/guiding_priniciples_pop.htm', width: 750, height: 455, title: 'Guiding Principles'  },
	
		
		
		
		tutorial : { type: 'page', path: '../html/a.html', width: 1024, height: 500, title: 'Main Tutorial Page'  }
	};
	var dialog,panel,promoDescription;
	
	//lessons learned 
	var widthOffset = 18;
	var heightOffset = 73;
	
	return {
		
		init : function() {
			this.createDialog();
			//this.createSrcButton();
			Ext.select('a.'+styleGroup).on('click',this.show);
		},
		
		show : function(e,el,o) {
			if ( config[el.id] ) { 
				DJIndexes.Promo.displayDialog(config[el.id],el.id);
			} else {
				DJIndexes.Promo.showStatus('Your selection could not be found');
			}
		},
		
		createSrcButton : function() {
			this.myButton = new Ext.Button('srcCodeBtn',{
				text: 'View source code',
				tooltip: 'I\'m a tooltip',
				tooltipType: 'title'
			}).on('click',this.showSrcCode);
		},
		
		showSrcCode : function() {
			top.location = 't1.js';
		},
		
		// this function runs only once, on init() (which is called on page load)
		// it creates the dialog object but doesn't show it yet.
		createDialog : function() {
			
			//create dialog only if it doesn't exist
			if (!dialog) {
					
				this.dialog = new Ext.LayoutDialog('promo-dialog', {
					autoCreate: true,
					modal: true,
					shim: true,
					fixedcenter: true,
					shadow: true,
					proxyDrag: true,
					collapsible: false,
					center: {
						autoScroll: true
					}
				});
				
				//this.dialog.addListener('resize', this.debug);
				
				//map ESC key to hide()
				this.dialog.addKeyListener(27, this.dialog.hide, this.dialog);
				
				//create 'Close' button and map to hide()
				this.dialog.setDefaultButton(
					this.dialog.addButton('Close', this.dialog.hide, this.dialog)
				);
				
				this.promoDescription = new Ext.ContentPanel(
					'promo-desc-panel',{
						autoCreate: true,
						fitToFrame: true,
						fitContainer: true
					}
				);
				
				var borderLayout = this.dialog.getLayout();
				this.dialog.beginUpdate();
					borderLayout.add('center',this.promoDescription);
				this.dialog.endUpdate();
				
			}
			
		},
		
		displayDialog : function(o,el) {
			
			//set the dialog's content
			this.setContent(o.type,o.path);
			
			//resize dialog to accomodate current image
			this.dialog.resizeTo(o.width+widthOffset, o.height+heightOffset);
			
			//update title
			this.dialog.setTitle(o.title);
			
			//show it
			this.dialog.show(el); //passing the calling element animates the window
		},
		
		setContent : function(type,path) {
			
			var html = null;
			
			if (type==='image') {
				
				html = '<img src="../js/' + path + '" border="0" />';
				this.promoDescription.setContent(html);
				
			} else if (type==='page') {
				
				this.promoDescription.load({
					url: path,
					text: "Loading...",
					timeout: 10,
					scripts: false
				})
				
			} else if (type==='pdf') {

				 //this.promoDescription.dom.src = 'Brochure.pdf';	
				Ext.get('center-iframe').dom.src = path;	
								
				//this.promoDescription.load({
				//	url: a,
				//	text: "Loading...",
				//	timeout: 10,
				//	scripts: false
				//})
				 Ext.EventManager.onDocumentReady(DJIndexes.Promo.init, DJIndexes.Promo, true);
		
			//	Ext.get('center-iframe').dom.src = "Brochure.pdf";
								
			}
			
		},
		
		showStatus : function(msg) {
			Ext.MessageBox.alert('Status',msg);
		}
		
	}
	
}();

//wait for dom to be ready and call init()
Ext.onReady(DJIndexes.Promo.init,DJIndexes.Promo);