var _r4dio = function (_method) {
	switch (_method) {
		case 'version':
			return '1.02.26';
			break;
		case 'showFlashPlayer':
			_jx('reproductor','write','<div style="margin:12px 16px 0px 17px;font-size:10px"><div id="player">Este reproductor requiere<br><a href="http://get.adobe.com/es/flashplayer/" target="_blank">Flash Player</a>.</div></div>');
			var flashvars = { file:"http://r4diog.com:15000/;stream.nsv", type:"mp3", autostart:"true", backcolor:"0x151515", frontcolor:"0xAAAAAA", lightcolor:"0xFFFFFF", screencolor:"0x151515", showeq:"true", showdigits:"false", showicons:"false", showstop:"true"}
			var params = { allowfullscreen:"false", allowscriptaccess:"always" }
			var attributes = { id:"radioplayer", name:"radioplayer" }
			swfobject.embedSWF("http://www.r4diog.com/mediaplayer317.swf", "player", "154", "56", "9.0.115", false, flashvars, params, attributes);
			_jx('bRepClosed','visible',false);
			_jx('bRepWmp','visible',false);
			_jx('bRepFlash','visible',true);
			playerLoaded=1;
			r4dioMode=1;
			break;
		case 'showWMPPlayer':
			_jx('reproductor','write','<div style="height:12px;">&nbsp;</div><embed loop="0" filename="http://r4diog.com:15000" autostart="true" showstatusbar="1" type="application/x-mplayer2" controller="true" transparentstart="0" enablecontextmenu="false" name="mediaplayer1" height="44" width="154"></embed>');
			_jx('bRepFlash','visible',false);
			_jx('bRepClosed','visible',false);
			_jx('bRepWmp','visible',true);
			playerLoaded=0;
			r4dioMode=2;
			break;
		case 'closePlayer':
			_jx('reproductor','write','<div style="margin:12px 16px 14px 16px;font-size:10px">No hay ning&uacute;n reproductor abierto.</div>');
			_jx('bRepFlash','visible',false);
			_jx('bRepWmp','visible',false);
			_jx('bRepClosed','visible',true);
			playerLoaded=0;
			r4dioMode=0;
			break;
		case 'reload':
			switch (r4dioMode) {
				case 1:
					_r4dio('showFlashPlayer');
					break;
				case 2:
					_r4dio('showWMPPlayer');
					break;
				default:
					_r4dio('closePlayer');
			}
			break;
		case 'updateInfo':
			var linfo = document.getElementById('locInfo');
			linfo.src = linfo.src;
			_infoTimer = 0;
			break;
		case 'hideMenu':
			_jx('menuNone','visible',false);
			_jx('menuNoticias','visible',false);
			_jx('menuChat','visible',false);
			_jx('menuProgramacion','visible',false);
			_jx('menuAgreganos','visible',false);
			_jx('menuContacto','visible',false);
			break;
		case 'hideContent':
			_jx('tab-noticias','visible',false);
			_jx('tab-chat','visible',false);
			_jx('tab-programacion','visible',false);
			_jx('tab-agreganos','visible',false);
			_jx('tab-contacto','visible',false);
			_jx('tab-none','visible',false);
			break;
		case 'addPet':
			var p=encodeURIComponent(document.getElementById('mensj').value);
			if (p!='' && petUpdating==0) { petUpdating=1; _petTimer=0; _jx('functions/interactivo.php','post','do=addPet&s='+encodeURIComponent(_timer('status'))+'&p='+p);}
			break;
		case 'delPet':
			if (p!='' && petUpdating==0) { petUpdating=1; _petTimer=0; _jx('functions/interactivo.php','post','do=delPet&p='+arguments[1]);}
			break;
		case 'chooseRoom':
			chatUpdating=1;
			_jx('msala'+arguments[1],'write','Entrando...');
			_jx('includes/chat.php','post','do=getRoom&id='+arguments[1]);
			break;
		case 'updateChat':
			if (chatUpdating==0) {
				chatUpdating=1;
				_jx('chat-room','get','includes/chat.php'+chatPars,'_chatTimer=0;_chatDelay=0;chatUpdating=0;');
			}
			break;
		case 'switchValue':
			var _f = document.chatForm;
			switch (arguments[1]) {
				case 'bold':
					if (_f.setbold.value=='B*') {
						_f.setbold.value='B';
						_f.fbold.value='';
						_f.msg.style.fontWeight='normal';
					} else {
						_f.setbold.value='B*';
						_f.fbold.value='X';
						_f.msg.style.fontWeight='bold';
					}
					break;
				case 'underline':
					if (_f.setunderline.value=='U*') {
						_f.setunderline.value='U';
						_f.funderline.value='';
						_f.msg.style.textDecoration='none';
					} else {
						_f.setunderline.value='U*';
						_f.funderline.value='X';
						_f.msg.style.textDecoration='underline';
					}
					break;
				case 'italic': 
					if (_f.setitalic.value=='I*') {
						_f.setitalic.value='I';
						_f.fitalic.value='';
						_f.msg.style.fontStyle='';
					} else {
						_f.setitalic.value='I*';
						_f.fitalic.value='X';
						_f.msg.style.fontStyle='italic';
					}
					break;
				case 'color':
					_f.fcolor.value=_f.setcolor.value;
					_f.msg.style.color='#'+_f.setcolor.value;
			}
			break;
		case 'getValues':
			var sformat='<span style="';
			var eformat='</span>';
			var _f = document.chatForm;

			if(_f.fbold.value=="X"){ sformat+='font-weight:bold;'; }
			if(_f.funderline.value=="X"){ sformat+='text-decoration:underline;'; }
			if(_f.fitalic.value=="X"){ sformat+='font-style:italic;'; }
			if(_f.fcolor.value){ sformat+='color:#'+(_f.fcolor.value.length>6?_f.fcolor.value.substr(0,6):_f.fcolor.value)+';'; }
			sformat+='">';
			return 's='+escape(sformat)+'&e='+escape(eformat);
			break;
		case 'getPlace':
			return iVis('tab-noticias')?1:iVis('tab-chat')?chatMode==0?2:100+chatMode:iVis('tab-programacion')?3:iVis('tab-agreganos')?4:iVis('tab-contacto')?5:0;
	}
};
var _timer = function (_method) {
	switch (_method) {
		case 'tick':
			_currentTimer++;
			_chatTimer++;
			_petTimer++;
			_infoTimer++;
			if (_chatTimer > 4 && chatUpdating==1) {_chatDelay++; if (_chatDelay > _maxChatDelay) { _maxChatDelay = _chatDelay; if (_chatDelay>90 && chatUpdating==1) { chatUpdating=0;_chatDelay=0; }} }
			if (_petTimer > 19 && petUpdating==1) {_petDelay++; if (_petDelay > _maxPetDelay) { _maxPetDelay = _petDelay; if (_petDelay>90 && petUpdating==1) { petUpdating=0;_petDelay=0; }} }
			_timer('exec');
			break;
		case 'status':
			return '_currentTimer='+_currentTimer+' | _chatTimer='+_chatTimer+' | _petTimer='+_petTimer+' | _infoTimer='+_infoTimer+' | _chatDelay='+_chatDelay+' | _petDelay='+_petDelay+' | _maxChatDelay='+_maxChatDelay+' | _maxPetDelay='+_maxPetDelay+' | chatUpdating='+chatUpdating+' | chatMode='+chatMode+' | chatPars=\''+chatPars+'\' | petUpdating='+petUpdating+' | petPars=\''+petPars+'\' | place='+_r4dio('getPlace')+' | r4dioMode='+r4dioMode+' | r4diog.js ver '+_r4dio('version');
			break;
		case 'exec':
			if (_infoTimer==30) { _r4dio('updateInfo'); }
			if (_chatTimer>=5 && chatUpdating==0) {
				if (document.getElementById('tab-chat').style.display=='block') {
					if (chatMode==0) { 
						chatUpdating=1;_jx('chat-content','get','includes/chat.php','_chatTimer=0;_chatDelay=0;chatUpdating=0;'); 
					} else { 
						if (document.getElementById('chat-room')) {
							chatUpdating=1;_jx('chat-room','get','includes/chat.php'+chatPars,'_chatTimer=0;_chatDelay=0;chatUpdating=0;');
						} else {
							chatMode=0;
							chatUpdating=0;
							chatPars='';
						}
					}
				} else {
				_chatTimer=0;
				}
			}
			if (_petTimer>=20 && petUpdating==0) { petUpdating=1;_jx('functions/interactivo.php','post','do=update&s='+encodeURIComponent(_timer('status'))); }
	}
};

