﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("Windows");

Windows.FadingHeroBehavior = function(element) {
    Windows.FadingHeroBehavior.initializeBase(this, [element]);
    
    this.heroMouseOverDelegate = Function.createDelegate( this, this.heroMouseOver );
    this.heroMouseOutDelegate = Function.createDelegate( this, this.heroMouseOut );
    
    this.autoRotateHeroTick = Function.createDelegate( this, this._autoRotateHero);
    this.autoRotateIntervalTime = 10000;
    this.autoRotateMouseOverIntervalTime = 1000;
    this.intervalIsOnShortIntervalTime = false;
}

Windows.FadingHeroBehavior.prototype = {
    initialize: function() {
        Windows.FadingHeroBehavior.callBaseMethod(this, 'initialize');
        
        $addHandler( this.get_HeroPanel().get_element(), "mouseover", this.heroMouseOverDelegate );
        $addHandler( this.get_HeroPanel().get_element(), "mouseout", this.heroMouseOutDelegate );
        $addHandler( this.get_HeroNavContainer().get_element(), "mouseover", this.heroMouseOverDelegate );
        $addHandler( this.get_HeroNavContainer().get_element(), "mouseout", this.heroMouseOutDelegate );
        
        this.autoRotateInterval = setInterval(this.autoRotateHeroTick , this.autoRotateIntervalTime);
    },
    dispose: function() {        
        Windows.FadingHeroBehavior.callBaseMethod(this, 'dispose');
    },
    
    get_HeroPanel : function() {
        return this._heropanel;
    },
    set_HeroPanel : function(value) {
        if (this._heropanel != value) {
            this._heropanel = value;
            this.raisePropertyChanged('HeroPanel');
        }
    },
    
    get_HeroNavContainer : function() {
        return this._heronavcontainer;
    },
    set_HeroNavContainer : function(value) {
        if (this._heronavcontainer != value) {
            this._heronavcontainer = value;
            this.raisePropertyChanged('HeroNavContainer');
        }
    },
    
    heroMouseOver : function()
    {
        this.isMouseOverHero = true;
    },
    
    heroMouseOut : function()
    {
        this.isMouseOverHero = false;
    },
    
    _autoRotateHero : function()
    {
		if (!this.isMouseOverHero)
		{
			this.get_HeroPanel().DisplayNewHero("AutoDisplayNextHero");
			this.get_HeroNavContainer().MoveSelectedNavButton("AutoDisplayNextHero");
        }
    }
}
Windows.FadingHeroBehavior.registerClass('Windows.FadingHeroBehavior', Sys.UI.Behavior);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
