<?php

/**
 * Default WordPress functions.php file
 * Loads and configures the theme.
 *
 * @since Tenacity 1.0
 * @author Erik Bernskiold
 * @version 1.0
 * @package Tenacity
 **/


/**
 * Include and Set Up Ilmenite Framework Class
 ***********************************************/
 
require_once(get_template_directory() . '/framework/theme.php'); // Includes Ilmenite Framework

$ilmenite = new Ilmenite_Framework();
$ilmenite->init(array(
	'theme_name' => 'Tenacity', // Change this to the name of the theme.
	'theme_slug' => 'tenacity' // Create a custom slug for the theme.
));

/**
 * Add Theme-Specific Stuff Below Here
 *****************************************/

/**
 * Defines content width
 **/

if (!isset($content_width)) {
	$content_width = 620; // Let this to the proper content width
}

/**
 * Custom Sidebars
 *
 * Uncomment below and duplicate as needed.
 * The default sidebar is in the framework.
 **/

// Register footer-col1
register_sidebar(array(
	'id' => 'footer-col1',
	'name' => 'Footer Column 1',
    'before_widget' => '<div class="footer-col1">',
    'after_widget' => '</div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>',
));

// Register footer-col2
register_sidebar(array(
	'id' => 'footer-col2',
	'name' => 'Footer Column 2',
    'before_widget' => '<div class="footer-col2">',
    'after_widget' => '</div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>',
));

// Register footer-col3
register_sidebar(array(
	'id' => 'footer-col3',
	'name' => 'Footer Column 3',
    'before_widget' => '<div class="footer-col3">',
    'after_widget' => '</div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>',
));

// Register footer-col4
register_sidebar(array(
	'id' => 'footer-col4',
	'name' => 'Footer Column 4',
    'before_widget' => '<div class="footer-col4">',
    'after_widget' => '</div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>',
));

/**
 * Custom Post Thumbnail Size
 *
 * @since Tenacity 1.0
 **/

add_image_size('post-thumbnails', 610, 200, true); // Adds "post-thumbnails" size

/**
 * Custom Excerpt Length
 *
 * Uncomment and change as necessary.
 *
 * @since Ilmenite 1.0
 **/

/*

function new_excerpt_length($length) {
	return 200; // Sets the excerpt length (in words)
}
add_filter('excerpt_length', 'new_excerpt_length');

*/

/**
 * Adds support for custom image header
 *
 * @since Tenacity 1.0
 **/

	// The default header text color
	define('NO_HEADER_TEXT', true );
	define( 'HEADER_TEXTCOLOR', '' );

	// By leaving empty, we allow for random image rotation.
	define( 'HEADER_IMAGE', '' );

	// The height and width of your custom header.
	// Add a filter to tenacity_header_image_width and tenacity_header_image_height to change these values.
	define( 'HEADER_IMAGE_WIDTH', apply_filters( 'tenacity_header_image_width', 960 ) );
	define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'tenacity_header_image_height', 300 ) );

	// We'll be using post thumbnails for custom header images on posts and pages.
	// We want them to be the size of the header image that we just defined
	// Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
	set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );

	add_image_size( 'large-feature', HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); // Used for large feature (header) images
	add_image_size( 'small-feature', 960, 300 ); // Used for featured posts if a large-feature doesn't exist

	// Turn on random header image rotation by default.
	add_theme_support( 'custom-header', array( 'random-default' => true ) );

	// Add a way for the custom header to be styled in the admin panel that controls
	// custom headers. See tenacity_admin_header_style(), below.
	add_custom_image_header( 'tenacity_header_style', 'tenacity_admin_header_style', 'tenacity_admin_header_image' );

	// ... and thus ends the changeable header business.

	// Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
	register_default_headers( array(
		'cityscape' => array(
			'url' => trailingslashit( get_stylesheet_directory_uri() ).'/images/header-default/cityscape.jpg',
			'thumbnail_url' => trailingslashit( get_stylesheet_directory_uri() ).'/images/header-default/cityscape-thumb.jpg',
			/* translators: header image description */
			'description' => __( 'Cityscape', 'tenacity' )
		),
		
		'fall-leaves' => array(
			'url' => trailingslashit( get_stylesheet_directory_uri() ).'/images/header-default/fall-leaves.jpg',
			'thumbnail_url' => trailingslashit( get_stylesheet_directory_uri() ).'/images/header-default/fall-leaves-thumb.jpg',
			/* translators: header image description */
			'description' => __( 'Fall Leaves', 'tenacity' )
		),
		
		'waterfall' => array(
			'url' => trailingslashit( get_stylesheet_directory_uri() ).'/images/header-default/waterfall.jpg',
			'thumbnail_url' => trailingslashit( get_stylesheet_directory_uri() ).'/images/header-default/waterfall-thumb.jpg',
			/* translators: header image description */
			'description' => __( 'Waterfall', 'tenacity' )
		)
	) );

