<?php

/************* INCLUDE NEEDED FILES ***************/

/*
1. library/emerald.php
	- head cleanup (remove rsd, uri links, junk css, ect)
	- enqueueing scripts & styles
	- theme support functions
	- custom menu output & fallbacks
	- related post function
	- page-navi function
	- removing <p> from around images
	- customizing the post excerpt
	- custom google+ integration
	- adding custom fields to user profiles
*/
require_once('library/emerald.php'); // if you remove this, emerald will break
/*
2. library/custom-post-type.php
	- slider post type
*/
require_once('library/custom-post-type.php'); // you can disable this if you like

/*
3. options-panel.php
	- adding options panel
*/
include('options-panel.php');

/*
4. library/translation/translation.php
	- adding support for other languages
*/
require_once('library/translation/translation.php'); // this comes turned off by default

/************* THUMBNAIL SIZE OPTIONS *************/

// Thumbnail sizes
add_image_size( 'emerald-thumb-600', 600, 150, true );
add_image_size( 'emerald-thumb-300', 300, 100, true );
add_image_size( 'emerald-thumb-250-square', 250, 250, true );
add_image_size( 'emerald-thumb-200-square', 200, 200, true );
add_image_size( 'emerald-thumb-150-square', 150, 150, true );
/*
to add more sizes, simply copy a line from above
and change the dimensions & name. As long as you
upload a "featured image" as large as the biggest
set width or height, all the other sizes will be
auto-cropped.

To call a different size, simply change the text
inside the thumbnail function.

For example, to call the 300 x 300 sized image,
we would use the function:
<?php the_post_thumbnail( 'emerald-thumb-300' ); ?>
for the 600 x 100 image:
<?php the_post_thumbnail( 'emerald-thumb-600' ); ?>

You can change the names and dimensions to whatever
you like. Enjoy!
*/

/************** CONTENT WIDTH *********************/

if ( ! isset( $content_width ) ) $content_width = 600;

/************* ACTIVE SIDEBARS ********************/

// Sidebars & Widgetizes Areas
function emerald_register_sidebars() {
	register_sidebar(array(
		'id' => 'sidebar1',
		'name' => __('Sidebar 1', 'emeraldtheme'),
		'description' => __('The first (primary) sidebar.', 'emeraldtheme'),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h4 class="widgettitle">',
		'after_title' => '</h4>',
	));

} // don't remove this bracket!

/************* COMMENT LAYOUT *********************/

// Comment Layout
function emerald_comments($comment, $args, $depth) {
   $GLOBALS['comment'] = $comment; ?>
	<li <?php comment_class(); ?>>
		<article id="comment-<?php comment_ID(); ?>" class="clearfix">
			<header class="comment-author vcard">
				<?php
				/*
					this is the new responsive optimized comment image. It used the new HTML5 data-attribute to display comment gravatars on larger screens only. What this means is that on larger posts, mobile sites don't have a ton of requests for comment images. This makes load time incredibly fast! If you'd like to change it back, just replace it with the regular wordpress gravatar call:
					echo get_avatar($comment,$size='32',$default='<path_to_url>' );
				*/
				?>
				<!-- custom gravatar call -->
				<?php
					// create variable
					$bgauthemail = get_comment_author_email();
				?>
				<img data-gravatar="http://www.gravatar.com/avatar/<?php echo md5($bgauthemail); ?>?s=32" class="load-gravatar avatar avatar-48 photo" height="32" width="32" src="<?php echo get_template_directory_uri(); ?>/library/images/nothing.gif" />
				<!-- end custom gravatar call -->
				<?php printf(__('<cite class="fn">%s</cite>', 'emeraldtheme'), get_comment_author_link()) ?>
				<time datetime="<?php echo comment_time('Y-m-j'); ?>"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php comment_time(__('F jS, Y', 'emeraldtheme')); ?> </a></time>
				<?php edit_comment_link(__('(Edit)', 'emeraldtheme'),'  ','') ?>
			</header>
			<?php if ($comment->comment_approved == '0') : ?>
				<div class="alert alert-info">
					<p><?php _e('Your comment is awaiting moderation.', 'emeraldtheme') ?></p>
				</div>
			<?php endif; ?>
			<section class="comment_content clearfix">
				<?php comment_text() ?>
			</section>
			<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
		</article>
	<!-- </li> is added by WordPress automatically -->
<?php
} // don't remove this bracket!

/************* SEARCH FORM LAYOUT *****************/

// Search Form
function emerald_wpsearch($form) {
	$form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
	<label class="screen-reader-text" for="s">' . __('Search for:', 'emeraldtheme') . '</label>
	<input type="text" value="' . get_search_query() . '" name="s" id="s" />
	<input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
	</form>';
	return $form;
} // don't remove this bracket!

/************ Responsive Slider ********************/

function emerald_add_slider_scripts() {
	wp_register_script( 'responsive_slides', get_template_directory_uri().'/library/js/libs/responsiveslides.min.js', array('jquery') );
	wp_register_script( 'responsive_slides_settings', get_template_directory_uri().'/library/js/libs/responsiveslides-hooks-settings.js', array('responsive_slides') );

	if( is_home() ){
    		wp_enqueue_script( 'responsive_slides' );
		wp_enqueue_script( 'responsive_slides_settings' );
	}
}
add_action( 'wp_enqueue_scripts', 'emerald_add_slider_scripts' );

/************ Hover Intent ********************/

function emerald_add_hover_intent() {
	wp_register_script( 'hover_intent', get_template_directory_uri().'/library/js/libs/hoverIntent.min.js', array('jquery') );
    	wp_enqueue_script( 'hover_intent' );
}
add_action( 'wp_enqueue_scripts', 'emerald_add_hover_intent' );

/************** NAV ***************************/

function emerald_header_dropdown_nav(){
	$return_val = '<div class="dropdown-menu"><select name="page-dropdown" onchange=\'document.location.href=this.options[this.selectedIndex].value;\'> 
	<option value="">';
	$return_val .= esc_attr( __( 'Select Page', "emeraldtheme") ) . '</option>';
	$menu_name = 'main-nav';

		if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) {
		$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
	if($pages = wp_get_nav_menu_items($menu->term_id)){
	  foreach ( $pages as $key => $page ) {
		$return_val .= '<option value="' . $page->url . '">';
		$menu_item_title =  $page->title;
		$return_val  .= $menu_item_title;
		$return_val  .= '</option>';
	  }
	}
	}

	if(!$pages){
		$pages = get_pages(); 
	  foreach ( $pages as $page ) {
		$return_val .= '<option value="' . get_page_link( $page->ID ) . '">';
		$return_val .= $page->post_title;
		$return_val .= '</option>';
	  }
	}
	$return_val .= '</select></div>';

	return $return_val;
}

function emerald_credit_links(){
	_e('Theme by <a href="http://wpgurus.net/">WP Gurus</a>.', 'emeraldtheme');
}

add_action('after_switch_theme', 'emerald_theme_activation');
function emerald_theme_activation(){
	header('Location: ' . admin_url() . 'admin.php?page=options-panel.php');
}

?>