/*
 * module: dsbox_gui_help 
 * 
 */
YUI.add('dsbox_gui_help', function(Y) {

	Y.namespace('dsbox');
 
    var contextObj = {
      name: "context"
    };

	var GUIStateReady = 'ready', 
	    GUIStateLoading = 'loading';
    
    Y.dsbox.GUIHelp = function(config) {
    	this._state = GUIStateReady;
    	this._config = config;
    	this._help_id = "";
    	this._default_help_rc = null;
    	this._default_help_data = null;
    };

    Y.dsbox.GUIHelp.prototype.start = function () {
    	this.start_show_default();
    };
    
    Y.dsbox.GUIHelp.prototype.start_show_default = function () {
    	if(this._default_help_data == null) {
    		this.start_show('null', this._config.default_help_id);
    	}
    	else {
    		this._state = GUIStateLoading;
    		this.start_show_load_success(this._default_help_rc, this._default_help_data);
    	}
    };
    
    Y.dsbox.GUIHelp.prototype.start_show = function (event, help_id) {
    	if(this._state == GUIStateReady) {
    		this._help_id = help_id;
    		this.start_show_load_start();
    	}
    };

    Y.dsbox.GUIHelp.prototype.start_show_load_success = function (rc, data) {
    	if(this._state == GUIStateLoading) {
          this._state = GUIStateReady;
          Y.one("#dsbox_help").set("innerHTML", data.responseText);
          
          if(this._help_id == this._config.default_help_id) {
          	this._default_help_rc = rc;
        	this._default_help_data = data;
          }
    	}
    }
    
    Y.dsbox.GUIHelp.prototype.start_show_load_start = function() {
    	if(this._state == GUIStateReady) {
      	  this._state = GUIStateLoading;
      	  this._load_cfg = {
      			method: "GET",
    			on: {
    				success: Y.bind(this.start_show_load_success, this)
    			}
    		};
      	  this._load_request = Y.io("/welcome/ajax_help/"+this._config.lang+"/"+this._help_id, this._load_cfg);
    	}
    }
    
    Y.dsbox.GUIHelp.prototype.stop_show = function (event, help_id) {
    	this.start_show_default();
    };

    Y.dsbox.GUIHelp.prototype.add_node = function (node_id, help_id) {
    	Y.all("#"+node_id).on("mouseover", Y.bind(this.start_show, this), contextObj, help_id);
    	Y.all("#"+node_id).on("mouseout", Y.bind(this.stop_show, this), contextObj, help_id);
    }
    
}, '1.0.0', { requires: ['base', 'base-base', "anim-base", "io"] });

