
//-------------------------------------------------------------------------
//
// Application specific API for dynamic positioning of page elements
//
//-------------------------------------------------------------------------

// constants

     /**
       *
       * The url used to get the base template.  The callback will install
       * the initial page after the template was loaded.
       *
       */

     var templateURL = "php/getxsl.php";

     /**
       *
       * The url used to "restore" pages after the window was resized; the
       * template won't be affected, but the page will be updated.
       *
       */

     var restoreURL = "php/restorepage.php";

// variables

    // Saved window dimensions, used to trigger contents resizing

    var theSavedWidth, theSavedHeight;

    // Timeout for replacing scaled image(s)

    var theTimeoutID;

// updaters

    // Schedules the loading of a scaled image after the initial image
    // was loaded.

    function doInitialLayout ()
    {
//##        // Save the image box dimensions
//##        theSavedWidth = getImageBoxWidth ();
//##        theSavedHeight = getImageBoxHeight ();

        // Save the window dimensions
        theSavedWidth = getAvailableWidth ();
        theSavedHeight = getAvailableHeight ();

        // Set a new timeout for calling the image scaler; note that the
        // method to be called is generated at the server side!
        theTimeoutID = window.setTimeout ("$.post (templateURL, { 'width' : " + theSavedWidth + ", 'height' : " + theSavedHeight + " }, processPageTemplate, 'xml');", 50);

        return true;
    }

    // Schedules the loading of a scaled image if the given dimensions are
    // different from the old dimenstions.  Any previous loads that were
    // scheduled for the same image are cancelled though, so the image
    // is only reloaded when the image size has become stable again.

    function doResizedLayout ()
    {
//##        // Check if the image box has changed.  Note that this test is too
//##        // crude: it may case the reloading of an image even if there is
//##        // no need to do so because it still fits inside the new box.  This
//##        // will usually happen if just the width is changed.
//##        if ((getImageBoxHeight () != theSavedHeight) || (getImageBoxWidth () != theSavedWidth)) {

//##            // Save the image box dimensions
//##            theSavedWidth = getImageBoxWidth ();
//##            theSavedHeight = getImageBoxHeight ();

        // Check if the window size has changed.  Note that this test is too
        // crude: it may case the reloading of an page even if there is no
        // need to do so because it still fits inside the new window.  This
        // will usually happen if just the width is changed.
        if ((getAvailableHeight () != theSavedHeight) || (getAvailableWidth () != theSavedWidth)) {

            // Save the window dimensions
            theSavedWidth = getAvailableWidth ();
            theSavedHeight = getAvailableHeight ();

            // Clear the existing timeout, if any; we're still resizing
            if (theTimeoutID != null) {

                window.clearTimeout (theTimeoutID);
            }

            // Set a new timeout for calling the image scaler; note that the
            // method to be called is generated at the server side!
            theTimeoutID = window.setTimeout ("$.post (restoreURL, { 'width' : " + theSavedWidth + ", 'height' : " + theSavedHeight + " }, updatePage, 'xml');", 400);
            //@@theTimeoutID = window.setTimeout ("getXML (restoreURL, [ 'width=" + theSavedWidth + "', 'height=" + theSavedHeight + "' ], updatePage, true);", 400);
        }

        return true;
    }


