/**
 * MULTIPLE ONLOAD / ONUNLOAD FUNCTIONS
 *
 * usage: window.onloadFunctions[window.onloadFunctions.length] = function() {
 *            ...your code... e.g. alert('mooo');
 *        };
 *
 */
document.domain = document.domain.split('.').slice(-2).join('.');

if (typeof window.onloadFunctions != 'object') {
	window.onloadOLD = window.onload;
	window.onload = function() { for (i in window.onloadFunctions) { window.onloadFunctions[i](); } };
	window.onloadFunctions = [];
	if (typeof window.onloadOLD == 'function') {
		window.onloadFunctions[window.onloadFunctions.length] = function() { window.onloadOLD(); };
	}
}
if (typeof window.onunloadFunctions != 'object') {
	window.onunloadOLD = window.onunload;
	window.onunload = function() { for (i in window.onunloadFunctions) { window.onunloadFunctions[i](); } };
	window.onunloadFunctions = [];
	if (typeof window.onunloadOLD == 'function') {
		window.onunloadFunctions[window.onunloadFunctions.length] = function() { window.onunloadOLD(); };
	}
}

if (typeof window.rpOnLoginFunctions != 'object') {
	window.RPOnLoginOLD = window.RPOnLogin;
	window.RPOnLogin = function() { for (i in window.rpOnLoginFunctions) { window.rpOnLoginFunctions[i](); } };
	window.rpOnLoginFunctions = [];
	if (typeof window.RPOnLoginOLD == 'function') {
		window.rpOnLoginFunctions[window.rpOnLoginFunctions.length] = function() { window.RPOnLoginOLD(); };
	}
}

