<?php // Meta Options (WPShout.com)

require(ghostpool_inc . 'options.php');

add_action('admin_menu', 'ghostpool_create_meta_box');
add_action('save_post', 'ghostpool_save_meta_data');

function ghostpool_create_meta_box() {
	global $theme_name;

	add_meta_box('post-meta-boxes', __('Post Settings', 'gp_lang'), 'post_meta_boxes', 'post', 'normal', 'high');
	add_meta_box('page-meta-boxes', __('Page Settings', 'gp_lang'), 'page_meta_boxes', 'page', 'normal', 'high');
	add_meta_box('portfolio-meta-boxes', __('Portfolio Item Settings', 'gp_lang'), 'portfolio_meta_boxes', 'portfolio', 'normal', 'high');	
}


/*************************** Post Settings ***************************/

function ghostpool_post_meta_boxes() {

	$meta_boxes = array(

	'category_page_settings' => array('name' => 'category_page_settings', 'type' => 'open', 'desc' => '', 'title' => __('Settings for when the post is on category pages...', 'gp_lang')),

		'ghostpool_custom_link' => array( 'name' => 'ghostpool_custom_link', 'title' => __('Category Page Image Link', 'gp_lang'), 'desc' => 'On category pages, this is what the image links to. Overrides the default page link.', 'type' => 'text', 'std' => ''),
		
		'ghostpool_lightbox_type' => array( 'name' => 'ghostpool_lightbox_type', 'title' => __('Lightbox Type', 'gp_lang'), 'desc' => 'Choose whether to open the "Category Page Image Link" in a lightbox.', 'options' => array('None', 'Image', 'Video'), 'type' => 'select', 'std' => ''),

	array('type' => 'close'),
	
	'post_settings' => array('name' => 'post_settings', 'type' => 'open', 'desc' => '', 'title' => __('Settings for the post...', 'gp_lang')),

		'ghostpool_hide_thumbnail' => array( 'name' => 'ghostpool_hide_thumbnail', 'title' => __('Hide Image', 'gp_lang'), 'desc' => __('Hide the image on the actual post.', 'gp_lang'), 'type' => 'checkbox', 'std' => ''),
		
		'ghostpool_image_width' => array( 'name' => 'ghostpool_image_width', 'title' => __('Cropped Image Width', 'gp_lang'), 'desc' => __('The width to crop the image to (px).', 'gp_lang'), 'std' => '0', 'type' => 'text_small'),
		
		'ghostpool_image_height' => array( 'name' => 'ghostpool_image_height', 'title' => __('Cropped Image Height', 'gp_lang'), 'desc' => __('The height to crop the image to (px).', 'gp_lang'), 'std' => '0', 'type' => 'text_small'),
		
		'ghostpool_hide_page_title' => array( 'name' => 'ghostpool_hide_page_title', 'title' => __('Hide Page Title', 'gp_lang'), 'desc' => __('Hide the page title.', 'gp_lang'), 'type' => 'checkbox', 'std' => ''),

		array('type' => 'divider'),	
		
		'ghostpool_hide_meta' => array( 'name' => 'ghostpool_hide_meta', 'title' => __('Hide Meta Text', 'gp_lang'), 'desc' => __('Hide the post date and categories.', 'gp_lang'), 'type' => 'checkbox', 'std' => ''),
		
		'ghostpool_sidebar_1' => array( 'name' => 'ghostpool_sidebar_1', 'title' => __('Left Sidebar', 'gp_lang'), 'desc' => __('Choose which sidebar to display on the left of the page.', 'gp_lang'), 'std' => 'Default Left Sidebar', 'type' => 'select_sidebar'),

		'ghostpool_sidebar_2' => array( 'name' => 'ghostpool_sidebar_2', 'title' => __('Right Sidebar', 'gp_lang'), 'desc' => __('Choose which sidebar to display on the right of the page.', 'gp_lang'), 'std' => 'Default Right Sidebar', 'type' => 'select_sidebar'),
		
		'ghostpool_skin' => array( 'name' => 'ghostpool_skin', 'title' => __('Page Skin', 'gp_lang'), 'desc' => __('Choose the skin for this page.', 'gp_lang'), 'options' => array('Default', 'Light', 'Dark'), 'type' => 'select', 'std' => 'Default'),
		
	array('type' => 'close'),

	'slider_settings' => array('name' => 'slider_settings', 'type' => 'open', 'desc' => '', 'title' => __('Settings for displaying a slider on the post...', 'gp_lang')),

		'ghostpool_slider' => array( 'name' => 'ghostpool_slider', 'title' => __('Enable Slider', 'gp_lang'), 'desc' => __('Choose this option to enable the slider on your post.', 'gp_lang'), 'type' => 'checkbox', 'std' => ''),
		
		'ghostpool_slides' => array( 'name' => 'ghostpool_slides', 'title' => __('Slide', 'gp_lang'), 'desc' => __('', 'gp_lang'), 'std' => '', 'type' => 'slides', 'size' => 'large'),		

		array('type' => 'divider'),		

		'ghostpool_slide_video_priority' => array( 'name' => 'ghostpool_slide_video_priority', 'title' => __('Video Priority', 'gp_lang'), 'desc' => 'If you have provided both flash and HTML5 videos, select which one will take priority if the browser can play both.', 'options' => array('Flash', 'HTML5'), 'type' => 'select', 'std' => ''),
		
		'ghostpool_slide_video_controls' => array( 'name' => 'ghostpool_slide_video_controls', 'title' => __('Video Controls', 'gp_lang'), 'desc' => 'Choose how to display the video controls (does not apply to Vimeo videos).', 'options' => array('Bottom', 'Over', 'None'), 'type' => 'select', 'std' => ''),
		
	array('type' => 'close'),
	
	array('type' => 'clear'),
	
	);

	return apply_filters( 'ghostpool_post_meta_boxes', $meta_boxes );
}


