/// <reference name="MicrosoftAjax.js"/>
Type.registerNamespace('WindowsSite.Ajax.Controls');

WindowsSite.Ajax.Controls.ImageCommandControlBehavior = function( element ) 
{
    WindowsSite.Ajax.Controls.ImageCommandControlBehavior.initializeBase( this, [element] );
    this.mouseOverDelegate = Function.createDelegate( this, this.onMouseOver );
    this.mouseOutDelegate = Function.createDelegate( this, this.onMouseOut );
}

WindowsSite.Ajax.Controls.ImageCommandControlBehavior.prototype = 
{    
    initialize : function() 
    {
        WindowsSite.Ajax.Controls.ImageCommandControlBehavior.callBaseMethod(this, 'initialize');
        if ( this.get_HoverImageUrl() != null && this.get_HoverImageUrl() != "" )
        {
			$addHandler( this.get_element(), 'mouseover', this.mouseOverDelegate );
			$addHandler( this.get_element(), 'mouseout', this.mouseOutDelegate );
        }
    },

    dispose : function() 
    {
    
        WindowsSite.Ajax.Controls.ImageCommandControlBehavior.callBaseMethod( this, 'dispose' );
    },
    
    //******************************************
    //	Parameters
    //******************************************    
    get_Image : function() {
        return this._image;
    },
    set_Image : function(value) {
        if (this._image != value) {
            this._image = value;
            this.raisePropertyChanged('Image');
        }
    },
    
    get_ImageUrl : function() {
        return this._imageUrl;
    },
    set_ImageUrl : function(value) {
        if (this._imageUrl != value) {
            this._imageUrl = value;
            this.raisePropertyChanged('ImageUrl');
        }
    },
    
    get_HoverImageUrl : function() {
        return this._hoverImageUrl;
    },
    set_HoverImageUrl : function(value) {
        if (this._hoverImageUrl != value) {
            this._hoverImageUrl = value;
            this.raisePropertyChanged('HoverImageUrl');
        }
    },
    
    get_SelectedImageUrl : function() {
        return this._selectedImageUrl;
    },
    set_SelectedImageUrl : function(value) {
        if (this._selectedImageUrl != value) {
            this._selectedImageUrl = value;
            this.raisePropertyChanged('SelectedImageUrl');
        }
    },
    
    get_IsHovered : function() {
        return this._isHovered;
    },
    set_IsHovered : function(value) {
        if (this._isHovered != value) {
            this._isHovered = value;
            this._refresh();
            this.raisePropertyChanged('IsHovered');
        }
    },
    
    //******************************************
    //	Handlers
    //******************************************
    onMouseOver : function ( args )
    {
		if ( this._isValidEvent( args ) )
		{
			this.set_IsHovered( true );
		}
    },
    
    onMouseOut : function ( args )
    {
		if ( this._isValidEvent( args ) )
		{
			this.set_IsHovered( false );
		}
    },
    
    _onControlCommand : function( sender, args )
    {
        if (args != null)
        {
            this._commandName = args.get_CommandName();
            this._commandArgument = args.get_CommandArgument();
        }
        switch ( this._commandName )
        {
            default:
                WindowsSite.Ajax.Controls.ImageCommandControlBehavior.callBaseMethod( this, '_onControlCommand' );
                break;
        }
    },
    
    //******************************************
    //	Other functions
    //******************************************
    _refresh : function()
    {
		var imageUrl;
        if ( this.get_IsSelected() )
			imageUrl = this.get_SelectedImageUrl();
		else if ( this.get_IsHovered() )
			imageUrl = this.get_HoverImageUrl();
		else
			imageUrl = this.get_ImageUrl();
		this.get_Image().src = imageUrl;
		
		WindowsSite.Ajax.Controls.ImageCommandControlBehavior.callBaseMethod( this, '_refresh' );
    }
}

WindowsSite.Ajax.Controls.ImageCommandControlBehavior.registerClass('WindowsSite.Ajax.Controls.ImageCommandControlBehavior', WindowsSite.Ajax.Controls.CommandControlBehavior );
