function resize(el,dw,dh){

    var minW = 200;
    var minH = 200;
    
    if (arguments.length == 0) {
        $('embed').each(function(){resize(this);});
    }
    if (arguments.length < 2) {
        dw = 0;
    }
    if (arguments.length < 3) {
        dh = 0;
    }
    
    var divW = $(el).width();   
    var divH = $(el).height();
    var AR = divW/divH; 

//    var docW = $(window).width()-dw;
    //var docH = $(el).parent().parent().height();
    var docH = $(window).height()-dh;
    var docW = $(el).parent().parent().width();
    var docAR = docW/docH;

    if ((docAR > AR) || (divH > docH) ) {
        var elH = docH;
        var elW = docH*AR;
    } else {
        var elW = docW;
        var elH = docW / AR;
    }
    
    elW = 0.97*elW; // To deal with scroll bars.  jquery does not have
    elH = 0.97*elH; // innerWidth for $(window).
    $(el).width(elW);
    $(el).height(elH);

}

$(function(){
    
    $(".showhide").toggle(
     function(){
        $(this).html('Hide');
        $(this).siblings("div").show();
        resize($(this).siblings("div").children('embed'),0,0);
        $( $(this).parent() )[0].scrollIntoView(true);
    }, 
    function(){
        $(this).siblings("div").hide();
        $(this).html('Show');
    });

    $(window).resize(function(){resize();});
    
});

