<?php
/**
 * @subpackage  tcshortcodes plugin
 */
//no direct accees
defined ('_JEXEC') or die('resticted aceess');
	
//[Tab]
if(!function_exists('tab_sc')) {
	$tabArray = array();
	function tab_sc( $atts, $content="" ){
		global $tabArray;
		
		$params = shtcode_atts(array(
			  'button' => 'nav-tabs',
			  'id' => 'tab',
			  'class'=>''
		 ), $atts);
		
		do_shtcode( $content );
		
		$html = '<div class="tab">';
		
		$html .= '<div class="' . $params['class'] . '">';
		
		//Tab Title
		$html .='<ul class="nav ' . $params['button'] . '" id="' . $params['id'] . '">';
		foreach ($tabArray as $key=>$tab) {
			$html .='<li class="'. ( ($key==0) ? "active" : "").'"><a href="#'. tcshortcodes::slug( $params['id'] ) . '-' . tcshortcodes::slug($tab['title']).'" data-toggle="tab">'. $tab['title'] .'</a></li>';
		}
		$html .='</ul>';
		
		//Tab Content
		$html .='<div class="tab-content">';
		foreach ($tabArray as $key=>$tab) {
			$html .='<div class="tab-pane fade'. ( ($key==0) ? " active in" : "").'" id="'. tcshortcodes::slug( $params['id'] ) . '-' . tcshortcodes::slug($tab['title']).'">' . do_shtcode($tab['content']) .'</div>';
		}
		$html .='</div>';
		
		$html .='</div>';
		
		$html .='</div>';
		
		$tabArray = array();
		
		return $html;
	}
	add_shtcode( 'tab', 'tab_sc' );
	
	//Tab Items
	function tab_item_sc( $atts, $content="" ){
		global $tabArray;
		$tabArray[] = array('title'=>$atts['title'], 'content'=>$content);
	}

	add_shtcode( 'tab_item', 'tab_item_sc' );	
}