<?php
/**
 * Tuned functions and definitions.
 *
 * @package      Tuned
 * @author       Elod Horvath
 * @copyright    2013-... Elod Horvath
 * @since        1.0
 */

 
 if ( ! isset( $content_width ) )
	$content_width = 900;
	
 
/* Tuned theme setup 
----------------------------------------------------------*/
function tuned_setup() {
	
	/* Add editor style */
	add_editor_style();
	
	/* Custom header */
	$args_ch = array( 
		// Header image default
	       'default-image'			=> get_template_directory_uri() . '/images/default-logo.png',
	        // Header text display default
	       'header-text'			=> false,
	        // Header image flex width
		   'flex-width'             => true,
	        // Header image width (in pixels)
	       'width'				    => 300,
		    // Header image flex height
		   'flex-height'            => true,
	        // Header image height (in pixels)
	       'height'			        => 100
	);
	add_theme_support( 'custom-header', $args_ch );
	
	/* Post thumbnails */
	add_theme_support( 'post-thumbnails' );
	//set_post_thumbnail_size( 624, 9999 );
	
	/* Make theme available for translation */
	load_theme_textdomain( 'tuned', get_template_directory() . '/languages' );
	
	/* Add Primary Navigation Menu */
	register_nav_menu( 'primary', __( 'Primary Menu', 'tuned' ) );
	
	/* Add posts and comments RSS feed links to <head> */
	add_theme_support( 'automatic-feed-links' );
	
	/* Add support for custom backgrounds. */
	$args_cb = array( 
		'default-color' => 'FFF',
		//'default-image' => ''
	);
	add_theme_support( 'custom-background', $args_cb );
	
	
	
}
add_action( 'after_setup_theme', 'tuned_setup' );



/* Add styles, and/or javascripts to theme 
-----------------------------------------------------------*/
function tuned_scripts() {
	
	// Add styles
	wp_enqueue_style( 'tuned-ie', get_template_directory_uri() .'/css/ie.css' );
	wp_enqueue_style( 'Montserrat', 'http://fonts.googleapis.com/css?family=Montserrat:400,700' );
	wp_enqueue_style( 'flexslider', get_template_directory_uri() .'/js/vendor/flexslider/flexslider.css' );
	
	/*
	 * Adds JavaScript to pages with the comment form to support
	 * sites with threaded comments (when in use).
	 */
	if ( is_singular() && comments_open() )
		wp_enqueue_script( 'comment-reply' );
	
	// Register FlexSlider
	wp_register_script( 'tuned_flexslider', get_template_directory_uri() .'/js/vendor/flexslider/jquery.flexslider.js', array( 'jquery' ) );
	wp_enqueue_script( 'tuned_flexslider' );
	
	// Register Infinite Scroll
	wp_register_script( 'tuned_infinite_scroll', get_template_directory_uri() .'/js/vendor/infinite-scroll/jquery.infinitescroll.js', array( 'jquery' ) );
	wp_enqueue_script( 'tuned_infinite_scroll' );
	
	// Register Masonry
	wp_register_script( 'tuned_masonry', get_template_directory_uri() .'/js/vendor/masonry/jquery.masonry.js', array( 'jquery' ) );
	wp_enqueue_script( 'tuned_masonry' );
	
	// Register Tuned javascript file
	wp_register_script( 'tuned_scripts', get_template_directory_uri() .'/js/tuned_scripts.js' );
	wp_enqueue_script( 'tuned_scripts' );

}
add_action( 'wp_enqueue_scripts', 'tuned_scripts' );


