<?php
/**
 * @version    $Id$
 * @package    IT_Theme_Framework
 * @author     InnoThemes Team <support@innothemes.com>
 * @copyright  Copyright (C) 2012 InnoThemes.com. All Rights Reserved.
 * @license    GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
 *
 * Websites: http://www.innothemes.com
 */

// Load WordPress's media selector
wp_enqueue_media();
?>
<div class="it-form-field-media-selector input-group" id="<?php $this->get( 'id' ); ?>">
	<input type="text" <?php $this->html_attributes( array( 'id', 'type' ) ); ?> />
	<span class="input-group-btn">
		<a href="javascript:void(0)" class="btn btn-default btn-sm" title="<?php _e( 'Select Media', IT_THEME_TEXTDOMAIN ); ?>">...</a>
	</span>
<?php
// Load Javascript initialization if not already loaded
if ( ! defined( 'IT_MEDIA_INITIALIZED' ) ) :

define( 'IT_MEDIA_INITIALIZED', true );

IT_Init_Assets::load( 'it-media-selector-js', 'wp-jquery-ui-dialog-css' );

$script = '
		new $.IT_MediaSelector({
			lang: {
				SELECT_MEDIA: "' . __( 'Select Media', IT_THEME_TEXTDOMAIN ) . '",
				SELECT: "' . __( 'Select', IT_THEME_TEXTDOMAIN ) . '",
			}
		});';

IT_Init_Assets::inline( 'js', $script, true );

// Generate media selector modal
?>
	<div id="it-form-field-media-selector-modal" class="hidden" title="<?php _e( 'Media Selector', IT_THEME_TEXTDOMAIN ); ?>"></div>
<?php endif; ?>
</div>
