<?php

function tabs($atts, $content) {
	extract(shortcode_atts(array(
		'style' => ''
		), $atts));
		$style ='tabsNav' . $style;

if (!preg_match_all("/(.?)\[(tab)\b(.*?)(?:(\/))?\](?:(.+?)\[\/tab\])?(.?)/s", $content, $matches)) {
		return do_shortcode($content);
	} else {
		for($i = 0; $i < count($matches[0]); $i++) {
			$matches[3][$i] = shortcode_parse_atts($matches[3][$i]);
		}
		
		
		if($style=='tabsNav') {
			$output = '<div class="tabsShortcode tabsstyle1"><ul class="'.$style.'">';
		
		for($i = 0; $i < count($matches[0]); $i++) {
			$output .= '<li><a href="#' . strtolower(str_replace(" ","",$matches[3][$i]['title'])) . '">' . $matches[3][$i]['title'] . '</a></li>';
		}
		$output .= '</ul>';
			
		}else {
		$output = '<ul class="'.$style.'">';
		
		for($i = 0; $i < count($matches[0]); $i++) {
			$output .= '<li><a href="#' . strtolower(str_replace(" ","",$matches[3][$i]['title'])) . '">' . $matches[3][$i]['title'] . '</a></li>';
		}
		$output .= '</ul>';
		}
		$output .= '<div class="tabsContainer">';
		for($i = 0; $i < count($matches[0]); $i++) {
			$output .= '<div class="panel tabContent" id="' . strtolower(str_replace(" ","",$matches[3][$i]['title'])) . '">' . do_shortcode(trim($matches[5][$i])) . '</div>';
		}
		$output .= '</div></div>';
		
		return '<div class="'.$style.'_container">' . $output . '</div>';
	}			
}

add_shortcode('tabs', 'tabs');


function accordion($atts, $content) {
	extract(shortcode_atts(array(
		), $atts));

	if (!preg_match_all("/(.?)\[(accordion)\b(.*?)(?:(\/))?\](?:(.+?)\[\/accordion\])?(.?)/s", $content, $matches)) {
		return do_shortcode($content);
	} else {
		for($i = 0; $i < count($matches[0]); $i++) {
			$matches[3][$i] = shortcode_parse_atts($matches[3][$i]);
		}
		$output = '';
		for($i = 0; $i < count($matches[0]); $i++) {
			$output .= '<span class="acc-trigger"><a href="#">' . $matches[3][$i]['title'] . '</a></span>';
			$output .= '<div class="acc-container">' . do_shortcode(trim($matches[5][$i])) . '</div>';
		}

		return '<div class="accrodation">' . $output . '</div>';
	}		
}

add_shortcode('accordions', 'accordion');

?>