/*************************** Page Settings ***************************/

function ghostpool_page_meta_boxes() {
	
	$meta_boxes = array(
	
	'page_settings' => array('name' => 'page_settings', 'type' => 'open', 'desc' => '', 'title' => __('Settings for the page...', 'gp_lang')),
		
		'ghostpool_hide_page_title' => array( 'name' => 'ghostpool_hide_page_title', 'title' => __('Hide Page Title', 'gp_lang'), 'desc' => __('Hide the page title.', 'gp_lang'), 'type' => 'checkbox', 'std' => ''),
		
		'ghostpool_sidebar' => array( 'name' => 'ghostpool_sidebar', 'title' => __('Sidebar', 'gp_lang'), 'desc' => __('Choose which sidebar area to display on this page.', 'gp_lang'), 'std' => 'Default Sidebar', 'type' => 'select_sidebar'),
		
		'ghostpool_skin' => array( 'name' => 'ghostpool_skin', 'title' => __('Page Skin', 'gp_lang'), 'desc' => __('Choose the skin for this page.', 'gp_lang'), 'options' => array('Default', 'Light', 'Dark'), 'type' => 'select', 'std' => 'Default'),
		
	array('type' => 'close'),
	
	array('type' => 'clear'),
	
	);

	return apply_filters( 'ghostpool_page_meta_boxes', $meta_boxes );
}


/*************************** Portfolio Settings ***************************/

