/*
_HalfPayMinWidth and _HalfPayMinHeight should be initialized to an appropriate value by skins
*/
var _HalfPayMinWidth = null;
var _HalfPayMinHeight = null;

var jq = jQuery.noConflict();
jq(document).ready(
    function() { windowMinResize(); }
)

function windowMinResize() {
    //note that this isn't perfect because of scrollbars, toolbar adjustability, etc.

    //alert('vals: ' + _HalfPayMinWidth + ':' + _HalfPayMinHeight );
    if ( _HalfPayMinWidth |  _HalfPayMinHeight ) {
        //alert('resizing to min: ' + _HalfPayMinWidth + ':' + _HalfPayMinHeight );
        var currentHeight = getH();
        var currentWidth = getW();

        //alert('current size: ' + currentWidth + '-' + currentHeight);
        if (currentHeight < _HalfPayMinHeight || currentWidth < _HalfPayMinWidth) {
            //use larger of the minimum or existing values
            var desiredWidth = Math.max(_HalfPayMinWidth, currentWidth);
            var desiredHeight = Math.max(_HalfPayMinHeight, currentHeight);

            // ensure it's not bigger than the screen height/width
            desiredWidth = Math.min(screen.width, desiredWidth)
            desiredHeight = Math.min(screen.height, desiredHeight)

            //alert('computed desired size: ' + desiredWidth + '-' + desiredHeight);
            resizeDocumentTo(desiredWidth, desiredHeight);
            return;
        }
    }
}


function getW() {
    return (typeof window.innerWidth == 'undefined') ? document.body.clientWidth : window.innerWidth;
}
function getH() {
    return (typeof window.innerHeight == 'undefined') ? document.body.clientHeight : window.innerHeight;
}

function resizeDocumentTo(setw, seth) {
    return window.resizeTo(setw, seth), window.resizeTo(setw * 2 - ((typeof window.innerWidth ==
	    'undefined') ? document.body.clientWidth : window.innerWidth), seth * 2 - ((typeof window.innerHeight ==
	    'undefined') ? document.body.clientHeight : window.innerHeight));
}