function number_format(number, decimals, dec_point, thousands_sep)
{
	var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
	var d = dec_point == undefined ? "," : dec_point;
	var t = thousands_sep == undefined ? "." : thousands_sep, s = n < 0 ? "-" : "";
	var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;

	return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}

// RADIO CONFIG
var stream_status = 0;
var listeners = 0;
var title = 'Cargando...';
var refresh_interval;
var playing = false;
var radio_player = $('body').attr('id') == 'popup_panic_fm' ? 'popup' : 'home';

// POPUPS CONFIG
var profiles = {
	chat: { height:700, width:754, toolbar:0, scrollbars:0, status:0, resizable:0, center:1, createnew:1 },
	panic_fm : { height:100, width:300, toolbar:0, scrollbars:0, status:0, resizable:0, center:1, createnew:0 }
};

$(document).ready(function()
{
	$.expr[':'].external = function(obj){ return !obj.href.match(/^mailto\:/) && (obj.hostname != location.hostname); };
	$('a:external:not(.fancybox), a.external').addClass('external').click(function(){ window.open(this.href); return false; });

	$.cookies.setOptions(cookie_options);

	$.strPad = function(i,l,s) {
		var o = i.toString();
		if (!s) { s = '0'; }
		while (o.length < l) {
			o = s + o;
		}
		return o;
	};

	if ($.browser.msie == true &&
		 parseInt($.browser.version.substr(0,1)) <= 6 &&
		 $.cookies.get('ie6sux') != '1')
	{
		$('body').prepend('<div id="ie6sux"> <h2>¡Actualiza tu navegador, por favor!</h2> <p>Lo sentimos, pero la versión del navegador que estás utilizando es demasiado antigua y no está soportada. Aún podrás navegar por la web, pero puede que no todo funcione correctamente. Te recomendamos que <strong>actualices tu navegador</strong> a la última versión disponible o que pruebes alternativas como <strong>Mozilla Firefox</strong>, <strong>Safari</strong> o <strong>Google Chrome</strong>.</p> <ul> <li class="ie"><a href="http://www.microsoft.com/spain/windows/internet-explorer/">Actualizar Explorer</a></li> <li class="firefox"><a href="http://www.mozilla-europe.org/es/firefox/">Cambiar a Firefox</a></li> <li class="safari"><a href="http://www.apple.com/es/safari/">Cambiar a Safari</a></li> <li class="chrome"><a href="http://www.google.com/chrome/index.html?hl=es">Cambiar a Chrome</a></li> </ul> <a id="nowai" href="#">¡No quiero!</a> </div> ');

		$('#ie6sux #nowai').click(function(){
			$(this).parent().slideUp();
			$.cookies.set('ie6sux', '1');

			return false;
		})
	}

	$(".popup").popup(profiles);

	$("a.close_window").click(function() { window.close(); return false; });

	$("form").submit(function() {
		$(this).find('.submit[name=""]').val('Enviando...').attr('disabled', 'disabled');
		return true;
	});

	$("#top_bar .menu .submenu").mouseout(function()
	{
		$(this).removeClass('active');
	});

	$('#system_message').append('<a href="#" class="close icn">cerrar</a>')
	$('#system_message a.close').click(function(){
		$(this).parent().hide();
		return false;
	});

	$("#newsticker ul").cycle({
		fx: 'scrollUp',
		speed: 250,
		timeout: 3000,
		pause: 1
	});

	$('#poll input').click(function() {
		$(this).closest('form').submit();
		return false;
	});
});