function Page() {
	this.vars = new Array();
	for(i in pageEnv) {
		this.vars[i] = pageEnv[i];
	}
	
	this.setVar = function (name, value)
	{
		this.vars[name] = escape(value);
	}
	
	this.getVar = function(name)
	{ 
		return this.vars[name];
	}
	
	this.getGetParam = function(varname)
	{ 
		return this.getGetParamFromUrl(document.location.href,varname);
	}
	
	this.getGetParamFromUrl = function(url, varname)
	{ 
		var qs=url.substring(url.indexOf("?")+1);
		var varvalue = this.getQsFormatValue(varname,qs).replace(/\+/g," ");
		return (typeof decodeURIComponent == 'function') ? decodeURIComponent(varvalue) : varvalue;
	}
	
	this.getQsFormatValue = function(varname,haystack)
	{
		var qsArray = new Array();
		var qsRE = new RegExp("(^|&)(" + varname + ")\=([^&]*)(&|$)");
		qsArray = qsRE.exec(haystack);
		return ( qsArray!=null ) ? qsArray[3] : '';
	}
	
	this.replaceGetParamInUrl = function(url, varname, varvalue)
	{
		var url = new String(url);
		var qsRE = new RegExp("(\\\?|&)(" + varname + ")\=([^&]*)(&|$)");
		var found = url.search(qsRE);
		if (found == -1)
			url+= (url.indexOf('?')>-1?'&':'?')+varname+'='+this.escapeGetParamValue(varvalue);
		else 
			url = url.replace(qsRE,'$1$2='+this.escapeGetParamValue(varvalue)+'$4');
		return url;
	}
	
	this.removeGetParamInUrl = function(url, varname)
	{
		var qsRE = new RegExp("(\\\?|&)" + varname + "\=[^&]*?(&|$)");
		return url.replace(qsRE, '');
	}
	
	this.passthruGetParamsToUrl = function(url, params)
	{
		return this.passthruGetParamsFromUrlToUrl(document.location.href, url, params);
	}
	
	this.passthruGetParamsFromUrlToUrl = function(surl, durl, params)
	{
		for (i in params) {
			var sParamValue = this.getGetParamFromUrl(surl,params[i]);
			var dParamValue = this.getGetParamFromUrl(durl,params[i]);
			if (sParamValue && !dParamValue) {
				durl+= (durl.indexOf('?')>-1?'&':'?')+params[i]+'='+this.escapeGetParamValue(sParamValue);
			}
		}
		return durl;
	}
	
	this.escapeGetParamValue = function( varvalue )
	{
		return escape(varvalue).split('%2C').join(',');
	}
	
	
	this.openPopUp = function(params)
	{
		if (typeof params.width == 'undefined')  params.width  = 100;
		if (typeof params.height == 'undefined') params.height = 100;
		if (typeof params.center == 'undefined') params.center = true;
		if (typeof params.resize == 'undefined') params.resize = false;
		if (typeof params.scroll == 'undefined') params.scroll = true;
		if (typeof params.top == 'undefined')    params.top    = 100;
		if (typeof params.left == 'undefined')   params.left   = 100;
		if (typeof params.name == 'undefined')   params.name   = 'W'+params.width+'x'+params.height+'X'+params.top+'x'+params.left+'y'+(params.resize?'y':'n')+'X'+(params.center?'y':'n')+'X';
		// Update properties if comp. browser
		if (params.center && parseInt(navigator.appVersion) >= 4) {
			params.top = screen.availHeight /2 - params.height / 2;
			params.left = screen.availWidth / 2 - params.width / 2;
		}
		// Open the new window using top and left properties
		var remoteWindow = window.open(params.url, params.name, 'status=no,toolbar=no,menubar=no,location=no,scrollbars='+(params.scroll?'yes':'no')+',width=' + params.width + ',height=' + params.height + ',left=' + params.left + ',top=' + params.top + ',resizable='+(params.resize?'yes':'no,resize=no')+'');
		if (remoteWindow) remoteWindow.focus();
		return true;
	}
	
	this.playStream = function (params)
	{
		if (typeof params.url == 'undefined')               params.url               = "";
		if (typeof params.context_url == 'undefined')       params.context_url       = "";
		if (typeof params.clipinfo == 'undefined')          params.clipinfo          = "";
		if (typeof params.width == 'undefined')             params.width             = 180;
		if (typeof params.height == 'undefined')            params.height            = 180;
		if (typeof params.media_browser_url == 'undefined') params.media_browser_url = "";
		if (typeof params.target == 'undefined')            params.target            = "";
		if (typeof params.bnow_playing == 'undefined')      params.bnow_playing      = true;

		if (typeof zeitgeist != 'object' ) var zeitgeist = new Zeitgeist();
		if (zeitgeist.isBrowserRealPlayer() == true){
			var plyrObj = window.external;
		}
		else if(typeof ActiveXObjects.IERPCtl == 'object'){ // check if player object was passed by iframe content
			var plyrObj = ActiveXObjects.IERPCtl;
		}
		else { // not IE or Rplayer not installed
			document.location.href = params.url;
		}

		if (plyrObj) {
			plyrObj.PlayClip(params.url, params.clipinfo, params.context_url, params.width, params.height, params.media_browser_url, params.target, params.bnow_playing);
		}
	}
	
	this.getCurrentBasePath = function()
	{
		return this.getVar('basepath');
	}
	
	this.getCurrentPagePath = function()
	{ 
		var basePath = this.getVar('basepath');
		if (document.location.href.indexOf(basePath) > -1) {
			var pagePath = document.location.href.substring(document.location.href.indexOf(basePath)+basePath.length);
			return pagePath.substring(0,pagePath.lastIndexOf('/'));
		}
		return false;
	}
	
	this.getCurrentHrefWithNoParams = function()
	{
		if (document.location.href.indexOf('?') > -1) {
			return document.location.href.substring(0, document.location.href.indexOf('?'));
		}
		return document.location.href;
	}
	
	this.guideSrcAppend = null;
	this.getGuideSrcAppend = function()
	{
		if (this.guideSrcAppend == null && this.getVar('edition_code') && this.getVar('page_path')) {
			var viewer = (this.getVar('basepath') == "/guide/") ?  "gb" : (this.getVar('basepath') == "/guide-player/") ?"gp" : "gb";
			this.guideSrcAppend = this.getVar('edition_code') + "_" + viewer + "_" + this.getVar('page_path').split('/')[0];
			var currentSrcCode = this.getGetParam("src").split(',');
			var newSrc = [];
			for (i in currentSrcCode) {
				if (currentSrcCode[i] && currentSrcCode[i].search(new RegExp('^'+this.getVar('edition_code')+'_(gp|gb)_([a-z0-9]+)$')) == -1) {
					newSrc[newSrc.length] = currentSrcCode[i];
				}
			}
			currentSrcCode = newSrc.join(',');
			if (currentSrcCode) {
				this.guideSrcAppend = currentSrcCode + "," + this.guideSrcAppend;
			}
		}
		return this.guideSrcAppend;
	}
	
	this.appendGuideSrcToUrl = function(url)
	{
		var guideSrcAppend = page.getGuideSrcAppend();
		if (guideSrcAppend == null) return url;
		var directSrc = page.getGetParamFromUrl(url, "src");
		return page.replaceGetParamInUrl(url, "src", guideSrcAppend + (directSrc?','+directSrc:'') );
	}
	
	this.appendGuideSrcToFormAction = function(form)
	{
		if (!form.guideSrcAppended) {
			form.action = this.appendGuideSrcToUrl(form.action);
			form.guideSrcAppended = true;
		}
	}
	
	this.parseTypeVars = function(type)
	{
		var typeVars = null;
		var typeSplited = type.split(';');
		if (typeSplited[0]) {
			typeVars = {TYPE : typeSplited[0]};
			for (var i=1; i<typeSplited.length; i++) {
				var pos = typeSplited[i].indexOf(':');
				if (pos > 0) {
					typeVars[typeSplited[i].substring(0,pos)] = typeSplited[i].substring(pos+1);
				}
			}
		}
		return typeVars;
	}

	this.addRTrackingToUrl = function(url, type)
	{
		// determine UrlType (part, ffteaser, fftoplist...)
		var urlProtocol = url.substring(0, url.indexOf('://'));
		// only add RTracking to http urls...
		if (urlProtocol != 'http') {
			return url;
		}
		var urlPath = url.substring(url.indexOf('://')+3);
		var urlDomain = urlPath.split('/')[0];
		var urlTypeVars = this.parseTypeVars(type);
		if (urlTypeVars == null) {
			return url;
		}
		var pagePath = this.getCurrentPagePath();
		if (pagePath) pagePath = pagePath.split('/');
		var editionCode = this.getVar('edition_code');
		switch (urlTypeVars.TYPE) {
			case 'navi':
				var partTracking = (pagePath[0]||'')+'/navi/'+urlTypeVars.NID+'.rx';
				var RTrackParams = '&p='+(pagePath[0]||'')
								+'&sp='+(pagePath[1]||'')
								+'&ssp='+(pagePath[2]||'')
								+'&gctry='+(editionCode||'')
								+'&viewer=na&sn=na&part=('+partTracking+')&area=navi&ltype=na';
				return 'http://'+location.host+'/R/R.'+RTrackParams+'.R/'+urlPath;

			case 'part':			
				var RTrackParams = '&p='+(pagePath[0]||'')
								+'&sp='+(pagePath[1]||'')
								+'&ssp='+(pagePath[2]||'')
								+'&gctry='+(editionCode||'')
								+'&viewer=na&sn=na&part=('+(urlTypeVars.PTID||'')+')&area=na&ltype=na';
				return 'http://'+location.host+'/R/R.'+RTrackParams+'.R/'+urlPath;

			case 'ffteaser':
			case 'fftoplist':
			case 'snteaser':
				var RTrackParams = '&p='+(pagePath[0]||'')
								+'&sp='+(pagePath[1]||'')
								+'&ssp='+(pagePath[2]||'')
								+'&gctry='+(editionCode||'')
								+'&type='+urlTypeVars.TYPE
								+'&domain='+urlDomain;
				return 'http://'+location.host+'/R/R.'+RTrackParams+'.R/'+urlPath;

		}
		return url;
	}
	
	return this;
}
page = new Page();


