').appendTo($tabMain)
                      .attr({ id: tabID })
                      .append(chartView(this));
                // Tooltip hover event
                var $tooltip = $tabContent.find('.tooltip-info:visible').hide();
                $tabContent.find('li.main').mouseenter(function(event) {
                  $tooltip.css({ opacity: 0 });
                  $tooltip.show().animate({ opacity: 1 }, { queue: false });
                  var $item = $(this);
                  $item.siblings().each(function() {
                    $tooltip.removeClass($(this).attr('rel'));
                  });
                  $tooltip.addClass('tooltip-info ' + $item.attr('rel'));
                });
                $tabContent.find('li.main').mouseleave(function(event) {
                  $tooltip.animate({ opacity: 0 }, { queue: false });
                });
                // Main items configure event
                $tabContent.find('li.main .view-all.configure').click(function() {
                  var itemID = $(this).closest('li').attr('rel');
                  $browser.cloudBrowser('addPanel', {
                    title: itemID + ' details',
                    maximizeIfSelected: true,
                    complete: function($newPanel) {
                      $newPanel.detailView(
                        $.extend(true, {}, naas.mainNetworks[itemID].detailView, {
                          $browser: listViewArgs.$browser,
                          context: { zones: context.physicalResources }
                        })
                      );
                    }
                  });
                  return false;
                });
                // Provider configure event
                $tabContent.find('li.provider .view-all.configure').click(function() {
                  var $li = $(this).closest('li');
                  var itemID = $li.attr('rel');
                  var status = $li.attr('network-status');
                  var networkProviderArgs = naas.networkProviders.types[itemID];
                  var action = networkProviderArgs.actions ? networkProviderArgs.actions.add : null;
                  var createForm = action ? networkProviderArgs.actions.add.createForm : null;
                  var itemName = networkProviderArgs.label;
                  /**
                   * Generate provider-wide actions
                   */
                  var loadProviderActions = function($listView) {
                    $listView.find('.toolbar .main-actions').remove();
                    var $providerActions = providerActions(
                      networkProviderArgs.providerActions ?
                        networkProviderArgs.providerActions : {},
                      {
                        success: function(args) {
                          var action = args.action;
                          $loading.appendTo($listView);
                          $('div.notifications').notifications('add', {
                            desc: action.messages.notification({}),
                            interval: 2000,
                            poll: action.notification.poll,
                            _custom: args ? args._custom : null,
                            complete: function(args) {
                              $loading.remove();
                              loadProviderActions($listView);
                            }
                          });
                        },
                        actionFilter: networkProviderArgs.providerActionFilter
                      }
                    );
                    $providerActions.appendTo($listView.find('.toolbar'));
                  };
                  $browser.cloudBrowser('addPanel', {
                    title: itemName + ' details',
                    maximizeIfSelected: true,
                    complete: function($newPanel) {
                      if (status == 'not-configured') {
                        // Create form
                        var formData = cloudStack.dialog.createForm({
                          form: createForm,
                          context: { zones: listViewArgs.context.physicalResources },
                          after: function(args) {
                            action.action($.extend(args, {
                              response: {
                                success: function(args) {
                                  $newPanel.find('form').prepend($('
').addClass('loading-overlay'));
                                  $('div.notifications').notifications('add', {
                                    desc: action.messages.notification({}),
                                    interval: 1000,
                                    poll: action.notification.poll,
                                    _custom: args ? args._custom : null,
                                    complete: function(args) {
                                      refreshChart();
                                      var $listView = $newPanel.html('').listView({
                                        listView: naas.networkProviders.types[itemID]
                                      });
                                      loadProviderActions($listView);
                                    }
                                  });
                                }
                              }
                            }));
                          },
                          noDialog: true
                        });
                        var $formContainer = formData.$formContainer.addClass('add-first-network-resource');
                        var $form = $formContainer.find('form');
                        var completeAction = formData.completeAction;
                        $newPanel.append(
                          $formContainer
                            .prepend(
                              $('
').addClass('title').html('Add new ' + itemName + ' device')
                            )
                            .append(
                              $('
')
                                .addClass('button submit')
                                .append($('').html('Add'))
                                .click(function() {
                                  if ($form.valid()) {
                                    completeAction($formContainer);
                                  }
                                })
                            )
                        );
                      } else {
                        var $listView = $newPanel.listView({
                          listView: naas.networkProviders.types[itemID]
                        });
                        loadProviderActions($listView);
                      }
                    }
                  });
                });
              });
              $tabMain.tabs();
              $tabMain.find('li:first').addClass('first');
              $tabMain.find('li:last').addClass('last');
            }
          }
        });
        var refreshChart = function() {
          $charts.children().remove();
          loadNetworkData();
        };
        $refresh.click(function() {
          refreshChart();
          return false;
        });
      };
      loadNetworkData();
      return $charts;
    };
  };
})(jQuery, cloudStack);