<?
##
## Note: if a contentslider active this will be completly ignored
##

global $Design;
$Design->RegCss['tab']['css'] = true;
require_once(DESIGNRENDERSCRIPTS.'tab.class.php');



if ($TABMODE=="3")
	{
	if (!isset($subtab))
		{
		$wb->JQUERY_ONSITE = true;	
		$wb->JQ_COOKIE = true;
		$wb->SENTRAJS_ONPAGE = true;
		$subtab = new TabClass($TABID);
		//DEBUG ($P);
		$content = $subtab->Add($TABID,$TABCAPTION,$P['TeaserParagraph']);

		$fp = fopen(PARAGRAPH_OUTPUT.$TABID.$content[1].'.php',"w+");
		fwrite($fp,$wb->SECURE_HEADER.$content[0]);
		fclose($fp);
		if (!isset($wb->griddy)) {
			$Paragraph->Content['Content'] = 'STR_MakeParagraph(SENTRA_HOME.\'assets/content/'.$TABID.'.php\');';
			$Paragraph->Content['Content'] .= 'STR_MakeParagraph(SENTRA_HOME.\'assets/content/'.$TABID.$content[1].'.php\');';
		}
		else
			$wb->griddy->Add('<?php STR_MakeParagraph(SENTRA_HOME.\'assets/content/'.$TABID.'.php\'); ?>');
		}	
	else
		{
		//$subtab->Add($TABID,$TABCAPTION,$P['TeaserParagraph']);
		$wb->CURRENT_TAB['idx']++;
		$content = $subtab->Add($TABID,$TABCAPTION,$P['TeaserParagraph'],$space);
		$fp = fopen(PARAGRAPH_OUTPUT.$TABID.$content[1].'.php',"w+");
		fwrite($fp,$wb->SECURE_HEADER.$content[0]);
		fclose($fp);
		if (!isset($wb->griddy))
			$Paragraph->Content['Content'] = 'STR_MakeParagraph(SENTRA_HOME.\'assets/content/'.$TABID.$content[1].'.php\',true,false);';
		else
			$wb->griddy->Add('<?php STR_MakeParagraph(SENTRA_HOME.\'assets/content/'.$TABID.$content[1].'.php\',true,false); ?>');
		}     
	

	}

