﻿var _BASKShowAnimation = {	
	    "AnimationName":"Sequence",
	    "AnimationChildren":
	    [
	        {
			    "AnimationName":"FadeIn",
			    "Duration":"1",
			    "Fps":"30",
			    "MinimumOpacity":"0",
			    "MaximumOpacity":"1",
			    "AnimationChildren":[]
		    },
		    {
			    "AnimationName":"ScriptAction",
			    "Duration":"3",
			    "Script":"_BASKAnimationPause();",
			    "AnimationChildren":[]
		    },
		    {
			    "AnimationName":"FadeOut",
			    "Duration":"1",
			    "Fps":"30",
			    "MinimumOpacity":"0",
			    "MaximumOpacity":"1",
			    "AnimationChildren":[]
		    },
		    {
			    "AnimationName":"ScriptAction",
			    "Script":"_BASKAnimationEnd();",
			    "AnimationChildren":[]
		    }
        ]
    };


function _BASKAnitmationStart(sContainerClientId, elementId)
{
    var hOriginalNode = document.getElementById(elementId);
    if (!hOriginalNode) return;
    var hContainer = document.getElementById(sContainerClientId);
    if (!hContainer) return;
    var hClone = hOriginalNode.cloneNode(true);
    
    hClone.id = "PopupClone";
    //hClone.style.visibility = "hidden";
    hClone = hContainer.appendChild(hClone);
    var anim = Sys.Extended.UI.Animation.createAnimation(_BASKShowAnimation, hClone);
    anim.play();
}

function _BASKAnimationEnd()
{
    var hOriginalNode = document.getElementById("PopupClone");
    /*if (hOriginalNode != null) {
        hOriginalNode.style.display = "none";
    }*/
    if (hOriginalNode) {
        hOriginalNode.parentNode.removeChild(hOriginalNode);
    }
}   

function _BASKAnimationPause()
{

}

/********************************/
/* Listing Control Animation    */
/********************************/
var _LCActiveElement = null;

var _LCShowAnimation = {
    "AnimationName": "Sequence",
    "AnimationChildren":
	    [
	        {
	            "AnimationName": "Parallel",
	            "Duration": "0.2",
	            "AnimationChildren":
	            [
	                {
	                    "AnimationName": "Length",
	                    "Duration": "0.2",
	                    "Property": "style",
	                    "PropertyKey": "height",
	                    "StartValue": "0",
	                    "EndValue": "0",
	                    "Fps": "25",
	                    "AnimationChildren": []
	                },
		            {
		                "AnimationName": "Fade",
		                "Duration": "0.2",
		                "MinimumOpacity": "0",
		                "MaximumOpacity": "1",
		                "Fps": "25",
		                "AnimationChildren": []
		            }
		        ]
		    },
		    {
		        "AnimationName": "ScriptAction",
		        "Script": "_LCAnimationEnd();",
		        "AnimationChildren": []
		    }
        ]
};


function _LCAnimationStart(elementId) 
{
    var element = document.getElementById(elementId);
    var subElement = null;
    _LCActiveElement = element;
    
    for (var i=0; (i<element.childNodes.length && element.childNodes[i].nodeName.toLowerCase()!="ul"); i++);
    subElement = (i < element.childNodes.length) ? element.childNodes[i] : element;
    
    //var subElement = element.childNodes[0];
    //alert(element.offsetHeight + " / " + subElement.offsetHeight);

    var nHeight = GetElementRealHeight(subElement);
    if (element.offsetHeight > 0) {
        // Replie le div
        _LCShowAnimation.AnimationChildren[0].AnimationChildren[0].StartValue = nHeight + '';
        _LCShowAnimation.AnimationChildren[0].AnimationChildren[0].EndValue = 0 + '';
        _LCShowAnimation.AnimationChildren[0].AnimationChildren[1].MinimumOpacity = 1 + '';
        _LCShowAnimation.AnimationChildren[0].AnimationChildren[1].MaximumOpacity = 0 + '';
    }
    else {
        // déplie le div
        _LCShowAnimation.AnimationChildren[0].AnimationChildren[0].StartValue = 0 + '';
        _LCShowAnimation.AnimationChildren[0].AnimationChildren[0].EndValue = nHeight + '';
        _LCShowAnimation.AnimationChildren[0].AnimationChildren[1].MinimumOpacity = 0 + '';
        _LCShowAnimation.AnimationChildren[0].AnimationChildren[1].MaximumOpacity = 1 + '';
    }

    var anim = Sys.Extended.UI.Animation.createAnimation(_LCShowAnimation, element);
    anim.play();
}

function _LCAnimationEnd() {
    if (_LCActiveElement && _LCActiveElement.offsetHeight != 0) {
        _LCActiveElement.style.height = 'auto';
        _LCActiveElement.className = 'expanded';
    }
    else {
        _LCActiveElement.className = _LCActiveElement.className.replace('expanded',"");
    }
}   

function GetElementRealHeight(element) {

    if (!element) return 0;
    if (element.offsetHeight > 0) return element.offsetHeight;
    if (element.realHeight && element.realHeight > 0) return element.realHeight;

    var hClone = element.cloneNode(true);
    hClone.id = "";
    hClone.style.position = "absolute";
    hClone.style.height = "auto";
    hClone.style.visibility = "hidden";
    
    hClone = element.parentNode.parentNode.appendChild(hClone);
    var nHeight = hClone.offsetHeight;
    element.realHeight = nHeight;
    element.parentNode.parentNode.removeChild(hClone);
    return nHeight;
}

// ! IMPORTANT !
if (typeof (Sys) != "undefined" && typeof (Sys.Application) != "undefined") {
    Sys.Application.notifyScriptLoaded();
}