// (tiny) Zeitgeist functionality
//--------------------------------------------------------------------
function Zeitgeist() {
	
	// Object for caching purpose only
	this.RNCookieNames = [ 'RNZGTP', 'RNUser', 'RNProduct', 'RNPreferences', 'RNPlayer', 'RNFeature', 'RNPC', 'RNSession' ]; 
	this.RNCookies = {};
	
	// zeitgeist.flushRNCookieCache();
	//----------------------------------------------------------------
	this.flushRNCookieCache = function () {
		for (i in this.RNCookieNames) {
			this.RNCookies[this.RNCookieNames[i]] = {};
		}
	}
	this.flushRNCookieCache();
	
	// zeitgeist.getRNCookie(name, type);
	//----------------------------------------------------------------
	this.getRNCookie = function (name, type) {
		if (typeof this.RNCookies[name][type] == 'undefined') {
			var cookietmp = document.cookie.split('; ');
			var RNCookie = [];
			if (cookietmp) {
				for(num1 in cookietmp){
					if(cookietmp[num1] && cookietmp[num1].split('=')[0] == name ){
						reqCookie = cookietmp[num1].substr(name.length);
						for(num2 in reqCookie.split('&')){
							var varname = reqCookie.split('&')[num2].split('=')[0];
							var varvalue = reqCookie.split('&')[num2].split('=')[1];
							if (varname) {
								eval('RNCookie.'+varname+' = "'+varvalue+'";');
							}
						}
					}
				}
			}			
			this.RNCookies[name][type] = (typeof RNCookie[type] == 'undefined') ? '' : RNCookie[type];
		}
		return this.RNCookies[name][type];
	}
	
	// zeitgeist.getSNValue();
	//----------------------------------------------------------------
	this.getSNValue = function () {
		var snValue = this.getRNCookie('RNProduct', 'SN') || '';
		if (!snValue && this.isThirdPartyContext()) {
			snValue = this.getRNCookie('RNZGTP', 'SN') || '';
		}
		return snValue;
	}
	
	// zeitgeist.hasSNValue( snValueToCheck );
	//----------------------------------------------------------------
	this.hasSNValue = function (snValueToCheck) {
		var snValue = '|'+this.getSNValue().toLowerCase()+'|';
		return snValue.indexOf('|'+snValueToCheck.toLowerCase()+'|') == -1 ? false : true;
	}
	
	// zeitgeist.hasPass( passHandle );
	//----------------------------------------------------------------
	this.passHandles = ['radiopass', 'radiopass_lite', 'superpass', 'superpass_eu','playerplus'];
	this.hasPass = function (passHandle) {
		switch (passHandle) {
			case 'radiopass': return ( 
					this.hasSNValue('rd')      // rd   = RadioPass Germany
					|| this.hasSNValue('rr')   // rr   = RadioPass France
					|| this.hasSNValue('rs')   // rs   = RadioPass Spain
					|| this.hasSNValue('rt')   // rt   = RadioPass Italy
					|| this.hasSNValue('s324') // s324 = RealOne RadioPass
					|| this.hasSNValue('s325') // s325 = RealOne RadioPass Basic
				);
			// SuperPass (any)
			case 'superpass': return (
					  this.hasPass('superpass_eu')
				);
			// SuperPass Europe
			case 'superpass_eu': return (
					  this.hasSNValue('re')
				   || this.hasSNValue('ru')
				   || this.hasSNValue('ru1')
				   || this.hasSNValue('ru3')
				);
			case 'radiopass_lite': return (
					  this.hasSNValue('S611')
				);
			case 'realmusic': return (
					this.hasSNValue('rk') 		// rk   = Realmusic UK
					|| this.hasSNValue('s780')  // s780 = Realmusic UK
				);
			case 'playerplus': return (
					  this.hasSNValue('lf10')
				   || this.hasSNValue('lf')
				   || this.hasSNValue('pp')
				   || this.hasSNValue('vf')
				);
		}
		return false;
	}
	// zeitgeist.hasProducts();
	//----------------------------------------------------------------
	this.hasProducts = function() {
		return (this.getRNCookie('RNProduct', 'SN')=='||' || this.getRNCookie('RNProduct', 'SN')=='') ? false : true;
	}
	
	// zeitgeist.isBrowserRealPlayer();
	//----------------------------------------------------------------
	this.isBrowserRealPlayer = function () {
		return (String(navigator.userAgent).indexOf('(R1') > -1 ? true : false) ||         // Windows Player
				(String(navigator.userAgent).indexOf('RealPlayer/') > -1 ? true : false);  // Mac Player
	}
	
	// zeitgeist.isUserLoggedIn();
	//----------------------------------------------------------------
	this.isUserLoggedIn = function () {
		// check customer Id
		return (this.getRNCookie('RNUser', 'CI')=='||' || this.getRNCookie('RNUser', 'CI')=='') ? false : true;
	}
	
	// zeitgeist.isUserOnEdition(editionCode);
	//----------------------------------------------------------------
	this.isUserOnEdition = function(editionCode) {
		return (page.getVar('edition_code')==editionCode);
	}
	
	// zeitgeist.isThirdPartyContext();
	//----------------------------------------------------------------
	this.isThirdPartyContext = function () {
		var inThirdPartyContext = false;
		// if it is not allowed to access the top location
		// we should be in a 'Third Party Context'
		try { if (top.location == '') { } }
		catch(e) { inThirdPartyContext = true; }
		return inThirdPartyContext;
	}
	
	
	// zeitgeist.doThirdPartyCookieCache();
	//----------------------------------------------------------------
	this.doThirdPartyCookieCache = function () {
		// do only update the RNZGTP when we are NOT in TPC
		if (!this.isThirdPartyContext()) {
			var cookieValue = 'CV=1.0';
			cookieValue+='&SN='+this.getRNCookie('RNProduct', 'SN');
			cookieValue+='&SNA='+this.getRNCookie('RNProduct', 'SNA');
			// update RNZGTP cookie
			try { document.cookie = 'RNZGTP='+(cookieValue)+'; path=/; domain=real.com'; }
			catch(e) { /* do nothing */ }
		}
	}
	
	this.detector = {
		zeitgeist: this,
		result: false,
		window: self,
		startDetection: function () { with (this.window) {
				var oThis = this;
				var detectIFrame_name = 'Zeitgeist_detectIFrame';
				var detectIFrame = document.createElement('iframe');
				detectIFrame.setAttribute('width', 0);
				detectIFrame.setAttribute('height', 0);
				detectIFrame.setAttribute('frameborder', 0);
				detectIFrame.setAttribute('name', detectIFrame_name+'NAME');
				detectIFrame.setAttribute('id', detectIFrame_name+'ID');
				detectIFrame.setAttribute('src', page.getVar('basepath')+'inc/guide/zeitgeist_detector.html?time='+(new Date().getTime()) );
				detectIFrame.loaded = false;
				detectIFrame.onload = detectIFrame.onreadystatechange = function (event) {
					try {
						var frame = oThis.window.frames[detectIFrame.name] || oThis.window.frames[detectIFrame.id];
						if ( (typeof frame.readyState == 'undefined' || frame.readyState=="complete") && !detectIFrame.loaded) {
							detectIFrame.loaded = true;
							if (!frame.detectionResult) {
								frame.onDetectionResult = function() {
									oThis.onDetectionResult(frame.detectionResult);
								}
							}
							else {
								oThis.onDetectionResult(frame.detectionResult);
							}
						}
					}
					catch (e) {}
				};
				document.body.appendChild(detectIFrame);
		}},
		onDetectionResult: function (detectionResult) {
			this.result = detectionResult;
		},
		// compVersions(v1,v2)
		// if  v1  is higher than  v2  return  2
		// if  v1  is equal to     v2  return  1
		// if  v1  is lower that   v2  return  0
		compVersions: function (v1,v2) {
			if (String(v1) == String(v2)) return 1;
			v1 = v1.split('.'); v2 = v2.split('.');
			if (v1[0] == v2[0]) return this.compVersions( v1.slice(1,v1.length).join('.'), v2.slice(1,v2.length).join('.') );
			return (parseInt(v1[0]?v1[0]:0) > parseInt(v2[0]?v2[0]:0)) ? 2 : 0;
		}
	};
	
	this.isPlayerCompatible = function(towhat)
	{
		if (!this.detector.result) return false;
		return this.detector.result['realplayer_'+towhat+'_compatible'];
	}
	this.isOperatingSystem = function()
	{
		if (!this.detector.result) return false;
		for (var i=0; i<arguments.length; i++) {
			if (this.detector.result['operating_system'].indexOf(arguments[i]) > -1) return true;
		}
		return false;
		
	}
	return this;
}
zeitgeist = new Zeitgeist();
zeitgeist.doThirdPartyCookieCache();
window.onloadFunctions[window.onloadFunctions.length] = function() {
	zeitgeist.detector.startDetection();
};