function ghostpool_portfolio_meta_boxes() {
	
	$meta_boxes = array(

	'category_page_settings' => array('name' => 'category_page_settings', 'type' => 'open', 'desc' => '', 'title' => __('Settings for when the post is on category pages...', 'gp_lang')),

		'ghostpool_custom_link' => array( 'name' => 'ghostpool_custom_link', 'title' => __('Category Page Image Link', 'gp_lang'), 'desc' => 'On category pages, this is what the image links to. Overrides the default page link.', 'type' => 'text', 'std' => ''),
		
		'ghostpool_lightbox_type' => array( 'name' => 'ghostpool_lightbox_type', 'title' => __('Lightbox Type', 'gp_lang'), 'desc' => 'Choose whether to open the "Category Page Image Link" in a lightbox.', 'options' => array('None', 'Image', 'Video'), 'type' => 'select', 'std' => ''),

	array('type' => 'close'),
	
	'post_settings' => array('name' => 'post_settings', 'type' => 'open', 'desc' => '', 'title' => __('Settings for the post itself...', 'gp_lang')),
		
		'ghostpool_image_width' => array( 'name' => 'ghostpool_image_width', 'title' => __('Cropped Image Width', 'gp_lang'), 'desc' => __('The width to crop the image to (px).', 'gp_lang'), 'std' => '578', 'type' => 'text_small'),
		
		'ghostpool_image_height' => array( 'name' => 'ghostpool_image_height', 'title' => __('Cropped Image Height', 'gp_lang'), 'desc' => __('The height to crop the image to (px).', 'gp_lang'), 'std' => '0', 'type' => 'text_small'),
		
		'ghostpool_hide_thumbnail' => array( 'name' => 'ghostpool_hide_thumbnail', 'title' => __('Hide Image', 'gp_lang'), 'desc' => __('Hide the image on the portfolio item page.', 'gp_lang'), 'type' => 'checkbox', 'std' => ''),
		
		'ghostpool_view_project' => array( 'name' => 'ghostpool_view_project', 'title' => __('View Project URL', 'gp_lang'), 'desc' => __('Add a link to your project on your portfolio item page e.g. <code>http://google.com</code>.', 'gp_lang'), 'std' => '', 'type' => 'text'),		

		array('type' => 'divider'),	
		
		'ghostpool_hide_page_title' => array( 'name' => 'ghostpool_hide_page_title', 'title' => __('Hide Page Title', 'gp_lang'), 'desc' => __('Hide the page title.', 'gp_lang'), 'type' => 'checkbox', 'std' => ''),
		
		'ghostpool_hide_meta' => array( 'name' => 'ghostpool_hide_meta', 'title' => __('Hide Meta Text', 'gp_lang'), 'desc' => __('Hide the post date and categories.', 'gp_lang'), 'type' => 'checkbox', 'std' => ''),
		
		'ghostpool_sidebar_1' => array( 'name' => 'ghostpool_sidebar_1', 'title' => __('Left Sidebar', 'gp_lang'), 'desc' => __('Choose which sidebar to display on the left of the page.', 'gp_lang'), 'std' => 'Default Left Sidebar', 'type' => 'select_sidebar'),

		'ghostpool_sidebar_2' => array( 'name' => 'ghostpool_sidebar_2', 'title' => __('Right Sidebar', 'gp_lang'), 'desc' => __('Choose which sidebar to display on the right of the page.', 'gp_lang'), 'std' => 'Default Right Sidebar', 'type' => 'select_sidebar'),

		array('type' => 'divider'),	
		
		'ghostpool_skin' => array( 'name' => 'ghostpool_skin', 'title' => __('Page Skin', 'gp_lang'), 'desc' => __('Choose the skin for this page.', 'gp_lang'), 'options' => array('Default', 'Light', 'Dark'), 'type' => 'select', 'std' => 'Default'),
		
	array('type' => 'close'),

	'slider_settings' => array('name' => 'slider_settings', 'type' => 'open', 'desc' => '', 'title' => __('Settings for displaying a slider on the post...', 'gp_lang')),

		'ghostpool_slider' => array( 'name' => 'ghostpool_slider', 'title' => __('Enable Slider', 'gp_lang'), 'desc' => __('Choose this option to enable the slider on your portfolio item page.', 'gp_lang'), 'type' => 'checkbox', 'std' => ''),
		
		'ghostpool_slides' => array( 'name' => 'ghostpool_slides', 'title' => __('Slide', 'gp_lang'), 'desc' => __('', 'gp_lang'), 'std' => '', 'type' => 'slides', 'size' => 'large'),		

		array('type' => 'divider'),		

		'ghostpool_slide_video_priority' => array( 'name' => 'ghostpool_slide_video_priority', 'title' => __('Video Priority', 'gp_lang'), 'desc' => 'If you have provided both flash and HTML5 videos, select which one will take priority if the browser can play both.', 'options' => array('Flash', 'HTML5'), 'type' => 'select', 'std' => ''),
		
		'ghostpool_slide_video_controls' => array( 'name' => 'ghostpool_slide_video_controls', 'title' => __('Video Controls', 'gp_lang'), 'desc' => 'Choose how to display the video controls (does not apply to Vimeo videos).', 'options' => array('Bottom', 'Over', 'None'), 'type' => 'select', 'std' => ''),
		
	array('type' => 'close'),
	
	array('type' => 'clear'),
	
	);

	return apply_filters( 'ghostpool_page_meta_boxes', $meta_boxes );
}


