﻿// Utility-methods for this page
Type.registerNamespace("manathanWeb");

manathanWeb.MoritzEiche.Utils = function() {
}

manathanWeb.MoritzEiche.Utils.prototype = {
    SetOpacity: function(element, value) {
	    element.style.opacity = value /10;
	    element.style.filter = 'alpha(opacity=' + value *10 + ')';
    }
}

manathanWeb.MoritzEiche.Utils.registerClass('manathanWeb.MoritzEiche.Utils');

manathanWeb.MoritzEiche.FadeElement = function(elementId, fadeInCaller, fadeOutCaller, wait) {
    this.opacity = 0;
    this.element = document.getElementById(elementId);
    this.fadeInCaller = fadeInCaller;
    this.fadeOutCaller = fadeOutCaller;
    this.relative = true;
    this.blockDisplay = true;
    this.wait = wait;
    this.waiter = null;
}

manathanWeb.MoritzEiche.FadeElement.prototype = {
    Open: function() {
        try {
            motz.SetFocus();
            this.InitFadeIn();
            return false;
	    } catch (err) {
	        alert('manathanWeb.MoritzEiche.FadeElement.Open() error: ' + err.message);
	    }
    },
    
    waitForClose: function() {
        if (motz) {
            // make sure last is closed 
            motz.Close();
            if (!motz.IsClosed() && this.wait) {
                this.waiter = window.setTimeout(this.wait, 50);
                return;
            }
        }
        this.__contFadeIn();
    },

    __contFadeIn: function() {
        try {
            clearTimeout(this.waiter);
            if (motz) {
                // register me as open
                motz.RegisterOpen(this);
            }
            if (this.blockDisplay)
                this.element.style.display = 'block';
            if (motz.IsIE() && this.relative) {
                this.element.style.position = 'relative';
	            this.element.style.top = '-' + 454 + 'px';
	            motz.AlignPage(2);
            }
            this.FadeIn();
        } catch (err) {
	        alert('manathanWeb.MoritzEiche.FadeElement.__contFadeIn() error: ' + err.message);
	    }
	    
    },

    InitFadeIn: function() {
        try {
            // Check if ain't already open
            if (this.opacity != 0)
                return;
            this.waitForClose();
	    } catch (err) {
	        alert('manathanWeb.MoritzEiche.FadeElement.InitFadeIn() error: ' + err.message);
	    }
    },
    
    FadeIn: function() {
        try {
	        this.opacity += 1;
	        utility.SetOpacity(this.element, this.opacity);
	        if (this.opacity < 10)
		        window.setTimeout(this.fadeInCaller, 50);
		    else
		        this.FadeInComplete();
	    } catch (err) {
	        alert('manathanWeb.MoritzEiche.FadeElement.FadeIn() error: ' + err.message);
	    }
    },
    
    FadeInComplete: function() {
    },
    
    InitFadeOut: function() {
        try {
            if (this.opacity != 10)
                return;
            this.FadeOut();
	    } catch (err) {
	        alert('manathanWeb.MoritzEiche.FadeElement.InitFadeOut() error: ' + err.message);
	    }
    },
    
    FadeOut: function() { 
        try {
	        this.opacity -= 1;
	        utility.SetOpacity(this.element, this.opacity);
	        if (this.opacity > 0)
		        window.setTimeout(this.fadeOutCaller, 50);
	        else 
	            this.FadeOutComplete();
	    } catch (err) {
	        alert('manathanWeb.MoritzEiche.FadeElement.FadeOut() error: ' + err.message);
	    }
    },
    
    FadeOutComplete: function() {
        try {
            if (this.blockDisplay)
	            this.element.style.display = 'none';
	        else
	            this.element.style.visibility = 'hidden';
	        if (motz.IsIE() && this.relative) {
                this.element.style.position = 'relative';
	            this.element.style.top = '0px';
	            motz.AlignPage(2);
	            document.getElementById('footer').style.top = '-87px';
            }
	    } catch (err) {
	        alert('manathanWeb.MoritzEiche.FadeElement.FadeOutComplete() error: ' + err.message);
	    }
    },
    
    getIsVisible: function() {
        return this.opacity == 10;
    },
    
    getIsClosed: function() {
        return this.opacity == 0;
    },
    
    getElement: function() {
        return this.element;
    },
    
    Close: function() {
        try {
            motz.SetFocus();
            this.InitFadeOut();
	    } catch (err) {
	        alert('manathanWeb.MoritzEiche.FadeElement.Close() error: ' + err.message);
	    }
    }
}
manathanWeb.MoritzEiche.FadeElement.registerClass('manathanWeb.MoritzEiche.FadeElement');

var utility = new manathanWeb.MoritzEiche.Utils();

function waitForClose() {
    utility.waitForClose();
}

// Notify ScriptManager that this is the end of the script.
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

