Ext.onReady(function() {
	Ext.select('a[target^=_modal]').each(function(el){
		var target = el.dom.target;
		var win_w = 400;
		var win_h = 250;
		if( target == "_modal_960540")
		{
			win_w = 960;
			win_h = 540;
		}
		var src = el.dom.href;
		src = src.replace(/#c[0-9]+$/,'');
		el.dom.href = 'javascript:void(0);';
		el.dom.target = '';
		var title = el.dom.title;
		var isFlv = src.search(/\.flv$/)!=-1 ? true : false;
		if(isFlv){
			var imgTag = '<img alt="'+title+'" src="typo3conf/ext/eclore_rtemodalboxlink/res/icon_video.gif" style="padding-right:5px;"/>';
			var dh = Ext.DomHelper;
			dh.insertHtml('afterBegin',el.dom,imgTag);
		}
		el.on('click',function(e,t){
			if(isFlv){
				var html = '<div id="fpBlock"></div>';
				var flashvars = {"file":src};
				var params = {"quality":"high","menu":"true","allowScriptAccess":"sameDomain","allowfullscreen":"true","play":"true"};
				var attributes = {};
				var win = new Ext.Window({
					title: imgTag + title,
					html: html,
					width: win_w+20,
					height: win_h+35,
					bodyStyle: 'background-color:black;padding-top:2px;',
					autoScroll: true,
					modal: true,
					listeners: {
			            show: function() {
							swfobject.embedSWF("typo3/contrib/flashmedia/flvplayer.swf", "fpBlock", win_w, win_h, "9", "http://tkgftbautechnik.de/typo3/contrib/flashmedia/swfobject/expressInstall.swf", flashvars, params, attributes);
			                Ext.select('.ext-el-mask').addListener('click', function() {
			                    win.close();
			                });
			            }
					}
				}).show(win);
			}else{		
				var win = new Ext.Window({
					title: el.dom.innerHTML,
					autoLoad: {url:src,params:{type:'2147483647'}},
					width: 640,
					height: 480,
					autoScroll: true,
					modal: true,
					bodyStyle: 'background-color:white',
					listeners: {
			            show: function() {
			                Ext.select('.ext-el-mask').addListener('click', function() {
			                    win.close();
			                });
			            }
					}
				}).show(win);
			}
		});
	});
});