document.write('<style type="text/css"> .noscript { display: none; } </style>');

if (zeitgeist.isUserLoggedIn())
	document.write('<style type="text/css"> .userIsNotLoggedIn { display: none; } </style>');
else 
	document.write('<style type="text/css"> .userIsLoggedIn { display: none; } </style>');

if (zeitgeist.isBrowserRealPlayer())
	document.write('<style type="text/css"> .browserIsNotRealPlayer { display: none; } </style>');
else 
	document.write('<style type="text/css"> .browserIsRealPlayer { display: none; } </style>');

for (i in zeitgeist.passHandles) {
	if (zeitgeist.hasPass(zeitgeist.passHandles[i]))
		document.write('<style type="text/css"> .userHasNotPass_'+zeitgeist.passHandles[i]+' { display: none; } </style>');
	else 
		document.write('<style type="text/css"> .userHasPass_'+zeitgeist.passHandles[i]+' { display: none; } </style>');
}

// Browser / Player switcher
//--------------------------------------------------------------------
if (zeitgeist.isBrowserRealPlayer()) {
	if (page.getCurrentBasePath().indexOf('/guide-player/') == -1 && !page.getVar('previewmode')) {
		document.location.href = document.location.href
			.split('/guide-browser/').join('/guide-player/')
			.split('/guide/').join('/guide-player/');
	}
}
else {
	if (page.getCurrentBasePath().indexOf('/guide-player/') > -1 && !page.getVar('previewmode')) {
		document.location.href = document.location.href.split('/guide-player/').join('/guide/');
	}
}

