<?php
/**
 * size: small, medium, blog
 * icon:zoom, doc, play
 */
function theme_shortcode_image($atts, $content = null, $code) {
	extract(shortcode_atts(array(
		'size' => 'medium',
		'link' => '#',
		'linktarget' => false,
		'icon' => false,
		'lightbox' => 'false',
		'title' => '',
		'align' => false,
		'group' => '',
		'width' => false,
		'height' => false,
		'autoheight' => 'false',
		'srctype'=>'url',
	), $atts));
	if(!$width){
		$width = theme_get_option('image', $size.'_width');
		if(!$width){
			$width = '150';
		}
	}
	if(!$height){
		$height = theme_get_option('image', $size.'_height');
		if(!$height){
			$height = '150';
		}
	}
	if($autoheight=='true'){
		$height = '';
	}
	$src = trim($content);
	$no_link = '';

	if($lightbox =='true'){
		if($link == '#'){
			$link = $src;
		}
		$lightbox = 'rel="prettyPhoto'.($group?'['.$group.']':'').'"';
	}else{
		if($link == '#'){
			$no_link = ' image_no_link';
		}
		$lightbox = '';
	}
	$linktarget = $linktarget?' target="'.$linktarget.'"':'';
	$resize = theme_resize($src,$width,$height,$srctype);
	$content = '<img width="'.$resize['width'].'" height="'.$resize['height'].'" data-msg="'.$resize['msg'].'" class="image_thumb" style="opacity: 0; visibility: visible;" alt="'.$title.'" src="'.$resize['url'].'"/>';
	return '<span class="image_styled'.($align?' align'.$align:'').'"><span class="image_frame"><a '.$lightbox.' class="image_size_'.$size.$no_link.($icon?' image_icon_'.$icon:'').'" title="'.$title.'" href="'.$link.'" '.$linktarget.'>' . $content . '<span class="preload overlay"></span></a></span></span>';
}
add_shortcode('image', 'theme_shortcode_image');

function theme_shortcode_picture_frame($atts, $content = null) {
	extract(shortcode_atts(array(
		'title' => '',
		'align' => 'left',
		'width' => false,
		'height'=> false,
		'framecolor'=>'',
		'bordercolor'=>'',
		'srctype'=>'url',
	), $atts));
	if(!$width){
		$width = '100';
	}
	if(!$height){
		$height = '100';
	}
	$image = theme_resize(trim($content),$width,$height,$srctype);
	$framecolor = empty($framecolor) ? '' : 'background:'.$framecolor.';'; 
	$bordercolor = empty($bordercolor) ? '' : 'border-color:'.$bordercolor.';'; 

	return '<div class="align'.$align.' picture_frame" style="width:'.($width+60).'px;height:'.($height+60).'px;"><span class="frameup" style="'.$framecolor.$bordercolor.'width:'.$width.'px;height:'.$height.'px;"><img width="'.$width.'" height="'.$height.'" data-msg="'.$image['msg'].'" alt="'.$title.'" src="'.$image['url'].'" /></span><span class="framedown" style="'.$framecolor.$bordercolor.'width:'.$width.'px;height:'.$height.'px"></span></div>';
}
add_shortcode('picture_frame', 'theme_shortcode_picture_frame');
