/**
 * @author dherbolt
 */
wa = {
	consts: {
		flashWidth: 445,
		flashHeight: 380,
		winWidth: 763,
		winHeight: 420,
		centerToElId: 'content-container'
	},
	
	detailWindow: {
		init: function () {
			var els = Ext.DomQuery.select('.detail');
			for (var i=0, cnt=els.length; i<cnt; i++) {
				Ext.get(els[i]).on('click', wa.detailWindow.showDetail, Ext.get(els[i]));
			}
		},
		
		showDetail: function (event) {
			var 
				win,
				html,
				cfg,
				closeId = Ext.id(),
				flashFileName = this.id + '.swf',
				descriptionFileName = this.id + '.html',
				detailWidth = wa.consts.winWidth - wa.consts.flashWidth - 10,
				detailHeight = wa.consts.winHeight - 10;
			
			html = '<div class="close"><img src="./images/close.gif" title="close" id="' + closeId + '"/></div>';
			
			html += '<div style="float: left;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + wa.consts.flashWidth + '" height="' + wa.consts.flashHeight + '" align="middle">' +
						'<param name="allowScriptAccess" value="sameDomain" />' +
						'<param name="movie" value="' + flashFileName + '" />' + 
						'<param name="quality" value="high" />' +
						'<param name="bgcolor" value="#FFFFFF" />' +
						'<embed src="' + flashFileName + '" quality="high" bgcolor="#FFFFFF" width="' + wa.consts.flashWidth + '" height="' + wa.consts.flashHeight + '" name="' + this.id + '" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
					'</object></div>';
					
			html += '<div class="descriptionContainer">';
			html += '<iframe frameborder="0" class="description" style="width:' + detailWidth + 'px; height:' + detailHeight + 'px;" src="' + descriptionFileName + '">';
			html += '</iframe></div>';
			 					
			cfg = {
				floating: true, 
				shadow: 'drop',
				shadowOffset: 5,
				resizable: false,
				modal: true,
				minimizable: false,
				maximizable: false,
				draggable: false,
				closable: false, 
			 	closeAction: 'close',
				animCollapse: true,
				animateTarget: this.dom,
				constrain: true,
				width: wa.consts.winWidth + 14,
				height: wa.consts.winHeight + 37,
				cls: 'detailWindow',
				closeId: closeId,
				listeners: {
					beforeshow: function (win) { 
						win.anchorTo(Ext.get(wa.consts.centerToElId), 'tl', [0, 2], true);
					},
					show: function (win) { 
						win.anchorTo(Ext.get(wa.consts.centerToElId), 'tl', [0, 2], true);
					}
				},
				html: html
			};
			
			win = new Ext.Window(cfg);
			
			win.afterRender = win.afterRender.createSequence(function () {
				Ext.get(this.closeId).on('click', function () {this.close()}, this);
			});
			
			win.show();
		}
	}
};

