﻿function EmbeddedFormResize(s, t) {
    if (t.height() != s.height()) {
        t.height(s.height());
    }
}

function EmbeddedFormSetup(sourceDiv, targetDiv) {

    $(document).ready(function() {

        //setup
        sourceDiv.css({ "position": "absolute", "display": "none" });

        //get the position of the placeholder element
        var pos = targetDiv.offset();

        //move the form directly over the target div
        sourceDiv.css({ "top": pos.top + "px" });
        sourceDiv.show();

        //set source width to match target
        sourceDiv.width(targetDiv.width());

        //Initial Resize
        EmbeddedFormResize(sourceDiv, targetDiv);
        
        //Add click handler for faster redraws
        sourceDiv.live('click', function() { EmbeddedFormResize(sourceDiv, targetDiv); });

        //Add interval recalculation for any changes not actioned though a click
        setInterval(function() { EmbeddedFormResize(sourceDiv, targetDiv); }, 250);

    });
}
