<?php
function theme_shortcode_button($atts, $content = null, $code) {
	extract(shortcode_atts(array(
		'id' => false,
		'class' => false,
		'size' => 'small',
		'link'=>'',
		'linktarget' => '',
		'color' => 'blue',
		'bgcolor' => '',
		'width' => false,
		'textcolor' => '',
		'hoverbgcolor' => '',
		'hovertextcolor' => '',
		'full' => "false",
		'align' => false,
		'fantasy' => "false",
		'icon' => "false",
		'iconsrc' =>THEME_IMAGES.'/arrow-white.png',
		'button' =>"false",
	), $atts));
	$id = $id?' id="'.$id.'"':'';
	$full = ($full==="false")?'':' full';
	$color = $color?' '.$color:'';
	$class = $class?' '.$class:'';
	if(!empty($link)){
		$link = theme_get_superlink($link);
		$link = $link?' href="'.$link.'"':'';
	}

	$linktarget = $linktarget?' target="'.$linktarget.'"':'';

	$button = ($button==="false")?'a':'button';
	if (!empty($bgcolor)) {
		$hoverbgcolor = $hoverbgcolor?($bgcolor?' data-bg="'.$bgcolor.'"':'').' data-hoverBg="'.$hoverbgcolor.'"':'';
	}
	$hovertextcolor = $hovertextcolor?($textcolor?' data-color="'.$textcolor.'"':'').' data-hoverColor="'.$hovertextcolor.'"':'';
	
	$bgcolor = $bgcolor?' style="background-color:'.$bgcolor.'"':'';
	if($width){
		if(is_numeric($width)){
			$width = $width.'px';
		}
		$width = 'width:'.$width.';';
	}else{
		$width = '';
	}
	$textcolor = $textcolor?'color:'.$textcolor.';':'';
	
	if($align != 'center'){
		$aligncss = ' align'.$align;
	}else{
		$aligncss = '';
	}
	$fantasy =  ($fantasy==="true")?' fantasy':'';
	$icon = ($icon==="true")? '<img class="vm btn-icon" alt="" src="'.$iconsrc.'">':'';
	$content = '<'.$button.$id.$link.$linktarget.$bgcolor.$hoverbgcolor.$hovertextcolor.' class="button '.$size.$color.$full.$class.$aligncss.$fantasy.'"><span class="button-glare"></span><span class="text" style="'.$width.$textcolor.'">' . do_shortcode($content) .$icon.'</span></'.$button.'>';
	if($align === 'center'){
		return '<p class="center">'.$content.'</p>';
	}else{
		return $content;
	}
}
add_shortcode('button','theme_shortcode_button');