if ($TABMODE=="2" && isset($subtab))
	{   
    $space = 0;
    if (isset($P['PreSpace']) && $P['PreSpace'] == "True")
        {    
        $space = $wb->SPACE_VALS[$P['PreSpaceVal']];
        } 
    $vspace = "";
    if ($space > 0)
        $vspace = '<div class="para" style="height:'.$space.'px"></div>';
	$content = $subtab->CloseTabs();
	$list = $subtab->GetListCode();	
  
	$fp = fopen(PARAGRAPH_OUTPUT.$subtab->commonid.'.php',"w+");
	fwrite($fp,$list);
	fclose($fp);

	$fp = fopen(PARAGRAPH_OUTPUT.$TABID.$content[1].'.php',"w+");
	fwrite($fp,'</div></div>
<div class="clearer"></div>
'.$vspace ."\n");
	fclose($fp);
	
	
	
	$script = $subtab->GetScript();
  
	$wb->QUEUE_EXTERN->AddEndScript($script);
	
	$Paragraph->Content['Content'] =  'STR_MakeParagraph(SENTRA_HOME.\'assets/content/'.$TABID.$content[1].'.php\',true,false);';

	$subtab->Dispose();    
	unset ($subtab);  
	}

#################################################################################	
## Open a Tab
#################################################################################	

if ($TABMODE=="1") {   
	$space = 0;
	if (isset($P['PreSpace']) && $P['PreSpace'] == "True")	{    
		$space = $wb->SPACE_VALS[$P['PreSpaceVal']];
	}
	$instance =  false;
	if (isset($P['nobg']) && $P['nobg'] == "True") {		
	} else {
		$instance =  $wb->Instances->TabInstance(); 
	}
	if (!$instance)	{   
	#if (!isset($wb->pageTab))	{       
		$wb->JQUERY_ONSITE = true;	
		$wb->JQ_COOKIE = true;
		$wb->SENTRAJS_ONPAGE = true;
		$tab = $wb->Instances->TabSetInstance (new TabClass($TABID));   
		if ($tab != null) {
			#$wb->pageTab = new TabClass($TABID);        
			$content = $tab->Add($TABID,VTDPARA::CaptionAdds().$TABCAPTION,$P['TeaserParagraph'],$space);
			$fp = fopen(PARAGRAPH_OUTPUT.$TABID.$content[1].'.php',"w+");
			fwrite($fp,$wb->SECURE_HEADER.$content[0]);
			fclose($fp);
			$Paragraph->Content = array();
			$Paragraph->Content['Content'] = 'STR_MakeParagraph(SENTRA_HOME.\'assets/content/'.$TABID.'.php\');';
			$Paragraph->Content['Content'] .= 'STR_MakeParagraph(SENTRA_HOME.\'assets/content/'.$TABID.$content[1].'.php\');';
			$tab->AddData($Paragraph->Content['Content']);
			$Paragraph->Content = array();  
		}
	}	else {
		$tab = $wb->Instances->TabGetInstance ();
		if ($tab != null) {
	    $wb->CURRENT_TAB['idx']++;
			$content = $tab->Add($TABID,VTDPARA::CaptionAdds().$TABCAPTION,$P['TeaserParagraph'],$space);
			$fp = fopen(PARAGRAPH_OUTPUT.$TABID.$content[1].'.php',"w+");
			fwrite($fp,$wb->SECURE_HEADER.$content[0]);
			fclose($fp);
			
			$Paragraph->Content['Content'] = 'STR_MakeParagraph(SENTRA_HOME.\'assets/content/'.$TABID.$content[1].'.php\');';	
			$tab->AddData($Paragraph->Content['Content']);
		}
		$Paragraph->Content = array();
	}     
}

if ($TABMODE=="0")	{     
	$space = 0;
	if (isset($P['PreSpace']) && $P['PreSpace'] == "True") {    
		$space = $wb->SPACE_VALS[$P['PreSpaceVal']];
	} 
	$vspace = "";
	if ($space > 0) {
		$vspace = '<div class="para" style="height:'.$space.'px"></div>';    
	}
	$tab = $wb->Instances->TabGetInstance ();
	if ($tab != null) {
		$wb->CURRENT_TAB['id'] = "";    
		$content = $tab->CloseTabs();
		#DEBUG($content);
		$list = $tab->GetListCode();	
	  #DEBUG($list);
		$fp = fopen(PARAGRAPH_OUTPUT.$tab->commonid.'.php',"w+");
		fwrite($fp,$list);
		fclose($fp);		
		$fp = fopen(PARAGRAPH_OUTPUT.$TABID.$content[1].'.php',"w+");
		fwrite($fp,'</div></div>
<div class="clearer"></div>
'.$vspace ."\n");
		fclose($fp);
		$Paragraph->Content['Content'] = 'STR_MakeParagraph(SENTRA_HOME.\'assets/content/'.$TABID.$content[1].'.php\',true,false);';	
		$tab->AddData($Paragraph->Content['Content']);
		$content = $tab->GetData();
		#DEBUG($content);
		VTDPARA::WriteContent('<?php '.$content.' ?>','t-'.$TABID);
		
		$script = $tab->GetScript();
		$wb->QUEUE_EXTERN->AddEndScript($script);

		$Paragraph->Content['Content'] =  '@include(SENTRA_HOME.\'assets/content/t-'.$TABID.'.php\');';

		$wb->Instances->TabDelInstance ();
		$wb->Instances->FillData($Paragraph->Content['Content']);	
	}
	#$wb->pageTab->Dispose();    
	unset ($wb->pageTab);   
	}
?>