<?php
function theme_shortcode_tips($atts,$content = null) {
	extract(shortcode_atts(array(
		'tipscontent'=>'',
		'delay' => 400,
		'position'=>'top-center',
		'width' => 200,
		'effect'=>'fade',
	    'bordercolor' => '',
	    'bgcolor' => '',
	    'textcolor' =>'',
	), $atts));
	$top_color='';
	$bot_color='';
	if (!preg_match_all("/(.*)\[(tip_content)\b\s*\](?:(.+?)\[\/tip_content\])?(.*)/s", $content, $matches)) {
		return do_shortcode($content);
	}else{
		switch ($position) {
		case 'top-center':
			$top_color = !empty($bgcolor) ? 'border-color:'.$bgcolor.' transparent transparent':'';
			$bot_color = !empty($bordercolor) ?'border-color:'.change_rgba($bordercolor,0.8).' transparent transparent':'';
			break;
		case 'top-left':
			$top_color = !empty($bgcolor) ? 'border-color:'.$bgcolor.' transparent transparent':'';
			$bot_color = !empty($bordercolor) ?'border-color:'.change_rgba($bordercolor,0.8).' transparent transparent':'';
			break;
		case 'top-right':
			$top_color = !empty($bgcolor) ? 'border-color:transparent '.$bgcolor:'';
			$bot_color = !empty($bordercolor) ?'border-color:transparent '.change_rgba($bordercolor,0.8):'';
			break;
		case 'center-right':
			$top_color = !empty($bgcolor) ? 'border-color:transparent '.$bgcolor.' transparent transparent':'';
			$bot_color = !empty($bordercolor) ?'border-color:transparent '.change_rgba($bordercolor,0.8).' transparent transparent':'';
			break;
		case 'center-left':
			$top_color = !empty($bgcolor) ? 'border-color:transparent transparent transparent '.$bgcolor:'';
			$bot_color = !empty($bordercolor) ?'border-color:transparent transparent transparent '.change_rgba($bordercolor,0.8):'';
			break;
		case 'bottom-center':
			$top_color = !empty($bgcolor) ? 'border-color:'.$bgcolor.' transparent':'';
			$bot_color = !empty($bordercolor) ?'border-color:'.change_rgba($bordercolor,0.8).' transparent':'';
			break;
		case 'bottom-left':
			$top_color = !empty($bgcolor) ? 'border-color:transparent '.$bgcolor:'';
			$bot_color = !empty($bordercolor) ?'border-color:transparent '.change_rgba($bordercolor,0.8):'';
			break;
		case 'bottom-right':
			$top_color = !empty($bgcolor) ? 'border-color:transparent '.$bgcolor:'';
			$bot_color = !empty($bordercolor) ?'border-color:transparent '.change_rgba($bordercolor,0.8):'';
			break;
		}
		$bgcolor = !empty($bgcolor) ? 'background-color:'.$bgcolor.';' : '';
		$bordercolor = !empty($bordercolor) ? 'border-color:'.$bordercolor.';' : '';
		$textcolor = !empty($textcolor) ? 'color:'.$textcolor.';' : '';
		$width = !empty($width) ? 'width:'.$width.'px;' : '';
		return  '<span data-position="'.str_replace('-',' ',$position).'" data-effect="'.$effect.'" data-delay="'.$delay.'" class="tips-wrap '.$position.'"><span class="tips">'.do_shortcode($matches[1][0].$matches[4][0]).'</span><span style="'.$width.$bgcolor.$bordercolor.$textcolor.'" class="tooltip">'.do_shortcode($matches[3][0]).'<span class="shadow"></span><span style="'.$bot_color.'" class="bot"></span><span style="'.$top_color.'"class="top"></span></span></span>';
	}	
}
add_shortcode('tips', 'theme_shortcode_tips');