function processClicks(e)
{
	var elem = null;
	if (!e) var e = window.event;
	if (e && e.target) elem = e.target;
	else if (window && window.event) elem = window.event.srcElement
	
	
	if (elem && ('IMG' == elem.tagName || 'FONT' == elem.tagName || 'SPAN' == elem.tagName || 'P' == elem.tagName)) {
		if (elem.parentNode && elem.parentNode.tagName == 'A') {
			elem = elem.parentNode;
		}
	}
	
	if (elem && 'A' == elem.tagName && elem.href.indexOf('javascript:') != 0) {
		
		if (elem.href.substring(0,1) == '/') {
			elem.href = 'http://'+location.host+elem.href;
		}
		if (!elem.originalHref) {
			elem.originalHref = elem.href;
		}
		
		// Set cookie lastclickedurl
		document.cookie='lastclickedurl='+elem.originalHref+'; path=/; domain=real.com;';
		
		// is href url a stream url?!
		var searchRE = new RegExp(/(\/start.real.com\/|\.(rm|ram|smi|smil)(\?|$)|(\?|&)rp(url|contextpane)=)/);
		elem.hrefIsStreamUrl = elem.href.search(searchRE) == -1 ? false : true;
		
		// when RealPlayer is our Browser, determine whenether 
		// this lik should be loaded in the Browser Tab or in 
		// the RealGuide Tab
		if (!elem.target) {
			var inPlayer = zeitgeist.isBrowserRealPlayer();
			if (!elem.hrefIsStreamUrl) { // only when it is not a stream url!
				var searchRE = new RegExp("/(guide|guide-browser|guide-player|guide-superpass|cms|edition|digestive.euro.real.com/tonepass)/");
				if (elem.href.search(searchRE) == -1) { // not guide internal
					elem.target = inPlayer ? '_rpbrowser' : '_blank';
				}
				else if (inPlayer) { // guide internal & Browser is RealPlayer
					var searchRE = new RegExp("/(music)/");
					if (elem.href.search(searchRE) > -1) { // musicguide
						elem.target = '_rpmusicguide';
					}
					else { // other guide
						elem.target = '_rphome';
					}
				}
			}
		}
		var searchRE = new RegExp("/(uk|de|germany|fr|france|it|italy|es|spain).music.euro.real.com/");
		
		if (elem.originalHref.search(searchRE) > -1) {
			elem.onclick = function () 
			{   
				openRealMusic( elem.originalHref, document.domain.split('.').slice(-2).join('.'));
				return false;	
			}
		}

		// {{{ SRC append-o-rama
		//guide-SRC
		var searchRE = new RegExp("/(guide|guide-browser|guide-player|guide-superpass|cms)/");
		if (elem.href.search(searchRE) > -1) { // guide internal
			elem.href = page.passthruGetParamsToUrl(elem.href, ['d','DC','moo','gooey','debug','src','tps','site','pcode','cpath','rsrc','opage','show-guide']);
			if (self.layercake) { // layer cake is shown, so add a SRC thats says so...
				elem.href = self.layercake.appendShownSrc(elem.href);
			}
		}
		else {
			var searchRE = new RegExp("(real.com|realnetworks.com)");
			if (elem.href.search(searchRE) > -1) { // realnetworks
				elem.href = page.passthruGetParamsToUrl(elem.href, ['DC','tps','pcode','cpath','rsrc','opage']);
				if (!elem.srcAppended){
					elem.href = page.appendGuideSrcToUrl(elem.href);
					elem.srcAppended = true;
				}
			}
		}
		// }}} SRC append-o-rama
		
		
		if (!elem.typeVars && elem.type) {
			elem.typeVars = page.parseTypeVars(elem.type);
		}
		
		if (!elem.RTrackAttached) {
			// {{{
			// don't ask about this fuckin' code below...
			var OLD_innerHTML = elem.innerHTML.indexOf('www.')>-1 ? elem.innerHTML : null;
			elem.href = page.addRTrackingToUrl(elem.href, elem.type);
			if (OLD_innerHTML) elem.innerHTML = OLD_innerHTML;
			// }}}
			elem.RTrackAttached = true;
		}
		
		if (elem.hrefIsStreamUrl && (!zeitgeist.detector.result.operating_system=='mac' && zeitgeist.detector.result.browser_name) && page.getVar('use_contextpane') == true && elem.typeVars && elem.typeVars.TC) {
			if (elem.typeVars.TC != 'radiotv' && elem.typeVars.TC != 'radiopass') {
				if (page.getVar('edition_code') != "jp" || (page.getVar('edition_code') == "jp" && (elem.typeVars.TC == "gravureidol" || elem.typeVars.TC ==  "entertainment" || elem.typeVars.TC == "movies"))) {
					elem.onclick = function () 
					{
						page.playStream({ url: this.href, height: 250, context_url: 'http://'+location.host+'/guide-player/contextpane/'+elem.typeVars.TC+'/' }); 
						return false; 
					}
				}
			}
		}	
		if (page.getCurrentHrefWithNoParams(document.location.href) == page.getQsFormatValue('rpurl', elem.href)) {
			elem.href = page.removeGetParamInUrl(elem.href, 'rpurl');
		}
		
		
		if (elem.hrefIsStreamUrl && ('|uk|de|'.indexOf('|'+page.getVar('edition_code')+'|') > -1) ) {
			if (!zeitgeist.isBrowserRealPlayer() && !zeitgeist.isPlayerCompatible('realguide') && !zeitgeist.isOperatingSystem('linux')) {
				elem.onclick = function () {
					page.openPopUp({url:'/guide/inc/guide_player_required_popup/'+page.getVar('edition_code')+'.html',width:350,height:50,center:true});
					return false; // break here
				}
			}
		}
		
		elem.type = null;
		return true;
	}
}

