var presentationWidth;
var presentationHeight;
var benWinWidth = -1;
var benWinHeight = -1;

function resizeEvent() 
{
    var backSize = new Array(2);
    getWindowSize(top, backSize);

    if ( ( benWinWidth != -1 ) && ( benWinHeight != -1 ) &&
         ( ( backSize[0] != benWinWidth ) || ( backSize[1] != benWinHeight ) ) )
        window.location.href = window.location.href;
            
    benWinWidth = backSize[0];
    benWinHeight = backSize[1];
}

function prepareLayout(navWidth, navHeight, picWidth, picHeight, heightMargin) 
{
    // Get background size
    var backSize = new Array(2);
    getWindowSize(top, backSize);

    // Write style header        
    document.writeln('<style type="text/css">');

    // Calculate postions/sizes for presentation pane
    var presTop = 2 * heightMargin;
    var presLeft = Math.floor(0.03 * backSize[0]);
    var presWidth = Math.floor(0.45 * backSize[0]);
    var presHeight = Math.floor(backSize[1] - 3.0 * heightMargin);
    var presHdrHeight = Math.floor(backSize[1] * 0.06);
    var presContentTop = presHdrHeight;
    var presContentHeight = presHeight - 2 * presHdrHeight - 10;
    var presContentWidth = Math.floor(0.98 * presWidth);

    // Write presentation pane style
    document.writeln('#presentation ');
    document.writeln('{');
    document.writeln('        width    : ' + presWidth + 'px;');
    document.writeln('    min-width    : ' + presWidth + 'px;');
    document.writeln('    max-width    : ' + presWidth + 'px;');
    document.writeln('        height   : ' + presHeight + 'px;');
    document.writeln('    min-height   : ' + presHeight + 'px;');
    document.writeln('    max-height   : ' + presHeight + 'px;');
    document.writeln('    position     : absolute;');
    document.writeln('    left         : ' + presLeft + 'px;');
    document.writeln('    top          : ' + presTop + 'px;');
    document.writeln('}');

    document.writeln('#prescontent');
    document.writeln('{');
    document.writeln('        width    : ' + presContentWidth + 'px;');
    document.writeln('    min-width    : ' + presContentWidth + 'px;');
    document.writeln('    max-width    : ' + presContentWidth + 'px;');
    document.writeln('        height   : ' + presContentHeight + 'px;');
    document.writeln('    min-height   : ' + presContentHeight + 'px;');
    document.writeln('    max-height   : ' + presContentHeight + 'px;');
    document.writeln('    position     : absolute;');
    document.writeln('    left         : 0px;');
    document.writeln('    top          : ' + presContentTop + 'px;' );
    document.writeln('}');

    presentationWidth = presContentWidth;
    presentationHeight = presContentHeight;
    
    // Calculate postions/sizes for right container
    var rightTop = presTop;
    var rightLeft = Math.floor(0.5 * backSize[0]);
    var rightWidth = Math.floor(0.5 * backSize[0] - 15);
    var rightHeight = Math.floor(backSize[1] - 2.0 * heightMargin);

    // Write right container style
    document.writeln('#rightcontainer');
    document.writeln('{');
    document.writeln('        width    : ' + rightWidth + 'px;');
    document.writeln('    min-width    : ' + rightWidth + 'px;');
    document.writeln('    max-width    : ' + rightWidth + 'px;');
    document.writeln('        height   : ' + rightHeight + 'px;');
    document.writeln('    min-height   : ' + rightHeight + 'px;');
    document.writeln('    max-height   : ' + rightHeight + 'px;');
    document.writeln('    position     : absolute;');
    document.writeln('    left         : ' + rightLeft + 'px;');
    document.writeln('    top          : ' + rightTop + 'px;');
    document.writeln('}');

    // Calculate postions/sizes for navigation pane
    var navLeft = Math.round((rightWidth - navWidth) / 2);

    // Write navigation pane style
    document.writeln('#navigation');
    document.writeln('{');
    document.writeln('        width    : ' + navWidth + 'px;');
    document.writeln('    min-width    : ' + navWidth + 'px;');
    document.writeln('    max-width    : ' + navWidth + 'px;');
    document.writeln('        height   : ' + navHeight + 'px;');
    document.writeln('    min-height   : ' + navHeight + 'px;');
    document.writeln('    max-height   : ' + navHeight + 'px;');
    document.writeln('    position     : absolute;');
    document.writeln('    left         : ' + navLeft + 'px;');
    document.writeln('    top          : 0px;');
    document.writeln('}');
    
    // Calculate postions/sizes for artwork
    var artSize = new Array(2);
    artSize[0] = rightWidth - 20;
    artSize[1] = rightHeight - navHeight - 20;
    var picSize = new Array(2);
    picSize[0] = picWidth;
    picSize[1] = picHeight;
    scaleMediaSize(artSize, picSize);

    var picLeft = Math.round((rightWidth - picSize[0]) / 2);

    // Write artwork style
    document.writeln('#artwork');
    document.writeln('{');
    document.writeln('    position     : absolute;');
    document.writeln('    left         : ' + picLeft + 'px;');
    document.writeln('    bottom       : 0px;');
    document.writeln('    width        : ' + picSize[0] + 'px;');
    document.writeln('    height       : ' + picSize[1] + 'px;');
    document.writeln('}');

    // Write style footer
    document.writeln('</style>');

    // Window resizing
    benWinWidth = backSize[0];
    benWinHeight = backSize[1];
 
//    window.onresize = function() { resizeEvent(); }
}
