$(document).ready(function(){

    // eliminar problemas de background de imágenes en interacciones de js en ie6
    if( ($.browser.msie==true) && ($.browser.version=="6.0") ){
        document.execCommand('BackgroundImageCache', false, true);
    };

    $('#loader-home').css({'background':'none'});
    $("#new2, #new3").hide();


    setTimeout(function() {
       // $('#loader-home-inner').css({ 'opacity': 0, 'visibility': 'visible' }).animate({ opacity: 1 }, 2000);
		// $(	'object, #contenedor-numeros-news, #columna-pildoras, #pildora-footer-home, #destacado-inferior-izq, #interior-i-inner, #destacado-inferior-der, #pilhome-principal, p.breadcrum').css({ 'opacity': 0, 'visibility': 'visible' }).animate({ opacity: 1 }, 2000);
		$(	'object, #borde-news, #numeros-news, #columna-pildoras, #pildora-footer-home, #inferior-i, h2.rir, #inferior-d, #pilhome-principal, p.breadcrum').css({ 'opacity': 0, 'visibility': 'visible' }).animate({ opacity: 1 }, 2000);
    }, 1000);

    // PIL HOME GRANDE NORMAL
    $('#a-pil-grande').mouseenter(function() {
        var url_link = $(this).attr("href");

        var color_de_borde = $(this).attr("color_borde");

        var texto_link = $(this).text();

        var elemento = '<a style="border-color: ' + color_de_borde + ' !important;" id="borde-pilhome-grande" class="borde-superpuesto" href="' + url_link + '">' + texto_link + '</a>';

        $(this).prepend(elemento);

        //$(this).prepend('<a id="borde-pilhome-grande" class="borde-superpuesto" href="/perder-peso-bimanan-pro/">texto enlace generado con JS</a>');
    });
    $('#a-pil-grande').mouseleave(function() {
        $("#borde-pilhome-grande").remove();
    });

    // PIL HOME GRANDE CON 2 IMAGENES
    $('#a-pil-b1').mouseenter(function() {

        var anchura = $(this).css("width");
        anchura = anchura.replace("px", "");
        anchura = anchura - 4;

        var altura = $(this).css("height");
        altura = altura.replace("px", "");
        altura = altura - 4;

        var posicion_top = $(this).css("margin-top");

        var posicion_left = $(this).css("margin-left");
        posicion_left = posicion_left.replace("px", "");
        // si es IE6
        if( ($.browser.msie==true) && ($.browser.version=="6.0") ){
            posicion_left = Number(posicion_left) + 10;
        };

        var url_link = $(this).attr("href");

        var color_de_borde = $(this).attr("color_borde_izq");

        var texto_link = $(this).text();

        var elemento = '<a style="width:' + anchura + 'px;height:' + altura + 'px;top: ' + posicion_top + ';left:' + posicion_left + 'px; border-color: ' + color_de_borde + ' !important;" id="borde-pilhome-grande-b1" class="borde-superpuesto" href="' + url_link + '">' + texto_link + '</a>';

        $(this).prepend(elemento);

    });

    $('#a-pil-b1').mouseleave(function() {
        $("#borde-pilhome-grande-b1").remove();
    });

    $('#a-pil-b2').mouseenter(function() {

        var anchura = $(this).css("width");
        anchura = anchura.replace("px", "");
        anchura = anchura - 4;

        var altura = $(this).css("height");
        altura = altura.replace("px", "");
        altura = altura - 4;

        var posicion_top = $(this).css("margin-top");

        var ancho_img1 = $('#a-pil-b1').css("width").replace("px", "");
        var ancho_margen = $(this).css("margin-left").replace("px", "");
        var margen_img1 = $('#a-pil-b1').css("margin-left").replace("px", "");
        var posicion_left = Number(ancho_img1) + Number(ancho_margen) + Number(margen_img1);
        // si es IE6
        if( ($.browser.msie==true) && ($.browser.version=="6.0") ){
            posicion_left = Number(posicion_left) + 10;
        };

        var url_link = $(this).attr("href");

        var color_de_borde = $(this).attr("color_borde_der");

        var texto_link = $(this).text();

        var elemento = '<a style="width:' + anchura + 'px;height:' + altura + 'px;top: ' + posicion_top + ';left:' + posicion_left + 'px; border-color: ' + color_de_borde + ' !important;" id="borde-pilhome-grande-b2" class="borde-superpuesto" href="' + url_link + '">' + texto_link + '</a>';

        $(this).prepend(elemento);

    });

    $('#a-pil-b2').mouseleave(function() {
        $("#borde-pilhome-grande-b2").remove();
    });

	// PIL HOME GRANDE CON HTML DENTRO
    $('#a-pil-html').mouseenter(function() {

        var color_de_borde = $(this).attr("color_borde");

        var borde_top = '<div class="borde-falso" style="width:678px; height: 2px; overflow: hidden; background: ' + color_de_borde + '; position: absolute; top: 0px; left: 0px;">&nbsp;</div>';
        var borde_left = '<div class="borde-falso" style="width:2px; height: 216px; overflow: hidden; background: ' + color_de_borde + '; position: absolute; top: 0px; left: 0px">&nbsp;</div>';
        var borde_right = '<div class="borde-falso" style="width:2px; height: 216px; overflow: hidden; background: ' + color_de_borde + '; position: absolute; top: 0px; right: 0px">&nbsp;</div>';
        var borde_bottom = '<div class="borde-falso" style="width:678px; height: 2px; overflow: hidden; background: ' + color_de_borde + '; position: absolute; bottom: 0px; left: 0px">&nbsp;</div>';

        $(this).prepend(borde_top);
        $(this).prepend(borde_left);
        $(this).prepend(borde_right);
        $(this).prepend(borde_bottom);

    });
    $('#a-pil-html').mouseleave(function() {
		 $('.borde-falso').remove();  
    });
	

    // PILS HOME INFERIORES
    $('.pilhome-inf').mouseenter(function() {
        var url_link = $(this).attr("href");

        var color_de_borde = $(this).attr("color_borde");

        var texto_link = $(this).text();

        var elemento = '<a style="border-color: ' + color_de_borde + ' !important;" id="borde-pilhome-inf" class="borde-superpuesto" href="' + url_link + '">' + texto_link + '</a>';

        $(this).prepend(elemento);
        //$(this).prepend('<a id="borde-pilhome-inf" class="borde-superpuesto" href="/perder-peso-bimanan-pro/">texto enlace generado con JS</a>');
    });
    $('.pilhome-inf').mouseleave(function() {
        $("#borde-pilhome-inf").remove();
    });

    //News
    $("#a-new1")
        .bind("click", function() {
            if( $("p#new1").is(':visible') == false ){
                $('a').removeClass("new-seleccionada");
                $(this).addClass("new-seleccionada");
                $("p#new2, p#new3").hide();
                $("p#new1").show();
            }
        });
    $("#a-new2")
        .bind("click", function() {
            if( $("p#new2").is(':visible') == false ){
                $('a').removeClass("new-seleccionada");
                $(this).addClass("new-seleccionada");
                $("p#new1, p#new3").hide();
                $("p#new2").show();
            }
        });
    $("#a-new3")
        .bind("click", function() {
            if( $("p#new3").is(':visible') == false ){
                $('a').removeClass("new-seleccionada");
                $(this).addClass("new-seleccionada");
                $("p#new1, p#new2").hide();
                $("p#new3").show();
            }
        });

});

