/**
 *
 *//*
function loadScript(url, callback){
    var script = document.createElement("script");
    script.type = "text/javascript";

    if (script.readyState){  //IE
        script.onreadystatechange = function(){
        if (script.readyState == "loaded" ||
            script.readyState == "complete"){
                script.onreadystatechange = null;
                callback();
            }
        };
    } else {  //Otros
        script.onload = function(){
            callback();
        };
    }

    script.src = url;
    document.getElementsByTagName("head")[0].appendChild(script);
}
*/
/**
 *
 */
function get_tamanio_ventana() {
    var dimensiones = [0, 0];
    if (typeof window.innerWidth != 'undefined') {
        dimensiones = [
            window.innerWidth,
            window.innerHeight
        ];
    }
    else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
        dimensiones = [
            document.documentElement.clientWidth,
            document.documentElement.clientHeight
        ];
    }
    else {
        dimensiones = [
            document.getElementsByTagName('body')[0].clientWidth,
            document.getElementsByTagName('body')[0].clientHeight
        ];
    }
    return dimensiones;
}

/**
 *
 */
function iniciar_interfaz(){
    // Variables
    var height_footer   = $('#footer').css('height').replace('px', '');
  
    // Calculos
    var tamanio_ventana = get_tamanio_ventana();
    var new_height_content = tamanio_ventana[1] - height_footer;
    var header_height   = new_height_content / 4;

    $('#fondo').css('height', new_height_content);
    $('#content').css('height', new_height_content);
    $('#header').css('height', header_height);
    $('#fondo').html('<img src="images/' + fondo + '" />').fadeIn(3000);
    
    return tamanio_ventana;
}


function iniciar_interfaz_inicio(){
    // Variables
    //var height_footer   = $('#footer1').css('height').replace('px', '');
  
    // Calculos
    var tamanio_ventana     = get_tamanio_ventana();
    var new_height_content  = tamanio_ventana[1];
    var header_height       = new_height_content / 4;

    $('#fondo').css({'height': new_height_content});
    $('#content').css('height', new_height_content);
    $('#header').css('height', header_height);
    $('.carrusel_noticias').css('top', 10);
    //$('#fondo').css('background', 'url(images/' + fondos[0] + ')').fadeIn(1000);    
    $('#fondo').html('<img src="images/' + fondo + '" />').fadeIn(3000);
    /*
    var arrImagenes = fondos;
    var imagenActual = arrImagenes[0];
    var tiempo = 5000;
    var id_contenedor = 'fondo'

    var i=0;
    setInterval( function(){
        i++;
        if (i==arrImagenes.length){
            i=0;
        }
        sigImagen = arrImagenes[i];
        imagenActual = sigImagen;
        cambiarImagenFondo(imagenActual, id_contenedor);
    }, tiempo);
    */
    return tamanio_ventana;
}

/**
 *
 */
function actualizar_interfaz_inicio(){
// Calculos
    var tamanio_ventana     = get_tamanio_ventana();
    var new_height_content  = tamanio_ventana[1];
    //var header_height       = new_height_content / 4;
    
    // Asignacion de nuevos valores
    $('#fondo').css({'height': new_height_content});
    $('#content').css('height', new_height_content);
    
    return tamanio_ventana;
}

/**
 *
 */
function cambiarImagenFondo(nuevaImagen, contenedor){
    var contenedor = $('#' + contenedor);
    contenedor.fadeOut(500, function(){
        contenedor.css('background', 'url(images/' + nuevaImagen + ')').fadeIn(500);
    });
}


/**
 *
 */
function actualizar_interfaz(){
    // Variables
    var height_footer = 0;
    height_footer   = $('#footer').css('height').replace('px', '');
  
    // Calculos
    var tamanio_ventana     = get_tamanio_ventana();
    var new_height_content  = tamanio_ventana[1] - height_footer;
    var header_height       = new_height_content / 4;
    
    // Asignacion de nuevos valores
    $('#fondo').css('height', new_height_content);
    $('#content').css('height', new_height_content);
    $('#header').css('height', header_height);
    
    return tamanio_ventana;
}

/**
 *
 */
function getQueryParams(qs) {
    qs = qs.split("+").join(" ");
    var params = {},
        tokens,
        re = /[?&]?([^=]+)=([^&]*)/g;

    while (tokens = re.exec(qs)) {
        params[decodeURIComponent(tokens[1])]
            = decodeURIComponent(tokens[2]);
    }

    return params;
}

/**
 *
 */
function updateTips( t ) {
    tips.text( t ).addClass( "ui-state-highlight" );
    setTimeout(function() {
        tips.removeClass( "ui-state-highlight", 1500 );
    }, 500 );
}

/**
 *
 */
function checkLength( o, n, min, max ) {
    if ( o.val().length > max || o.val().length < min ) {
        o.addClass( "ui-state-error" );
        updateTips( "Length of " + n + " must be between " +
        min + " and " + max + "." );
        return false;
    } else {
        return true;
    }
}

/**
 *
 */
function checkRegexp( o, regexp, n ) {
    if ( !( regexp.test( o.val() ) ) ) {
        o.addClass( "ui-state-error" );
        updateTips( n );
        return false;
    } else {
        return true;
    }
}
/*
window.onresize = function() {
    actualizar_interfaz();
};

*/

function handleSliderChange(e, ui) {
    var maxScroll = $("#content-scroll").attr("scrollWidth") - $("#content-scroll").width();
    $("#content-scroll").animate({scrollLeft: ui.value * (maxScroll / 100)}, 1000);
}

function handleSliderSlide(e, ui) {
    var maxScroll = $("#content-scroll").attr("scrollWidth") - $("#content-scroll").width();
    $("#content-scroll").attr({scrollLeft: ui.value * (maxScroll / 100)});  
}

function handleBioSliderChange(e, ui) {  
    var maxScroll = $("#content-scroll").attr("scrollHeight") - $("#content-scroll").height();
    $("#content-scroll").animate({scrollTop: (100-ui.value) * (maxScroll / 100)}, 1000);
}

function handleBioSliderSlide(e, ui) {
  var maxScroll = $("#content-scroll").attr("scrollHeight") - $("#content-scroll").height();
  $("#content-scroll").attr({scrollTop: (100-ui.value) * (maxScroll / 100)});
}
