<?php
/**
 * @subpackage  tcshortcodes plugin
 */
//no direct accees
defined ('_JEXEC') or die('resticted aceess');

//[carousel]
if(!function_exists('carousel_sc')) {
	$carouselArray = array();
	function carousel_sc( $atts, $content="" ){
		global $carouselArray;
		tcshortcodes::addJS('init.js');
		$caption = array(
			'[caption]'=>'<div class="carousel-caption">',
			'[/caption]'=>'</div>'
		);
		
		$params = shtcode_atts(array(
			  'id' => 'myCarousel'
		 ), $atts);
		
		do_shtcode( $content );
		
		$html = '<div class="carousel slide" id="' . $params['id'] . '">';
		$html .= '<div class="carousel-inner">';
		
		//carousels
		foreach ($carouselArray as $key=>$carousel) {
			$html .='<div class="'. ( ($key==0) ? "active" : "").' item">' . do_shtcode( strtr($carousel['content'], $caption) ) . '</div>';
		}
		
		$html .='</div>';//end carousel-inner
		
		$html .='<a class="carousel-control left" href="#' . $params['id'] . '" data-slide="prev">&lsaquo;</a><a class="carousel-control right" href="#' . $params['id'] . '" data-slide="next">&rsaquo;</a>';
		
		$html .='</div>';
	
		$carouselArray = array();	
		return $html;
	}
	
	add_shtcode( 'carousel', 'carousel_sc' );
		
	//carousel Items
	function carousel_item_sc( $atts, $content="" ){
		global $carouselArray;
		$carouselArray[] = array('content'=>$content);
	}

	add_shtcode( 'carousel_item', 'carousel_item_sc' );			
}