<?
class TabClass {
	#var $TABsrcpath;
	var $TAB_CONTROL = array();
	var $idx = 0;
	#var $style = "";
	var $default = "current";
	var $firsttab = true;
	var $commonid = "";
    var $script = "";
	var $listItem = '';
	var $listNav = '';
	var $TabData= array();
	// var $defaultpath = "../";
	// var $pluginpath = "../../../";

	function __construct ($id,$style="")
		{
		global $Design,$wb;
		$Design->RegCss['tab']['css'] = true;		
		// if ($style == "")
			// $this->style=$wb->TAB_STYLE;
		// else
			// $this->style=$style;

			// $this->defaultpath = $wb->PROJECT['templatefull'].DIRECTORY_SEPARATOR;
			// $this -> TABsrcpath = $this->defaultpath."modules".DIRECTORY_SEPARATOR."tabs".DIRECTORY_SEPARATOR.$this->style.DIRECTORY_SEPARATOR;
			// $this->TABscommonpath = $this->defaultpath."modules".DIRECTORY_SEPARATOR."tabs".DIRECTORY_SEPARATOR."_common".DIRECTORY_SEPARATOR;
		
		$this->listItem = file_get_contents(DESIGNRENDERSCRIPTS."tab.item.tpl");
		$this->listNav = file_get_contents(DESIGNRENDERSCRIPTS."tab.nav.tpl");
		$this->script = file_get_contents(DESIGNRENDERSCRIPTS."tab.script.js");
		$this->script = str_replace('{{ID}}',$id,$this->script);
		$this->commonid=$id;
        $wb->JQUERY_ONSITE = true;
        $wb->JQ_COOKIE = true;
		#$wb -> TAB_styles_required = TRUE;/* Notice for tpl_post.php to register TAB styles */
		}


	function AddHTML ($html)
		{
		$tmp = array();
		$tmp['code']=$html;
		$tmp['tabmode'] = false;
		array_push ($this->TAB_CONTROL,$tmp);
		}
	function AddData ($data) {
		array_push($this->TabData, $data);
	}
	function GetData () {
		return implode("\n",$this->TabData);
	}
	function Add ($id,$caption,$class="dummy",$space = "")
		{
        global $wb;
		$tmp = array();
		$tmp['id']=$id;
		$tmp['caption'] = $caption;
		$tmp['tabmode'] = true;
        if ($space == "") $space=5;
        // if ($this->style =="")
        // {
        // $this->style ="Bricks ";
        // }
		$listitem = $this->listItem;
		$listitem = str_replace("{{LINKCLASS}}",$class,$listitem);
		$listitem = str_replace("{{CAPTION}}",$caption,$listitem);
		#$listitem = str_replace("{{DEFAULT}}",$this->default,$listitem);
		$listitem = str_replace("{{IDX}}",$this->idx,$listitem);
		$listitem = str_replace("{{ID}}",$this->commonid.'-'.$this->idx,$listitem);
		
		// $cc = "s".GetHashCode("width".$wb->TEMPLATE_WIDTHES['Width']);
        // RegCssClass($cc,"width:".$wb->TEMPLATE_WIDTHES['Width']."px");
		if ($this->firsttab)
			{
			$this->firsttab = false;
			// $content = file_get_contents($this->TABscommonpath."tabs_common.tpl");
			// $content .= file_get_contents($this -> TABsrcpath."script_template.tpl");
            // $content= str_replace("{{width}}",$wb->TEMPLATE_WIDTHES['Width'],$content);

            $vspace = "";
            if ($space > 0)
                $vspace = VTDPARA::GapGen($space);;
            // DEBUG($content.$space);
			$content = '
		
			<div id="'.$this->commonid.'-'.$this->idx.'">'.$vspace .'
			';
			// $content = str_replace("{{ID}}",$this->commonid,$content);
            // $content = str_replace("{{WIDTH}}",$wb->TEMPLATE_WIDTHES['Width'],$content);
			$tmp['code']= $content;
			$tmp['id']=$this->commonid;
			// $listitem = str_replace("{{CURRENT_ID}}",$this->commonid,$listitem);
			}
		else
			{
			$listitem = str_replace("{{CURRENT_ID}}",$id,$listitem);
            $vspace = "";
            if ($space > 0)
                $vspace = '<div class="para" style="height:'.$space.'px"></div>';
			$content = '
			</div><div class="clearfix"></div>
			<div id="'.$this->commonid.'-'.$this->idx.'" >'.$vspace.'
			';
			$tmp['code']=$content;
			$tmp['id']=$id;
			}
		$tmp['list']= $listitem;
		array_push ($this->TAB_CONTROL,$tmp);
		$this->idx++;
		return array($content,($this->idx-1));
		}

	function CloseTabs() {
		global $wb;
		$tmp = array();
		$tmp['tabmode']=false;
		$tmp['code']=PHP_EOL.'	</div>	</div>'.PHP_EOL;
		$wb -> TAB_styles_required = TRUE;/* Notice for tpl_post.php to register TAB styles */
		array_push ($this->TAB_CONTROL,$tmp);
		return array($tmp['code'],($this->idx));
	}

	function Dispose()
		{
		$this->TAB_CONTROL=array();
		}

	function GetAll()
		{
		$content = "";
		if (count($this->TAB_CONTROL) > 0)
			{
			for ($x=0;$x < count($this->TAB_CONTROL);$x++)
				{
				if ($x == 0)
					$content .= $this->GetListCode();
				else
					{
					$content .= $this->TAB_CONTROL[$x]['code'];
					}
				}
			}
		return ($content);
		}

	function GetListCode()
		{
        global $wb,$P;
		
		$content = $this->listNav;
		
			if (count($this->TAB_CONTROL) > 0)
			{
			$list = ""; $main_tab = ""; $list_id = array(); $cont_id = array();
			for ($x=0;$x < count($this->TAB_CONTROL);$x++)
				{
				if ($this->TAB_CONTROL[$x]['tabmode'])
					{
					if ($x == 0)
						{
						#$content = $this->TAB_CONTROL[0]['code'];
						$list .= $this->TAB_CONTROL[0]['list'];
						}
					else
						{
						if ($this->TAB_CONTROL[$x]['tabmode'])
							$list .= $this->TAB_CONTROL[$x]['list'];
						}
					array_push($list_id,'"str_'.$this->TAB_CONTROL[$x]['id'].'"');
					array_push($cont_id,'"tab_'.$this->TAB_CONTROL[$x]['id'].'"');
					}
				}
			$content = str_replace("{{ID}}",$this->commonid,$content);
			$content = str_replace("{{ITEMS}}",$list,$content);
			
			}
		return ($content);
		}
function GetScript ()
		{
		return ($this->script);
		}

	function GetTabArray ()
		{
		return ($this->TAB_CONTROL);
		}

	function GetLastContent ()
		{
		return ($this->TAB_CONTROL[count($this->TAB_CONTROL)-1]['code']);
		}
}
?>