/*************************** Meta Fields ***************************/

function post_meta_boxes() {
	global $post;
	$meta_boxes = ghostpool_post_meta_boxes(); ?>

	<?php echo '<link rel="stylesheet" href="'.get_bloginfo('template_url').'/lib/admin/css/meta.css" type="text/css" media="screen" />'; ?>

	<?php foreach ( $meta_boxes as $meta ) :
		if(isset($meta['name'])) { $value = get_post_meta( $post->ID, $meta['name'], true ); }
		if ( $meta['type'] == 'text' )
			get_meta_text( $meta, $value );
		if ( $meta['type'] == 'text_small' )
			get_meta_text_small( $meta, $value );			
		elseif ( $meta['type'] == 'textarea' )
			get_meta_textarea( $meta, $value );
		elseif ( $meta['type'] == 'select' )
			get_meta_select( $meta, $value );
		elseif ( $meta['type'] == 'select_sidebar' )
			get_meta_select_sidebar( $meta, $value );
		elseif ( $meta['type'] == 'select_taxonomy' )
			get_meta_select_taxonomy( $meta, $value );			
		elseif ( $meta['type'] == 'checkbox' )
			get_meta_checkbox( $meta, $value );		
		elseif ( $meta['type'] == 'slides' )
			get_meta_slides( $meta, $value );			
		elseif ( $meta['type'] == 'open' )
			get_meta_open( $meta, $value );		
		elseif ( $meta['type'] == 'close' )
			get_meta_close( $meta, $value );
		elseif ( $meta['type'] == 'divider' )
			get_meta_divider( $meta, $value );			
		elseif ( $meta['type'] == 'clear' )
			get_meta_clear( $meta, $value );
	endforeach; ?>
	
<?php
}

function page_meta_boxes() {
	global $post;
	$meta_boxes = ghostpool_page_meta_boxes(); ?>

	<?php echo '<link rel="stylesheet" href="'.get_bloginfo('template_url').'/lib/admin/css/meta.css" type="text/css" media="screen" />'; ?>

	<?php foreach ( $meta_boxes as $meta ) :
		if(isset($meta['name'])) { $value = get_post_meta( $post->ID, $meta['name'], true ); }
		if ( $meta['type'] == 'text' )
			get_meta_text( $meta, $value );
		if ( $meta['type'] == 'text_small' )
			get_meta_text_small( $meta, $value );			
		elseif ( $meta['type'] == 'textarea' )
			get_meta_textarea( $meta, $value );
		elseif ( $meta['type'] == 'select' )
			get_meta_select( $meta, $value );
		elseif ( $meta['type'] == 'select_sidebar' )
			get_meta_select_sidebar( $meta, $value );
		elseif ( $meta['type'] == 'select_taxonomy' )
			get_meta_select_taxonomy( $meta, $value );			
		elseif ( $meta['type'] == 'checkbox' )
			get_meta_checkbox( $meta, $value );				
		elseif ( $meta['type'] == 'open' )
			get_meta_open( $meta, $value );		
		elseif ( $meta['type'] == 'close' )
			get_meta_close( $meta, $value );
		elseif ( $meta['type'] == 'divider' )
			get_meta_divider( $meta, $value );			
		elseif ( $meta['type'] == 'clear' )
			get_meta_clear( $meta, $value );	
	endforeach; ?>

<?php
}