document.onmousedown = processClicks;
if (document.captureEvents) document.captureEvents(Event.MOUSEDOWN);

ActiveXObjects = {};

window.onloadFunctions[window.onloadFunctions.length] = function() {
	var dExp = new Date();
	dExp.setTime(dExp.getTime() + (1*24*60*60*1000));// 1 day
	document.cookie = 'homeguide=' + location.host + '; path=/; domain=real.com; expires=' + dExp.toGMTString();	
};


/**
 * layercake: Special Guide Header for Big Advertisement
 */
if (page.getCurrentBasePath().indexOf('/guide/') > -1
	&& page.getGetParam('src').indexOf('.layercake.') > -1
	&& page.getGetParam('src').indexOf(',layercakeshown') == -1
	&& page.getVar('edition_code') in {'uk':'uk'}) {
	self.layercake = {
		appendShownSrc: function(href)
		{
			if (page.getGetParamFromUrl(href,'src').indexOf('layercakeshown') > -1) {
				return href;
			}
			return page.replaceGetParamInUrl(href, 'src', page.getGetParamFromUrl(href,'src')+',layercakeshown');
		},
		getHtmlCode: function()
		{
			return '<iframe style="width:100%;height:375px;margin-bottom:5px;" scrolling="no" frameborder="0" src="/guide_layercake_header/'+self.location.search+'"></iframe>';
		}
	}
	document.write('<style type="text/css"> .guide div.hdr { display: none; } .guide div.hdrlayercake { display: block; } </style>');
}
function dumpObject(obj, prefix) { 
	var str = '';
	for (var i in obj) {
		if (typeof obj[i] != 'function') { str+= '<span style="color:gray">'+prefix+'</span>'+i+' = '+obj[i]+'<br>';}
		if (typeof obj[i] == 'object') { str+= dumpObject(obj[i],prefix+i+'.');}
	}
	return str;
};
/*
if (page.getGetParam('debugtest')){

var plyrObj = window.external;
alert (plyrObj.versionInfo);


}*/
//additional guide logic per edition
document.write( "<scr" + "ipt src='/guide/inc/guide/guide_"+page.getVar('edition_code')+".js'><\/scr" + "ipt>" ); 
