function adv(element) {    

    var cont = $('#adv');
    var contBoxImg = $('.advImg');
    var contImg = $('#'+element);
    var chiudi = $('.btChiudi');
    //var img1 = $('.img1');
    var t1 = 5000;
    var t2 = 500;
    var t3 = 200;
	var top = $(window).scrollTop() + ($(window).height() / 10);
	
    cont.css({
        'opacity': 0,
        'display': 'block'
        //'z-index': 301
    }).animate({'opacity': 0.75}, t2, openImage)

    contBoxImg.css({
		'top': parseInt(top)
    })

    cont.click(function() {
        chiudi.click();
    });
    
    chiudi.css({'cursor': 'pointer'}).click(function() {
        cont.fadeOut(t3, function(){ 
                cont.css({
                    'display': 'none' 
                }); 
        });
        contImg.fadeOut(t3, function(){ 
                contImg.css({
                    'display': 'none' 
                }); 
        });
        
        //clearTimeout(upd);
    });
    
    function openImage() {  
        contImg.css({
            'opacity': 0,
            'display': 'block'
            //'z-index': 401
        }).animate({'opacity': 1}, t2)
        //upd = setTimeout(function(){nascondiImg()}, t1) 
    }
}


function resizeFrame() {
    var myDiv = $('.pagTxtCont');
    var cont = $('#adv')
    var h = $(window).height();
	var hDoc = $(document).height();
    var w = $(window).width();
    if(h <= 1500) h = hDoc;
    if(w <= 970) {
        w = 970;
        //$('body').css({'margin-left':'500px'});
    }
    cont.css({
        'width': w,
        'height': h
        //'top': (-1)*myDiv.offset().top,
        //'left': (-1)*myDiv.offset().left
    })
}

jQuery.event.add(window, "load", resizeFrame);
jQuery.event.add(window, "resize", resizeFrame);
//jQuery(document).ready(adv)
jQuery(document).ready(function() {
    jQuery("#bt-brochure").click(function() {
        adv('popLibro')
    });
});


