Type.registerNamespace('SitrainControlToolkit');

SitrainControlToolkit.HeaderAnimation = function(element)
{
    SitrainControlToolkit.HeaderAnimation.initializeBase(this, [element]);
    
    this._onHeaderResizeHandler = null; 
}

SitrainControlToolkit.HeaderAnimation.prototype =
{
    initialize : function SitrainControlToolkit$HeaderAnimation$initialize()
    { 
        /// <summary>
        /// Initialize the behavior
        /// </summary> 
        SitrainControlToolkit.HeaderAnimation.callBaseMethod(this, 'initialize');
        
        this.layer         = null;
	    this.slide         = {}
	    this.animate       = false;
	    this.augmented     = true;

	    if  (pageType == "1" || pageType == "2" || pageType == "entry") 
	    {
//		    if (USE_FLASH_IN_HEADER && Info.os.isMac && !Info.browser.isSafariGte3) 
//		    {
//			    // deactivate animation on browsers that have problems with wmode=transparent */
//			    this.diminishable = false;
//		    } 
//		    else 
		    {
			    this.diminishable = true;
		    }
	    } else {
		    this.diminishable = false;
	    }
	    
	    this.diminishable = true;
	    
	    if(Sys.Browser.agent === Sys.Browser.InternetExplorer) this.animate = true;
        
        this.diminish      = (this.diminishable) ? this.diminish_393 : function() {};
	    this.augment       = (this.diminishable) ? this.augment_393 : function() {};	    
	    
	    this.toolbarHeight = $common.getBounds($get("toolbar-zone")).height;	        
	    
	    this._onHeaderResizeHandler = Function.createDelegate(this, this.onHeaderResized); 
        $addHandler($get("header-zone"), "resize", this._onHeaderResizeHandler);
    },
    
    dispose : function SitrainControlToolkit$HeaderAnimation$dispose()
    {
        /// <summary>
        /// Dispose the behavior
        /// </summary> 
        
       if (this._onHeaderResizeHandler)
       {
            $removeHandler($get("header-zone"), "resize", this._onHeaderResizeHandler);
            this._onHeaderResizeHandler = null;
       }        
        
       SitrainControlToolkit.HeaderAnimation.callBaseMethod(this, 'dispose');
    },
    
    augment_393: function SitrainControlToolkit$HeaderAnimation$augment_393()
    {
        if (!this.augmented) 
        {
		    if (this.animate) 
		    {
			    this._toggleAnimated(393);
		    } 
		    else 
		    {
			    this._toggle(393);
		    }
		    this.augmented = true;
	    }
    },
    
    diminish_393: function SitrainControlToolkit$HeaderAnimation$diminish_393()
    {
        if (this.augmented) 
        {
		    if (this.animate) 
		    {
			    this._toggleAnimated(144);
		    } 
		    else 
		    {
			    this._toggle(144);
		    }
		    this.augmented = false;
	    }
    },
    
    registerLayer: function SitrainControlToolkit$HeaderAnimation$registerLayer(layer)
    {
        this.layer = layer;
	    if(this.layer) 
	    {
		    this.layer.superSetOffset(this.toolbarHeight); 
	    }
    },
    
    unregisterLayer: function SitrainControlToolkit$HeaderAnimation$unregisterLayer()
    {
        this.layer = null;
    },
    
    _toggle: function SitrainControlToolkit$HeaderAnimation$_toggle(offset)   
    {
        this.diminished = !this.diminished;         
	    this._setOffsets(offset);
    },
    
    _toggleAnimated: function SitrainControlToolkit$HeaderAnimation$_toggleAnimated(offsets)
    {        
        var bounds = $common.getBounds(headerZone);
        var animation = new AjaxControlToolkit.Animation.ResizeAnimation(headerZone, 0.5, 24, bounds.width, offsets);
       	animation.play();
    },
    
    _setOffsets:  function SitrainControlToolkit$HeaderAnimation$_setOffsets(offset)
    {
        document.body.style.backgroundPosition = "0 " + (offset - 393) + "px";
	    headerZone.style.height = offset + "px";
	    if(this.layer) 
	    {
		    this.layer.superSetOffset(this.toolbarHeight + offset);
	    }
    },
    
    onHeaderResized: function SitrainControlToolkit$HeaderAnimation$onHeaderResized()
    {        
        var bounds = $common.getBounds(headerZone);        
        document.body.style.backgroundPosition = "0 " + (bounds.height - 393) + "px";
        if(this.layer) 
	    {
		    this.layer.superSetOffset(this.toolbarHeight + bounds.height);
	    }
    }
}



SitrainControlToolkit.HeaderAnimation.registerClass('SitrainControlToolkit.HeaderAnimation', Sys.UI.Behavior );
