﻿// This file has been set to correct some bugs due to page layouts


// Enable WebPart move
// http://neilmosafi.blogspot.com/2007/11/sharepoint-dragging-webparts-causes.html
//
function MSOLayout_GetRealOffset(StartingObject, OffsetType, EndParent) {
    var realValue = 0;
    if (!EndParent) EndParent = document.body;
    for (var currentObject = StartingObject; currentObject && currentObject != EndParent && currentObject != document.body; currentObject = currentObject.offsetParent) {
        var offset = eval('currentObject.offset' + OffsetType);
        if (offset) realValue += offset;
    }
    return realValue + top;
}

// Correct the position of the preview while moving
// This method is extracted and corrected from the one in the original files (12\TEMPLATE\LAYOUTS\1033\ie55up.js)
//   
function MSOLayout_MoveDragObject() {
    if (MSOLayout_currentDragMode != 'move') return;
    if (MSOLayout_moveObject.style.display == 'none') MSOLayout_moveObject.style.display = '';
    if (MSOLayout_moveObject.style.width == '') {
        MSOLayout_moveObject.realWidth = MSOLayout_moveObject.offsetWidth;
        MSOLayout_moveObject.realHeight = MSOLayout_moveObject.offsetHeight;
    }
    var newWidth = MSOLayout_moveObject.realWidth;
    var newHeight = MSOLayout_moveObject.realHeight;
    var newLeft = event.clientX + document.body.scrollLeft - (newWidth / 2);
    var newTop = event.clientY + document.body.scrollTop + 1;
    if (newLeft + newWidth > document.body.scrollWidth) newWidth -= (newLeft + newWidth - document.body.scrollWidth);
    if (newTop + newHeight > document.body.scrollHeight) newHeight -= (newTop + newHeight - document.body.scrollHeight);
    if (newHeight <= 0 || newWidth <= 0) {
        MSOLayout_moveObject.style.display = 'none';
        newWidth = newHeight = 0;
    }
    else MSOLayout_moveObject.style.display = '';
    MSOLayout_moveObject.style.width = newWidth;
    MSOLayout_moveObject.style.height = newHeight;
    MSOLayout_moveObject.style.pixelLeft = newLeft;

    var guitop = (document.documentElement && document.documentElement.scrollTop) ?
  document.documentElement.scrollTop : document.body.scrollTop;

    MSOLayout_moveObject.style.pixelTop = newTop + guitop;
}