if ( ! function_exists( 'tenacity_header_style' ) ) :
/**
 * Styles the header image and text displayed on the blog
 *
 * @since Twenty Eleven 1.0
 */
function tenacity_header_style() {

	// If no custom options for text are set, let's bail
	// get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value
	if ( HEADER_TEXTCOLOR == get_header_textcolor() )
		return;
	// If we get this far, we have custom styles. Let's do this.
	?>
	<style type="text/css">
	<?php
		// Has the text been hidden?
		if ( 'blank' == get_header_textcolor() ) :
	?>
		#site-title,
		#site-description {
			position: absolute !important;
			clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
			clip: rect(1px, 1px, 1px, 1px);
		}
	<?php
		// If the user has set a custom color for the text use that
		else :
	?>
		#site-title a,
		#site-description {
			color: #<?php echo get_header_textcolor(); ?> !important;
		}
	<?php endif; ?>
	</style>
	<?php
}
endif; // tenacity_header_style

if ( ! function_exists( 'tenacity_admin_header_style' ) ) :
/**
 * Styles the header image displayed on the Appearance > Header admin panel.
 *
 * Referenced via add_custom_image_header() in tenacity_setup().
 *
 * @since Tenacity 1.0
 */
function tenacity_admin_header_style() {
?>
	<style type="text/css">
	#headimg img {
		max-width: 960px;
		height: 300px;
		width: 960px;
	}
	</style>
<?php
}
endif; // tenacity_admin_header_style

if ( ! function_exists( 'tenacity_admin_header_image' ) ) :
/**
 * Custom header image markup displayed on the Appearance > Header admin panel.
 *
 * Referenced via add_custom_image_header() in tenacity_setup().
 *
 * @since Tenacity 1.0
 */
function tenacity_admin_header_image() { ?>
	<div id="headimg">
		<?php
		if ( 'blank' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) || '' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) )
			$style = ' style="display:none;"';
		else
			$style = ' style="color:#' . get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) . ';"';
		?>
		<?php $header_image = get_header_image();
		if ( ! empty( $header_image ) ) : ?>
			<img src="<?php echo esc_url( $header_image ); ?>" alt="" />
		<?php endif; ?>
	</div>
<?php }
endif;

/**
 * Template for comments and pingbacks.
 *
 * @since Tenacity 1.0
 */
if ( ! function_exists( 'tenacity_comment' ) ) :
function tenacity_comment( $comment, $args, $depth ) {
	$GLOBALS['comment'] = $comment;
	switch ( $comment->comment_type ) :
		case 'pingback' :
		case 'trackback' :
	?>
	<li class="post pingback">
		<p><?php _e( 'Pingback:', 'tenacity' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'tenacity' ), '<span class="edit-link">', '</span>' ); ?></p>
	<?php
			break;
		default :
	?>
	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
		<article id="comment-<?php comment_ID(); ?>" class="comment">
			<footer class="comment-meta">
				<div class="comment-author vcard">
					<?php
						$avatar_size = 68;
						if ( '0' != $comment->comment_parent )
							$avatar_size = 39;

						echo get_avatar( $comment, $avatar_size );

						/* translators: 1: comment author, 2: date and time */
						printf( __( '%1$s on %2$s <span class="says">said:</span>', 'tenacity' ),
							sprintf( '<span class="fn">%s</span>', get_comment_author_link() ),
							sprintf( '<a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a>',
								esc_url( get_comment_link( $comment->comment_ID ) ),
								get_comment_time( 'c' ),
								/* translators: 1: date, 2: time */
								sprintf( __( '%1$s at %2$s', 'tenacity' ), get_comment_date(), get_comment_time() )
							)
						);
					?>

					<?php edit_comment_link( __( 'Edit', 'tenacity' ), '<span class="edit-link">', '</span>' ); ?>
				</div><!-- .comment-author .vcard -->

				<?php if ( $comment->comment_approved == '0' ) : ?>
					<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'tenacity' ); ?></em>
					<br />
				<?php endif; ?>

			</footer>

			<div class="comment-content"><?php comment_text(); ?></div>

			<div class="reply">
				<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply <span>&darr;</span>', 'tenacity' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
			</div><!-- .reply -->
		</article><!-- #comment-## -->

	<?php
			break;
	endswitch;
}
endif; // ends check for tenacity_comment()