function portfolio_meta_boxes() {
	global $post;
	$meta_boxes = ghostpool_portfolio_meta_boxes(); ?>

	<?php echo '<link rel="stylesheet" href="'.get_bloginfo('template_url').'/lib/admin/css/meta.css" type="text/css" media="screen" />'; ?>

	<?php foreach ( $meta_boxes as $meta ) :
		if(isset($meta['name'])) { $value = get_post_meta( $post->ID, $meta['name'], true ); }
		if ( $meta['type'] == 'text' )
			get_meta_text( $meta, $value );
		if ( $meta['type'] == 'text_small' )
			get_meta_text_small( $meta, $value );			
		elseif ( $meta['type'] == 'textarea' )
			get_meta_textarea( $meta, $value );
		elseif ( $meta['type'] == 'select' )
			get_meta_select( $meta, $value );
		elseif ( $meta['type'] == 'select_sidebar' )
			get_meta_select_sidebar( $meta, $value );
		elseif ( $meta['type'] == 'select_taxonomy' )
			get_meta_select_taxonomy( $meta, $value );			
		elseif ( $meta['type'] == 'checkbox' )
			get_meta_checkbox( $meta, $value );	
		elseif ( $meta['type'] == 'slides' )
			get_meta_slides( $meta, $value );				
		elseif ( $meta['type'] == 'open' )
			get_meta_open( $meta, $value );		
		elseif ( $meta['type'] == 'close' )
			get_meta_close( $meta, $value );
		elseif ( $meta['type'] == 'divider' )
			get_meta_divider( $meta, $value );			
		elseif ( $meta['type'] == 'clear' )
			get_meta_clear( $meta, $value );	
	endforeach; ?>
	

<?php } function get_meta_open( $args = array(), $value = false ) {
extract( $args ); ?>
	
	<div class="meta-group">
	
	<h3><?php echo $title; ?></h3>
	<div class="group-desc"><?php echo $desc; ?></div><div class="clear"></div>
	<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />		
	
	
<?php } function get_meta_close( $args = array(), $value = false ) {
extract( $args ); ?>
	
	</div><div class="clear"></div>
	<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />		
	
	
<?php } function get_meta_divider( $args = array(), $value = false ) {
extract( $args ); ?>

	<div class="divider"></div>
	<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />		


<?php } function get_meta_clear( $args = array(), $value = false ) {
extract( $args ); ?>
	
	<div class="clear"></div>
	<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />		
	
	
<?php } function get_meta_text( $args = array(), $value = false ) {
extract( $args ); global $post; ?>

	<div class="meta-box">
		<strong><?php echo $title; ?></strong>
		<br/><input type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_html( $value, 1 ); ?>" size="30" tabindex="30" <?php if($extras == "getimage" OR $extras == "getvideo") { ?>class="uploadbutton"<?php } ?> />
		<?php if($extras == "getimage") { ?><a href="media-upload.php?post_id=<?php echo $post->ID; ?>&amp;type=image&amp;TB_iframe=true&amp;width=640&amp;height=790" id="add_image" class="thickbox button" title='Add an Image' onclick="return false;">Get Image</a><?php } elseif($extras == "getvideo") { ?><a href="media-upload.php?post_id=<?php echo $post->ID; ?>&amp;type=video&amp;TB_iframe=true&amp;width=640&amp;height=790" id="add_video" class="thickbox button" title='Add a Video' onclick="return false;">Get Video</a><?php } ?>
		<div class="meta-desc"><?php echo $desc; ?></div>
		<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
	</div>


<?php } function get_meta_text_small( $args = array(), $value = false ) {
extract( $args ); ?>

	<div class="meta-box">
		<strong><?php echo $title; ?></strong>
		<br/><input type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php if(esc_html( $value, 1 )) { echo esc_html( $value, 1 ); } else { echo esc_html( $std, 1 ); } ?>" size="30" tabindex="30" class="small-textbox" />
		<div class="meta-desc"><?php echo $desc; ?></div>
		<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
	</div>
	
	
<?php } function get_meta_select( $args = array(), $value = false ) {
extract( $args ); ?>

	<div class="meta-box">
		<strong><?php echo $title; ?></strong>
		<br/><select name="<?php echo $name; ?>" id="<?php echo $name; ?>">
		<?php foreach ( $options as $option ) : ?>
			<option <?php if(htmlentities($value, ENT_QUOTES) == $option) echo ' selected="selected"'; ?>>
				<?php echo $option; ?>
			</option>
		<?php endforeach; ?>
		</select>
		<div class="meta-desc"><?php echo $desc; ?></div>
		<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
	</div>


<?php } function get_meta_select_sidebar( $args = array(), $value = false ) {
extract( $args );
global $post, $wp_registered_sidebars; ?>

	<div class="meta-box">
		<strong><?php echo $title; ?></strong><br/>		
		<select name="<?php echo $name; ?>" id="<?php echo $name; ?>">			
			<?php if($std == "Default Left Sidebar") { ?>
				<option value="Default Left Sidebar"<?php if($value == "Default Left Sidebar") { echo ' selected="selected"'; } ?>>Default Left Sidebar</option>
			<?php } else { ?>
				<option value="Default Right Sidebar"<?php if($value == "Default Right Sidebar") { echo ' selected="selected"'; } ?>>Default Right Sidebar</option>
			<?php } ?>
			<?php $sidebars = $wp_registered_sidebars;
			if(is_array($sidebars) && !empty($sidebars)){ foreach($sidebars as $sidebar){ if($selected_sidebar[$i] == $sidebar['name']){ ?>
				<option value="<?php echo $sidebar['name']; ?>"<?php if($value == $sidebar['name']) { echo ' selected="selected"'; } ?>><?php echo $sidebar['name']; ?></option>
			<?php }else{ ?>
				<?php if($sidebar['name'] == "Default Left Sidebar" OR $sidebar['name'] == "Default Right Sidebar") {} else { ?>
					<option value="<?php echo $sidebar['name']; ?>"<?php if($value == $sidebar['name']) { echo ' selected="selected"'; } ?>><?php echo $sidebar['name']; ?></option>
				<?php } ?>
			<?php }}} ?>
		</select>
		<div class="meta-desc"><?php echo $desc; ?></div>
		<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
	</div>
	

<?php } function get_meta_select_taxonomy( $args = array(), $value = false ) {
extract( $args ); ?>

	<div class="meta-box">
		<strong><?php echo $title; ?></strong>
		<?php $terms = get_terms('portfolio_categories', 'hide_empty=0'); ?>
		<br/><select name="<?php echo $name; ?>" id="<?php echo $name; ?>">
			<option value="All"<?php if($value == "All") { echo ' selected="selected"'; } ?>>All Categories</option>
		<?php foreach ($terms as $term): ?>
			<option value="<?php echo $term->slug; ?>"<?php if($value == $term->slug) { echo ' selected="selected"'; } ?>><?php echo $term->name; ?></option>
		<?php endforeach; ?>
		</select>
		<div class="meta-desc"><?php echo $desc; ?></div>
		<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
	</div>
	
	
<?php } function get_meta_textarea( $args = array(), $value = false ) {
extract( $args ); ?>

	<div class="meta-box<?php if($size == "large") { ?> meta-box-large<?php } ?>">	
		<strong><?php echo $title; ?></strong>
		<br/><textarea name="<?php echo $name; ?>" id="<?php echo $name; ?>" cols="60" rows="4" tabindex="30"><?php echo esc_html( $value, 1 ); ?></textarea>
		<div class="meta-desc"><?php echo $desc; ?></div>
		<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
	</div>


<?php } function get_meta_checkbox( $args = array(), $value = false ) {
extract( $args ); ?>

	<div class="meta-box">
		<strong><?php echo $title; ?></strong>
		<?php if( esc_html($value, 1 ) ){ $checked = "checked=\"checked\""; } else { if ( $std === "true" ){ $checked = "checked=\"checked\""; } else { $checked = ""; } } ?>
		<input type="checkbox" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="false" <?php echo $checked; ?> />
		<div class="meta-desc"><?php echo $desc; ?></div>
		<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />		
	</div>


<?php } function get_meta_slides( $args = array(), $value = false ) {
extract( $args ); global $post; ?>

	<div class="meta-box">
	
		<div style="float: left; padding-top: 10px;">
			<a href="media-upload.php?post_id=<?php echo $post->ID; ?>&amp;type=image&amp;TB_iframe=true&amp;width=640&amp;height=790" id="add_image" class="thickbox button" title='<?php _e('Add Slide(s)', 'gp_lang'); ?>' onclick="return false;"><?php _e('Add Slide(s)', 'gp_lang'); ?></a> <a href="media-upload.php?post_id=<?php echo $post->ID; ?>&amp;type=image&amp;tab=gallery&amp;TB_iframe=true&amp;width=640&amp;height=790" id="add_image" class="thickbox button" title='<?php _e('View Slide(s)', 'gp_lang'); ?>' onclick="return false;"><?php _e('View Slide(s)', 'gp_lang'); ?></a>
		</div>
		
	</div>

	<div class="clear"></div>
	
	<div class="meta-box<?php if($size == "large") { ?> meta-box-large<?php } ?>">
	
		<?php $args = array('post_type' => 'attachment', 'post_parent' => $post->ID, 'numberposts' => -1, 'orderby' => 'date', 'orderby' => 'menu_order', 'order' => 'ASC'); $attachments = get_children($args); if($attachments) { foreach ($attachments as $attachment) { ?>
			<img src="<?php if($theme_timthumb == "0") { ?><?php echo get_template_directory_uri(); ?>/lib/scripts/timthumb.php?src=<?php } ?><?php echo wp_get_attachment_thumb_url($attachment->ID); ?><?php if($theme_timthumb == "0") { ?>&amp;h=100&amp;w=100&amp;zc=1<?php } ?>" alt="" width="100" height="100" />
		<?php }} ?>
		
		<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />

	</div>

<?php }


