// DECLARACIÓN DE VARIABLES GLOBALES
var chatIntervalId;
var monthNames = new Array('Enero','Febrero','Marzo','Abril','Mayo','Junio', 'Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre');
//
function wordwrap(str, width, brk, cut) {
    brk = brk || '\n';
    width = width || 75;
    cut = cut || false;

    if (!str) { return str; }

    var regex = '.{1,' +width+ '}(\\s|$)' + (cut ? '|.{' +width+ '}|.+$' : '|\\S+?(\\s|$)');

    return str.match( RegExp(regex, 'g') ).join( brk );

}
// Dada una url, esta función obtiene el contenido mediante ajax y lo pone en #content
function redirectAjax(url) {
    $.ajax({
        beforeSend:function (XMLHttpRequest) {
            $("#busy-indicator").fadeIn();
        },
        complete:function (XMLHttpRequest, textStatus) {
            $("#busy-indicator").fadeOut();
        },
        dataType:"html",
        success:function (data, textStatus) {
            $("#content").html(data);
        },
        url: url
    });
}
// Dado el id de un boton del menu, lo selecciona
function selectButton(id) {
    // Obtengo el id del boton seleccionado:
    var idSelected = $('#menu-layout .selected').attr('id');

    if (id != idSelected) {
        $('#'+idSelected).removeClass('selected');
        $('#'+id).addClass('selected');
        // Si el button no es el de inicio:
        if (id != 'boton1') {
            clearInterval(chatIntervalId);
        }
    }
}
//
$(document).ready(function() {
    // Defino las acciones para los eventos de los botones del menu:
    $('#menu-layout a').bind({
        click: function(event) {
            event.preventDefault();

            var parent = $(this).parent();
            var id = parent.attr('id');

            selectButton(id);
        },
        mouseenter: function() {
            $(this).animate({color:'#88E713'}, 100, 'linear');
        },
        mouseleave :function() {
            $(this).animate({color:'#FFF'}, 100, 'linear');
        }
    });
    // Drag el reproductor:
    $('#reproductor').draggable({
        cancel:'.jp-volume-bar, jp-progress'
    });
    // Login toolbar:
    $('#login a').button();
    // Colortip
    $('[title]').colorTip({
        color:'black'
    });
});
