public function actionEditTag(array $variables = array())
    {
        if (!empty($variables['groupHandle'])) {
            $variables['group'] = craft()->tags->getTagGroupByHandle($variables['groupHandle']);
        } elseif (!empty($variables['groupId'])) {
            $variables['group'] = craft()->tags->getTagGroupById($variables['groupId']);
        }
        if (empty($variables['group'])) {
            throw new HttpException(404);
        }
        // Now let's set up the actual tag
        if (empty($variables['tag'])) {
            if (!empty($variables['tagId'])) {
                $variables['tag'] = craft()->tags->getTagById($variables['tagId'], craft()->locale->id);
                if (!$variables['tag']) {
                    throw new HttpException(404);
                }
            } else {
                $variables['tag'] = new TagModel();
                $variables['tag']->groupId = $variables['group']->id;
            }
        }
        // Tabs
        $variables['tabs'] = array();
        foreach ($variables['group']->getFieldLayout()->getTabs() as $index => $tab) {
            // Do any of the fields on this tab have errors?
            $hasErrors = false;
            if ($variables['tag']->hasErrors()) {
                foreach ($tab->getFields() as $field) {
                    if ($variables['tag']->getErrors($field->getField()->handle)) {
                        $hasErrors = true;
                        break;
                    }
                }
            }
            $variables['tabs'][] = array(
                'label' => $tab->name,
                'url'   => '#tab'.($index + 1),
                'class' => ($hasErrors ? 'error' : null),
            );
        }
        if (!$variables['tag']->id) {
            $variables['title'] = Craft::t('Create a new tag');
        } else {
            $variables['title'] = $variables['tag']->title;
        }
        // Breadcrumbs
        $variables['crumbs'] = array(
            array('label' => Craft::t('Tag Manager'), 'url' => UrlHelper::getUrl('tagmanager')),
            array('label' => $variables['group']->name, 'url' => UrlHelper::getUrl('tagmanager')),
        );
        // Set the "Continue Editing" URL
        $variables['continueEditingUrl'] = 'tagmanager/'.$variables['group']->handle.'/{id}';
        // Render the template!
        $this->renderTemplate('tagmanager/_edit', $variables);
    }