function interfaceLoaded() {
	_jx('fullpage','visible',false);
	_jx('fullpage','write','');
	_petTimer=16;
	setInterval('_timer(\'tick\');',1000);
}
function register() {
	a=arguments[0];
	_r4dio('hideMenu');
	_r4dio('hideContent');
	_jx('menuNone','visible',true);
	_jx('tab-none','write','<div align="center" style="color:#FFF; font-size:14px;">Cargando...</div>');
	_jx('tab-none','visible',true);
	_jx('tab-none','get','includes/registro.php'+(a?'?'+a:''),(a=='s=2'?'_jx(\'regform\',\'disablesubmit\');':''));
}
function activate() {
	u=arguments[0];
	c=arguments[1];
	d=arguments[2]?arguments[2]:'';
	c=c==''?'[!!]':c;
	u=u==''?'[!!]':u;
	if(c=='[!!]'){
		alert('Escriba el codigo de activacion.');
	} else if(u=='[!!]') {
		alert('Hay un error de perdida de datos en el formulario.');
	} else {
		_jx('ret_act','write','<strong>Activando...</strong>');
		_jx('functions/register.php','post','do=activate&u='+escape(u)+'&c='+escape(c)+'&d='+escape(d));
	}
}
function iVis(_o) {
	try {rv = document.getElementById(_o).style.display; }
	catch(e) {rv='error';}
	return rv=='block'?true:false;
}

_currentTimer=0;
_chatTimer=0;
_petTimer=0;
_infoTimer=0;

// Debug timers
_chatDelay=0;
_petDelay=0;
_maxChatDelay=0;
_maxPetDelay=0;

r4dioMode=0;
chatMode=0;
chatUpdating=0;
chatPars='';
petUpdating=0;
petPars='';