﻿// © Copyright Strategy Builders Inc. 2000-2009. All rights reserved.
//   
// The entire contents of this file is protected by International and
// U.S.Copyright Laws. Unauthorized reproduction, distribution, 
// redistribution and reverse engineering of any or all portion of the code 
// contained in this file is strictly prohibited and may
// result in severe civil and criminal penalties and will be
// prosecuted to the maximum extent possible under the law.
//  
// RESTRICTIONS 
//  
// THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES  
// ARE CONFIDENTIAL AND PROPRIETARY TRADE  
// SECRETS OF Strategy Builders Inc. 
//  
// THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED
// FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE  
// COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE 
// AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  
// AND PERMISSION FROM Strategy Builders Inc. 
//  
// CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON 
// ADDITIONAL RESTRICTIONS.
//  

function getPos(el) {
    // yay readability
    for (var lx = 0, ly = 0;
        el != null;
        lx += el.offsetLeft, ly += el.offsetTop, el = el.offsetParent);
    return { x: lx, y: ly };
}

function flyAjax(flyingObject, to) {
    var locationTo = Sys.UI.DomElement.getLocation(to);
    var MoveImage1 = new AjaxControlToolkit.Animation.MoveAnimation(flyingObject, .3, 30, locationTo.x, locationTo.y, false, "px");
    MoveImage1.play();
    var MoveImage2 = new AjaxControlToolkit.Animation.MoveAnimation(flyingObject, 2, 30, 0, 1, true);
    MoveImage2.play();
}

function fly(flyingObject, to, AfterMove_Callback) {
    if (flyingObject == null) { AfterMove_Callback(); return; }
    var locationTo = Sys.UI.DomElement.getLocation(to);
    var flyingObjectCopy = flyingObject.cloneNode(true);
    flyingObjectCopy.setAttribute('id', flyingObject.id + '_Copy');
    flyingObjectCopy.style.position = 'absolute';
    document.body.appendChild(flyingObjectCopy);
    MoveAnimationPlay(flyingObjectCopy, 2, 20, locationTo.x, locationTo.y, false, "px", AfterMove_Callback);
}

function MoveAnimationPlay(movingObject, duration, fps, destinationX, destinationY, relative, unit, AfterMove_Callback) {
    var locationFrom = Sys.UI.DomElement.getLocation(movingObject);

    var xDistance = destinationX - locationFrom.x;
    var yDistance = destinationY - locationFrom.y;

    var interval = fps * duration;

    var xStep = xDistance / interval;
    var yStep = yDistance / interval;

    var intID = setInterval(function () { MoveIt(movingObject, xStep, yStep, destinationX, destinationY, intID, unit, AfterMove_Callback) }, 1);
}

function MoveIt(movingObject, xStep, yStep, destinationX, destinationY, intID, unit, AfterMove_Callback) {
    movingObject.style.left = (parseInt(movingObject.style.left) + xStep) + unit;
    movingObject.style.top = (parseInt(movingObject.style.top) + yStep) + unit;

    if (Math.abs(destinationX - parseInt(movingObject.style.left)) < Math.abs(xStep)) {
        clearInterval(intID);
        document.body.removeChild(movingObject);
        AfterMove_Callback();
    }
}


function fade(fadingObject) {
    //AjaxControlToolkit.Animation.FadeInAnimation.play(fadingObject, 2, 30, 0, 1, true);
    //AjaxControlToolkit.Animation.FadeOutAnimation.play(fadingObject, .3, 30, .1, .9, false);

    return true;
}

function relocate(flyingObject, from) {
    var location = Sys.UI.DomElement.getLocation(from);
    flyingObject.style.top = location.y + 'px';
    flyingObject.style.left = location.x + 'px';
}

