
sustituyeImg = function(selector,image,width)
{
    var imagenesBase = "imagenes/" + sustituyeImg.pagina + "/";
    $(selector).attr('src',imagenesBase + image);
}

function setPagina(pagina)
{
    sustituyeImg.pagina = pagina;
    document.title = pagina;
}

sustituyeFlash = function(selector,file,w,h,inicial)
{
    flashembed(selector, {
        src: file,
        width: w,
        height: h,
        w3c: true,
        wmode: 'transparent'
    }, {
        flashVarText:"flash/section/"+inicial
    }
    );
}
/*
 * Lo ponemos en una función para
 * que sea accesible desde flash
 *
 **/
function toggleCompartir()
{
    $('#comparteSitio').slideToggle();
}

function animaCompartir()
{
    $('#comparteLnk').click(function(){
        toggleCompartir();
        return false;
    });

    $('#comparteSitio #cerrar').click(function(){
        toggleCompartir();
        return false;
    });
}

function animaProductShot()
{
    $("#productShot a").hover(
        function(){ $('#productSection').fadeIn("fast"); },
        function(){ $('#productSection').fadeOut(); }
    );
}
function animaRegistrate()
{
    $("#registrate a").hover(
        function(){ $('#registrateBanner').fadeIn("fast"); },
        function(){ $('#registrateBanner').fadeOut(); }
    );
}

function loadMovie(file)
{
    var movie = $("#videoInterior object")[0];
    movie.loadMovieUrl("flash/section/"+file);
}

function inicializaPagina()
{   

    var name = $.url.attr("file").split(".")[0];
    setPagina(name);

    var subseccion = $.url.param("s");
    
    if(subseccion == 'faqs')
    {
	var link  = $('#menuSuperior li a').get(3);
	$(link).removeClass('activo');
	link = $('#menuSuperior li a').get(8);
	$(link).addClass('activo');
	    $("#personaj").attr("src", "imagenes/005.png");
	    $("#personaj").css({
            width: 207,
            height: 382,
            "margin-top": 50
        });
    }

    var idInicial = $("#botones a:first").attr("id");
    if(subseccion) {
        idInicial = subseccion;
    }
    sustituyeFlash('videoInterior','flash/section/loaderMovie.swf',508,286, idInicial+".swf");
    sustituyeFlash('flashComparte','flash/TAF.swf',210,90);
    $('#'+idInicial).addClass("seleccion");
    /*
     * Botones a las otras secciones
     **/

    if($("#flashSalud").length) {
        sustituyeFlash('flashSalud','flash/button_section_salud.swf',250,103);
    }
    if($("#flashGastritis").length) {
        sustituyeFlash('flashGastritis','flash/button_section_gastritis.swf',250,103);
    }
    if($("#flashTestimonios").length) {
        sustituyeFlash('flashTestimonios','flash/button_section_testimonios.swf',250,103);
    }

    sustituyeImg('#personaje', 'personaje.png');
    sustituyeImg('#personajeInfo', 'personaje-info.png');
    sustituyeImg('#titulo img', 'title.png');


    animaCompartir();
    animaProductShot();
    animaRegistrate();

    $("#botones a").each(function(){
        var texto = $(this.firstChild).text();
        $(this).attr("href","#"+texto);
    });
    /*
     * Instala onClick
     **/
    $("#botones a").click(function() {
        var id = $(this).attr("id");        
            loadMovie(id + ".swf");
            $("#botones a").removeClass('seleccion');
            $(this).addClass("seleccion");        
        return false;
    });

    $(document).pngFix();
}

function creaBotones(datos) {
    tabla = $("#botones table");
    var tr;
    for(r in datos) {
        if(r % 2 == 0) {
            tr = $("<tr>");
            tabla.append(tr);
        }
        var id = datos[r][0];
        var texto = datos[r][1];

        var div = $("<div>").html("&nbsp;" + texto);
        var a = $("<a>").attr("href","#").attr("id",id);
        a.append(div);
        tr.append(a);
    }
}

function closeForum() {
$("#forumPanel").fadeOut("slow");
}

function forumButtonClick() {
    $("#forumPanel").fadeIn("slow");
    offset = $(this).offset();
}