/* Register widgets 
-------------------------------------------------------------*/
function tuned_widgets_init() {

	register_sidebar( array( 
		'name'            => __( 'Main sidebar', 'tuned' ),
		'id'              => 'sidebar-1',
		'before_widget'   => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'    => '</aside>',
		'before_title'    => '<h3 class="widget-title">',
		'after_title'     => '</h3>'
	) );
	
	register_sidebar(array(
		'name'          => __('Front Page - Hero Box', 'tuned'),
		'description' => __( 'Full width box for Hero on Front Page Template. Drag and drop to here the Hero for Hero Box Widget.', 'tuned' ),
		'id'            => 'frontend-hero',
		'before_widget' => '<div class="fullbox">',
		'after_widget'  => '</div>',		
	));
	
	register_sidebar(array(
		'name'          => __('Full width Template - Hero Box', 'tuned'),
		'description' => __( 'Full width box for Hero on Full width Template. Drag and drop to here the Hero for Hero Box Widget.', 'tuned' ),
		'id'            => 'full-width-template-hero',
		'before_widget' => '',
		'after_widget'  => '',		
	));
	
	register_sidebar(array(
		'name'          => __('Front Page - Carousel Box', 'tuned'),
		'description' => __( 'Full width box for Carousel on Front Page Template. Drag and drop to here the Category for Carousel Box Widget. If you want to display featured image of the post ONLY in the Carousel, add the following string to your image(rename): _icon(eg. yourthumb_icon.png)', 'tuned' ),
		'id'            => 'frontend-carousel',
		'before_widget' => '',
		'after_widget'  => '',		
	));
	
	register_sidebar(array(
		'name'          => __('Full width Template - Carousel Box', 'tuned'),
		'description' => __( 'Full width box for Carousel on Full width Template. Drag and drop to here the Category for Carousel Box Widget. If you want to display featured image of the post ONLY in the Carousel, add the following string to your image(rename): _icon(eg. yourthumb_icon.png)', 'tuned' ),
		'id'            => 'full-width-template-carousel',
		'before_widget' => '',
		'after_widget'  => '',		
	));
	
	register_sidebar(array(
		'name'          => __('Front Page - 1 Column Grid Box', 'tuned'),
		'description' => __( 'Appears on the Front Page. If you want to display featured image of the post ONLY in the grid, add the following string to your image(rename): _icon(eg. yourthumb_icon.png)', 'tuned' ),
		'id'            => 'frontend-grid-1',
		'before_widget' => '',
		'after_widget'  => '',		
	));
	
	register_sidebar(array(
		'name'          => __('Front Page - 3 Column Grid Box', 'tuned'),
		'description' => __( 'Appears on the Front Page. If you want to display featured image of the post ONLY in the grid, add the following string to your image(rename): _icon(eg. yourthumb_icon.png)', 'tuned' ),
		'id'            => 'frontend-grid-3',
		'before_widget' => '',
		'after_widget'  => '',		
	));
	
	register_widget('Tuned_Hero_Widget');
	register_widget('Tuned_Category_Widget');
	register_widget('Tuned_Carousel_Widget');

}
add_action( 'widgets_init', 'tuned_widgets_init' );
require_once( 'inc/widgets.php' );


/* Content navigation 
----------------------------------------------------------*/
if( !function_exists( 'tuned_content_nav' ) ) {

	function tuned_content_nav( $nav_id ) {

		global $wp_query;
		$nav_id = esc_attr( $nav_id );
	
		if( $wp_query->max_num_pages > 1 ) : ?>
	
			<nav id="<?php echo $nav_id; ?>" class="nav-content" role="navigation">
				<?php if( get_next_posts_link() ) : ?>
					<span class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'tuned' ) ); ?></span>
				<?php endif; ?>
				<?php if( get_previous_posts_link() ) : ?>
					<span class="nav-next"><?php previous_posts_link( __( 'Newer posts <span>&rarr;</span>', 'tuned' ) ); ?></span>
				<?php endif; ?>
			</nav>
	
		<?php endif;

	}
	
}


/* Single content navigation 
----------------------------------------------------------*/
if( !function_exists( 'tuned_single_nav' ) ) {

	function tuned_single_nav() {

		?>
		
		<nav class="nav-single">
			<span class="nav-previous"><?php previous_post_link( '%link', '<span class="meta-nav">' . __( '&larr;', 'tuned' ) . '</span> %title' ); ?></span>				
			<span class="nav-next"><?php next_post_link( '%link', '%title <span class="meta-nav">' . __( '&rarr;', 'tuned' ) . '</span>' ); ?></span>		
		</nav>
		
		<?php
	}
	
}




/* Entry meta 
------------------------------------------------------------*/
if( !function_exists( 'tuned_entry_meta' ) ) {

	function tuned_entry_meta() {
			
		$category_list = get_the_category_list( __( ', ', 'tuned' ) );
		$tag_list      = get_the_tag_list( __( 'Tags', 'tuned' ) . ': ' , __( ', ', 'tuned' ) );
		$date          = esc_attr( get_the_date() );
		$time          = esc_attr( get_the_time( 'c' ) );
		$author        = esc_attr( get_the_author() );
		$link_to_author_posts  = esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) );
	
		?>
		<p>
		<time class="entry-date" datetime="<?php echo $time; ?>"><a href="<?php esc_url( get_permalink() ); ?>" rel="bookmark"><?php echo $date; ?></a></time>
		<span class="author vcard"> - <a href="<?php echo $link_to_author_posts; ?>"><?php echo __( 'By', 'tuned' ) . ' ' . $author; ?></a></span><br />
		<span class="category-list"><?php echo __( 'Categories', 'tuned' ) . ': ' . $category_list; ?></span>
		<span class="tag-list"><?php echo $tag_list; ?></span>
		</p>
		<?php
	}
	
}



?>