Type.registerNamespace('hexagon.web.Controls.Home');

hexagon.web.Controls.Home.CompanyInfoBehavior = function(element) 
{
    hexagon.web.Controls.Home.CompanyInfoBehavior.initializeBase(this, [element]);

	this._ParentBehaviorID = null;
    this._TargetCompanyInfoID = null;
    this._NormalImageUrl = null;
    this._HoverImageUrl = null;
    this._LinkTargetUrl = null;
    
    this._parentBehaviour = null;
	this._imageTarget = null;
	this._panelTarget = null;
    
    this._mouseOverHandler = null;
    this._mouseOutHandler = null;
    this._clickHandler = null;
}

hexagon.web.Controls.Home.CompanyInfoBehavior.prototype = 
{

    get_ParentBehaviorID : function() 
    {
        return this._ParentBehaviorID;
    },

    set_ParentBehaviorID : function(value) 
    {
        this._ParentBehaviorID = value;
    },

    get_TargetCompanyInfoID : function() 
    {
        return this._TargetCompanyInfoID;
    },

    set_TargetCompanyInfoID : function(value) 
    {
        this._TargetCompanyInfoID = value;
    },
    
    get_NormalImageUrl : function() 
    {
        return this._NormalImageUrl;
    },

    set_NormalImageUrl : function(value) 
    {
        this._NormalImageUrl = value;
    },
    
    get_HoverImageUrl : function() 
    {
        return this._HoverImageUrl;
    },

    set_HoverImageUrl : function(value) 
    {
        this._HoverImageUrl = value;
    },
    
    get_LinkTargetUrl : function() 
    {
        return this._HoverImageUrl;
    },

    set_LinkTargetUrl : function(value) 
    {
        this._LinkTargetUrl = value;
    },
    
    initialize : function() 
    {
        hexagon.web.Controls.Home.CompanyInfoBehavior.callBaseMethod(this, 'initialize');
        
		this._imageTarget = '#ci_img_' + this.get_TargetCompanyInfoID();
		this._panelTarget = '#ci_pan_' + this.get_TargetCompanyInfoID();
        
        this._clickHandler = Function.createDelegate(this, this._onClick);
        this._mouseOverHandler = Function.createDelegate(this, this._onMouseOver);
        this._mouseOutHandler = Function.createDelegate(this, this._onMouseOut);
        $addHandler($get('ci_img_' + this.get_TargetCompanyInfoID()), "click", this._clickHandler);
        $addHandler($get('ci_img_' + this.get_TargetCompanyInfoID()), "mouseover", this._mouseOverHandler);
        $addHandler($get('ci_img_' + this.get_TargetCompanyInfoID()), "mouseout", this._mouseOutHandler);
        
        this._parentBehaviour = Sys.Application.findComponent(this.get_ParentBehaviorID());
    },

    dispose : function() 
    {
        hexagon.web.Controls.Home.CompanyInfoBehavior.callBaseMethod(this, 'dispose');
    },
    
    showHoverImage : function()
    {
		if($(this._imageTarget).attr('src').indexOf('#hover') == -1) 
		{
			$(this._imageTarget).attr('src', this.get_HoverImageUrl() + '#hover');
		}
    },
    
    showNormalImage : function()
    {
		if($(this._imageTarget).attr('src').indexOf('#hover') != -1) 
		{
			$(this._imageTarget).attr('src', this.get_NormalImageUrl());
		}
    },
    
    showPanel : function()
    {
		$(this._panelTarget).show();
    },
    
    hidePanel : function()
    {
		$(this._panelTarget).hide();
    },
    
    _onClick : function(ev) 
    {
		document.location = this._LinkTargetUrl;
		ev.preventDefault();
    },
    
    _onMouseOver : function(ev) 
    {
		clearTimeout(this._parentBehaviour._deselectTimer);
		this._parentBehaviour.setCurrent(this);
		this.showHoverImage();
    },
    
    _onMouseOut : function(ev) 
    {
		this._parentBehaviour._deselectTimer = setTimeout(Function.createDelegate(this, this._deselect), 1000);
    },
    
    _deselect : function(ev)
    {
		this._parentBehaviour.setCurrent(null);
		this.showNormalImage();
	}
    
}

hexagon.web.Controls.Home.CompanyInfoBehavior.registerClass('hexagon.web.Controls.Home.CompanyInfoBehavior', AjaxControlToolkit.BehaviorBase);