<?php
/**
 * icon:zoom, doc, play
 */

function theme_shortcode_lightbox($atts, $content = null, $code) {
	global $theme_inline_id;
	$theme_inline_id = md5(uniqid(rand()));
	extract(shortcode_atts(array(
		'type' => 'image',
		'href' => '#',
		'title' => '',
		'group' => '',
		'width' => 600,
		'height' => 400,
	), $atts));
	if (! empty($group)) {
		$group = '['.$group.']';
	}

	$content = do_shortcode(str_replace('[button','[button button="true"',$content));
	if(empty($width) || !is_numeric($width)){
		$width = '600';
	}
	if(empty($height) || !is_numeric($height)){
		$height = '400';
	}
	switch ($type) {
	case 'image':
		return '<a href="'.$href.'" rel="prettyPhoto'.$group.'" title="'.$title.'">'.$content.'</a>';
		break;
	case 'inline':
		if(empty($title))
			$title='Inline Lightbox';
		return '<a href="#inline-'.$theme_inline_id.'" rel="prettyPhoto'.$group.'" title="'.$title.'">'.$title.'</a><div id="inline-'.$theme_inline_id.'" class="hide" style="width:'.$width.'px;height:'.$height.'px">'.$content.'</div>';
		break;
	case 'iframe':
		return '<a href="'.$href.'?iframe=true&amp;width='.$width.'&amp;height='.$height.'" rel="prettyPhoto'.$group.'" title="'.$title.'">'.$content.'</a>';
		break;
	case 'mv':
		return '<a href="'.$href.'?width='.$width.'&amp;height='.$height.'" rel="prettyPhoto'.$group.'" title="'.$title.'">'.$content.'</a>';
		break;
	case 'flash':
		return '<a href="'.$href.'?width='.$width.'&amp;height='.$height.'" rel="prettyPhoto'.$group.'" title="'.$title.'">'.$content.'</a>';
		break;
	default:
		return null;
		break;
	}
}

add_shortcode('lightbox', 'theme_shortcode_lightbox');
