}
}
if ($isArticle) {
    $clustereditbar->setVariationSelector(getChannelVariations($chid), $variation);
}
if ($sitepage && !($action == $lang->get("edit_all") || $action == $lang->get("save") || $action == $lang->get("save_back") || $action == "editsingle" || $action == "delete" || $action == "addci") && $aclf->checkAccessToFunction("B_PREVIEW_PAGE")) {
    $clustereditbar->add("preview", $lang->get("sp_preview"), "BUTTON", "window.open('" . $c["devdocroot"] . $path . "?page={$spid}&v={$variation}', 'Preview','Width=800px,Height=600px,help=no,status=yes,scrollbars=yes,resizable=yes');");
}
if (isset($clustereditbar) && (!$clusterEditState || $isArticle)) {
    $clusterPanel->add($clustereditbar);
}
$clustereditbar->addAction('separator');
if ($sitepage && ($aclf->checkAccessToFunction("B_EXPIRE_LAUNCH") || $aclf->checkAccessToFunction("B_LAUNCH_TREE") || $aclf->checkAccessToFunction("B_RELAUNCH_TREE") || $aclf->checkAccessToFunction("B_EXPIRE_TREE") || $aclf->checkAccessToFunction("B_DESTROY_TREE")) && !($action == $lang->get("edit_all") || $action == $lang->get("save") || $action == $lang->get("save_back") || $action == "editsingle")) {
    if ($aclf->checkAccessToFunction("B_EXPIRE_LAUNCH")) {
        if ($spid != "") {
            if (isSPVarLiveEx($spid, $variation)) {
                $clustereditbar->addAction($lang->get("sp_expire"));
            }
            $clustereditbar->add("action", $lang->get("sp_launch"), "submit", getWaitupScreen());
            $clustereditbar->addAction($lang->get('sp_launch'));
        }
    }
    if ($sitepage && $aclf->checkAccessToFunction("DELETE_SITEPAGE")) {
        $mid = getDBCell("sitepage", "MENU_ID", "SPID = {$oid}");
        $spm = getDBCell("sitepage", "SPM_ID", "SPID={$oid}");
        $sptype = getDBCell("sitepage_master", "SPMTYPE_ID", "SPM_ID = {$spm}");
        $clustereditbar->addAction('separator');
        if ($sptype == 1) {
            if (countRows("sitemap", "MENU_ID", "PARENT_ID={$mid}") == 0) {
                if (!isSPLive($oid) && $isDeletable) {
                    $clustereditbar->addAction($lang->get("delete_page", "Delete Page"));
		function buildInstances(& $startnode, $menuId, $isLocked=0) {		
			global $variation, $sid, $lang;
			$siteadd = "site_add.gif";
			$red = "site_red.gif";
			$green = "site_green.gif";
			
			if ($isLocked != 1) {
				  $node = &$startnode->addItem(new HTML_TreeNode(array (
					'text' => $lang->get("sp_newinstance"),
					'class' => "treemenu",
					'link' => $this->action . "?sid=$sid&go=insert&mid=" . $menuId . "&action=newinstance", 
					'icon' => $siteadd,
					'expandedIcon' => $siteadd,
					isDynamic => true
				  )));				
			}
			
			
						
			$spids = createDBCArray("sitepage", "SPID", "MENU_ID = " . $menuId, "ORDER BY POSITION");	
			for ($i = 0; $i < count($spids); $i++) {			
				$href = $this->action . "?sid=$sid&mid=" . $menuId . "&action=editcontent&oid=".$spids[$i];
				$title = getMenu($spids[$i], $variation);
				if (isSPVarLiveEx($spids[$i], $variation)) {
					$icon = $green;
					$expandedicon = $green;	
				} else {
					$icon = $red;
					$expandedicon = $red;	
				}
				
				$node = &$startnode->addItem(new HTML_TreeNode(array (
					'text' => $title[0],
					'class' => "treemenu",
					'link' => $href,
					'icon' => $icon,
					'expandedIcon' => $expandedicon,
					isDynamic => true
				)));
			}
		}