function ghostpool_save_meta_data( $post_id ) {
	global $post;

	if ( 'page' == $_POST['post_type'] )
		$meta_boxes = array_merge( ghostpool_page_meta_boxes() );
	elseif ( 'portfolio' == $_POST['post_type'] )
		$meta_boxes = array_merge( ghostpool_portfolio_meta_boxes() );		
	else
		$meta_boxes = array_merge( ghostpool_post_meta_boxes() );
		

	foreach ( $meta_boxes as $meta_box ) :

		if ( !wp_verify_nonce( $_POST[$meta_box['name'] . '_noncename'], plugin_basename( __FILE__ ) ) )
			return $post_id;

		if ( 'page' == $_POST['post_type'] && !current_user_can( 'edit_page', $post_id ) )
			return $post_id;

		elseif ( 'post' == $_POST['post_type'] && !current_user_can( 'edit_post', $post_id ) )
			return $post_id;

		elseif ( 'portfolio' == $_POST['post_type'] && !current_user_can( 'edit_post', $post_id ) )
			return $post_id;
			
		$data = stripslashes( $_POST[$meta_box['name']] );

		if ( get_post_meta( $post_id, $meta_box['name'] ) == '' )
			add_post_meta( $post_id, $meta_box['name'], $data, true );

		elseif ( $data != get_post_meta( $post_id, $meta_box['name'], true ) )
			update_post_meta( $post_id, $meta_box['name'], $data );

		elseif ( $data == '' )
			delete_post_meta( $post_id, $meta_box['name'], get_post_meta( $post_id, $meta_box['name'], true ) );

	endforeach;
}
?>