raismth.ns(function() { with (raismth.LIB) {
myDump("[RAISMTH] rai module initialization\n");

theApp.rai = {
	old_style_inject : function(doc,idx) {
		// let sl = doc.getElementById('SilverlightControl') ? doc.getElementById('SilverlightControl') : doc.getElementById('silverlightControl') ? doc.getElementById('silverlightControl') : false ;
		// let sl = window.content.document.body.innerHTML;
		// alert(sl);
		// return false;
		let sl = doc.getElementById('media');
		let value = '';
		for(let c = 0; c < sl.childNodes.length; c++){
			// alert(sl.childNodes[c].name);
			
			if (sl.childNodes[c].name == 'src'){
				value = sl.childNodes[c].value;
				break;
			}
			
		}
		// alert(value);
		// return false;
		let pl = sl.parentNode;
		if(sl) {
				/*
				let res = result.snapshotItem(0).value;
				let mediaUri = res.substring(res.indexOf('mediaUri')+9,res.indexOf(',',res.indexOf('mediaUri')));
				let chan = raismth.parsers.parseURI(mediaUri);
				// this.stato('UI->AUTH', 'chan: '+this.chan, 2);
				// this.stato('UI->AUTH', 'Authenticating...', 2);
				let ttauth = raismth.utils.bypassNTP(chan);
				mediaUri += '&output=20';
				let mData = raismth.utils.wget(mediaUri, ttauth).replace('mms','http');
				*/				
				let mData = raismth.utils.wget(value, false).trim();
				let embed = doc.createElement('embed');
				embed.setAttribute('name', 'mpmitm');				
				embed.setAttribute('id', 'mpmitm');
				embed.setAttribute('width', '560');
				embed.setAttribute('height', '40');
				embed.setAttribute('type', 'application/x-mplayer2');
				// embed.setAttribute('type', 'audio/x-pn-realaudio-plugin');
				embed.setAttribute('autostart', 'true');
				embed.setAttribute('src', mData);
				if(pl.getAttribute('class') == 'Player') {
					pl.removeChild(pl.childNodes[1]);
					pl.appendChild(embed);
					let jso = myWrapper(doc);
					jso.installedPlugins['real-player'] = true;
				}
				// let playerObj = '<embed name=mpmitm id=mpmitm width="560" height="40" type="application/x-mplayer2" autostart="true" src="'+mData+'" loop="true" onClick="this.Pause()" />';
				// mediaUri = this.cb(mData,this.idx);
				// sl.innerHTML = playerObj;
			
			// alert(sl.innerHTML);
		} else {
			// alert('not found');
		}
	},

	identify : function(doc,ts,indice) {
		let Prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
		let rai_windows_counter = Prefs.getIntPref("extensions.raismth.rai_windows_counter");
		
		
		let index = indice ? indice : rai_windows_counter;
		let inc = true;
		/*
		for(let c = 0; c < rai_windows_counter; c++) {
			if(raismth.rai_windows[c] === 0) {
				inc = false;	
				index = c;
				dump('[RAISMTH] Replacing window [index: ' + index + ' ] \n');
				break;
			}
		}
		*/
		raismth.rai_windows[index] = doc;
		raismth.rai_windows_ts[index] = ts;
		if(inc) {
			rai_windows_counter++;
			Prefs.setIntPref("extensions.raismth.rai_windows_counter", rai_windows_counter);
		}
	},
}

}});
