﻿//start class Veil
var _page_veils = [];
function Veil(backgroundId, contentId, contentHeight) {
    this.Background = $get(backgroundId);
    this.Content = $get(contentId);
    this.ContentHeight = contentHeight;
    //initially make visible but w/ zero height
    this.Content.style.height = '0px';
    this.Content.style.width = (Win.Width() - 205) + 'px';
    this.Content.style.display = "block";

    this.IsVisible = function() {
        return (this.Background.style.display == "block" && this.Content.clientHeight != 0);
    };

    // Animations are initialized at the end, after the AddAnimations() function has been declared

    this.Show = function() {
        if (!this.ShowAnimation.get_isPlaying()) {
            //Trace("Veil.ShowAnimation.play() for " + this.Content.id);
            this.ShowAnimation.play();
        }
        else {
            //Trace("Veil.ShowAnimation.play() for " + this.Content.id + " IGNORED");
        }

    };
    this.Hide = function() {
        //Trace("Veil.HideAnimation.play() for " + this.Content.id);
        if (this.ShowAnimation.get_isPlaying()) this.ShowAnimation.stop();
        if (!this.HideAnimation.get_isPlaying()) {
            this.HideAnimation.play();
        }
        else {
            //Trace("Veil.HideAnimation.play() for " + this.Content.id + " IGNORED");
        }
    };
    this.InitializeAnimations = function() {
        Trace('Veil - Adding Animations...');
        this.ShowAnimation = new AjaxControlToolkit.Animation.ResizeAnimation(this.Content, .25, 25, Win.Width() - 205, this.ContentHeight, "px");
        this.ShowAnimation.Veil = this;
        this.ShowAnimation.add_started(function(src) {
            src.Veil.Background.style.display = "block";
            src.Veil.Background.style.height = (Win.Height() - 111) + 'px';
        });
        this.ShowAnimation.add_ended(function(src) {
            //Trace("Veil.ShowAnimation.onEnd() for " + src.Veil.Content.id + " has height: " + src.Veil.Content.style.height);
        });

        this.HideAnimation = new AjaxControlToolkit.Animation.ResizeAnimation(this.Content, .25, 25, Win.Width() - 205, 0, "px");
        this.HideAnimation.Veil = this;
        this.HideAnimation.add_started(function(src) {
            //Trace("Veil.HideAnimation.onStart() for " + src.Veil.Content.id);
        });
        this.HideAnimation.add_ended(function(src) {
            //Trace("Veil.HideAnimation.onEnd() for " + src.Veil.Content.id);
            src.Veil.Background.style.display = "none";
        });
    };

    this.ResizeAnimations = function() {
        Trace('Veil - Resize() ');
        this.InitializeAnimations();
    };
    // set the animation when the Veil object is created.  do this after InitializeAnimations() is declared.
    this.InitializeAnimations();
    _page_veils.push(this);
}
//end class Veil