<?php
if ( ! function_exists( 'catchflames_register_styles' ) ) :
/**
 * Register theme styles
 *
 * Registers stylesheets used by the theme.
 * Also offers integration with Google Web Fonts Directory
 * @uses wp_register_style() To register styles
 *
 * @since Catch Flames Pro 1.0.
 */
function catchflames_register_styles() {
	global $catchflames_options_settings;
    $options = $catchflames_options_settings;

	$fontbody = $options[ 'body_font' ];
	$fonttitle = $options[ 'title_font' ];
	$fontheading = $options[ 'headings_font' ];
	$fontcontent = $options[ 'content_font' ];

	$web_fonts = array(
		'allan'					=> 'Allan',
		'allerta'				=> 'Allerta',
		'amaranth'				=> 'Amaranth',
		'bitter'				=> 'Bitter',
		'cabin'					=> 'Cabin',
		'cantarell'				=> 'Cantarell',
		'crimson-text'			=> 'Crimson+Text',
		'dancing-script'		=> 'Dancing+Script',
		'droid-sans'			=> 'Droid+Sans',
		'droid-serif'			=> 'Droid+Serif',
		'istok-web'				=> 'Istok+Web',
		'lato'					=> 'Lato',
		'lobster'				=> 'Lobster',
		'lora'					=> 'Lora',
		'nobile'				=> 'Nobile',
		'open-sans'				=> 'Open+Sans',
		'oswald'				=> 'Oswald',
		'patua-one'				=> 'Patua+One',
		'playfair-display'		=> 'Playfair+Display',
		'pt-sans'				=> 'PT+Sans',
		'pt-serif'				=> 'PT+Serif',
		'quattrocento-sans' 	=> 'Quattrocento+Sans',
		'ubuntu'				=> 'Ubuntu',
		'yanone-kaffeesatz' 	=> 'Yanone+Kaffeesatz'
	);

	if ( empty( $options[ 'reset_typography' ] )  && ( array_key_exists( $fontbody, $web_fonts ) || array_key_exists( $fonttitle, $web_fonts ) || array_key_exists( $fontheading, $web_fonts ) || array_key_exists( $fontcontent, $web_fonts ) ) ) {

		$web_fonts_stylesheet = 'http' . ( is_ssl() ? 's' : '' ) . '://fonts.googleapis.com/css?family=';

		if( array_key_exists( $fontbody, $web_fonts ) ) {
			$web_fonts_stylesheet .= $web_fonts[$fontbody] . ':300,300italic,regular,italic,600,600italic';
		}

		if( array_key_exists( $fonttitle, $web_fonts ) ) {
			if( array_key_exists( $fontbody, $web_fonts ) ) {
				$web_fonts_stylesheet .='|';
			}
			$web_fonts_stylesheet .= $web_fonts[$fonttitle] . ':300,300italic,regular,italic,600,600italic';
		}

		if( array_key_exists( $fontheading, $web_fonts ) ) {
			if( array_key_exists( $fontbody, $web_fonts ) || array_key_exists( $fonttitle, $web_fonts ) ) {
				$web_fonts_stylesheet .='|';
			}
			$web_fonts_stylesheet .= $web_fonts[$fontheading] . ':300,300italic,regular,italic,600,600italic';
		}

		if( array_key_exists( $fontcontent, $web_fonts ) ) {
			if( array_key_exists( $fontbody, $web_fonts ) || array_key_exists( $fonttitle, $web_fonts ) || array_key_exists( $fontheading, $web_fonts ) ) {
				$web_fonts_stylesheet .='|';
			}
			$web_fonts_stylesheet .= $web_fonts[$fontcontent] . ':300,300italic,regular,italic,600,600italic';
		}

		$web_fonts_stylesheet .= '&subset=latin';

	}
	else {

		$web_fonts_stylesheet = false;

	}

	if( false !== $web_fonts_stylesheet ) {
		wp_register_style( 'catchflames-web-font', $web_fonts_stylesheet, false, null );
		$catchflames_deps = array( 'catchflames-web-font' );
	}
	else {
		$catchflames_deps = false;
	}

	wp_register_style( 'catch-flames', get_stylesheet_uri(), $catchflames_deps, null );

}
endif;
add_action( 'init', 'catchflames_register_styles' );


/**
 * Register jquery scripts
 *
 * @register jquery cycle and custom-script
 * hooks action wp_enqueue_scripts
 */
function catchflames_scripts_method() {
	global $post, $wp_query, $catchflames_options_settings;

	// Get value from Theme Options panel
	$options = $catchflames_options_settings;
	$enableslider = $options[ 'enable_slider' ];

	// Front page displays in Reading Settings
	$page_on_front = get_option('page_on_front') ;
	$page_for_posts = get_option('page_for_posts');

	// Get Page ID outside Loop
	$page_id = $wp_query->get_queried_object_id();

	// Enqueue catchflames Sytlesheet
	wp_enqueue_style( 'catch-flames' );
	
	//For genericons
	wp_enqueue_style( 'genericons', get_template_directory_uri() . '/css/genericons/genericons.css', false, '3.3' );


	/**
	 * Adds JavaScript to pages with the comment form to support
	 * sites with threaded comments (when in use).
	 */
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}

	// Register JQuery cycle all and JQuery set up as dependent on Jquery-cycle
	wp_register_script( 'jquery-cycle', get_template_directory_uri() . '/js/jquery.cycle.all.min.js', array( 'jquery' ), '2.9999.5', true );

	// Slider JS load loop
	if ( ( $enableslider == 'enable-slider-allpage' ) || ( ( is_front_page() || ( is_home() && $page_id != $page_for_posts ) ) && $enableslider == 'enable-slider-homepage' ) ) {
		wp_enqueue_script( 'catchflames-slider', get_template_directory_uri() . '/js/catchflames.slider.js', array( 'jquery-cycle' ), '1.0', true );
	}

	//Responsive-Static
	wp_register_script( 'sidr', get_template_directory_uri() . '/js/jquery.sidr.min.js', array('jquery'), '1.2.1', false );
	wp_register_script( 'fitvids', get_template_directory_uri() . '/js/fitvids.min.js', array( 'jquery' ), '20130324', true );
	wp_register_style( 'catchflames-responsive', get_template_directory_uri() . '/css/responsive.css' );
	wp_register_style( 'catchflames-static', get_template_directory_uri() . '/css/static.css' );
	if ( empty ($options[ 'disable_responsive' ] ) ) {
		wp_enqueue_style( 'catchflames-responsive' );
		wp_enqueue_script( array('catchflames-fitvids', 'sidr' ) );
	}
	else {
		wp_enqueue_style( 'catchflames-static' );
	}

	/**
	 * Loads up Waypoint script
	 */
	wp_register_script( 'jquery-waypoint', get_template_directory_uri() . '/js/jquery.waypoints.min.js', array( 'jquery' ), '3.1.1', true );
	if ( '1' == $options['enable_header_top'] || '1' != $options['disable_scrollup'] ) :
		wp_enqueue_script( 'jquery-waypoint' );
	endif;

	/**
	 * Loads up Custom script
	 */
	wp_enqueue_script( 'catchflames-custom', get_template_directory_uri() . '/js/catchflames-custom.min.js', array( 'jquery' ), '20140823', true );

	//Browser Specific Enqueue Script i.e. for IE 1-6
	$catchflames_ua = strtolower($_SERVER['HTTP_USER_AGENT']);
	if(preg_match('/(?i)msie [1-6]/',$catchflames_ua)) {
		wp_enqueue_script( 'catchflames-pngfix', get_template_directory_uri() . '/js/pngfix.min.js' );
	}
	//browser specific queuing i.e. for IE 1-8
	if(preg_match('/(?i)msie [1-8]/',$catchflames_ua)) {
	 	wp_enqueue_script( 'catchflames-ieltc8', get_template_directory_uri() . '/js/catchflames-ielte8.min.js', array( 'jquery' ), '20130114', false );
		wp_enqueue_style( 'catchflames-iecss', get_template_directory_uri() . '/css/ie.css' );
	}

} // catchflames_scripts_method
add_action( 'wp_enqueue_scripts', 'catchflames_scripts_method' );


/**
 * Register script for admin section
 *
 * No scripts should be enqueued within this function.
 * jquery cookie used for remembering admin tabs, and potential future features... so let's register it early
 * @uses wp_register_script
 * @action admin_enqueue_scripts
 */
function catchflames_register_js() {
	//jQuery Cookie
	wp_register_script( 'jquery-cookie', get_template_directory_uri() . '/js/jquery.cookie.min.js', array( 'jquery' ), '1.0', true );
}
add_action( 'admin_enqueue_scripts', 'catchflames_register_js' );


/**
 * Responsive Layout
 *
 * @get the data value of responsive layout from theme options
 * @display responsive meta tag
 * @action wp_head
 */
function catchflames_responsive() {
	//delete_transient('catchflames_responsive');

	if ( !$catchflames_responsive = get_transient( 'catchflames_responsive' ) ) {
		global $catchflames_options_settings;
        $options = $catchflames_options_settings;

		if ( $options[ 'disable_responsive' ] == '0' ) {
			$catchflames_responsive = '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
		}
		else {
			$catchflames_responsive = '<!-- Disable Responsive -->';
		}
		set_transient( 'catchflames_responsive', $catchflames_responsive, 86940 );
	}
	echo $catchflames_responsive;
} // catchflames_responsive
add_filter( 'wp_head', 'catchflames_responsive', 1 );


/**
 * Get the favicon Image from theme options
 *
 * @uses favicon
 * @get the data value of image from theme options
 * @display favicon
 *
 * @uses default favicon if favicon field on theme options is empty
 *
 * @uses set_transient and delete_transient
 */
function catchflames_favicon() {
	//delete_transient( 'catchflames_favicon' );

	if( ( !$catchflames_favicon = get_transient( 'catchflames_favicon' ) ) ) {

		global $catchflames_options_settings;
        $options = $catchflames_options_settings;

		echo '<!-- refreshing cache -->';
		if ( $options[ 'remove_favicon' ] == "0" ) :
			// if not empty fav_icon on theme options
			if ( !empty( $options[ 'fav_icon' ] ) ) :
				$catchflames_favicon = '<link rel="shortcut icon" href="'.esc_url( $options[ 'fav_icon' ] ).'" type="image/x-icon" />';
			else:
				// if empty fav_icon on theme options, display default fav icon
				$catchflames_favicon = '<link rel="shortcut icon" href="'. get_template_directory_uri() .'/images/favicon.ico" type="image/x-icon" />';
			endif;
		endif;

		set_transient( 'catchflames_favicon', $catchflames_favicon, 86940 );
	}
	echo $catchflames_favicon ;
} // catchflames_favicon

//Load Favicon in Header Section
add_action('wp_head', 'catchflames_favicon');

//Load Favicon in Admin Section
add_action( 'admin_head', 'catchflames_favicon' );


/**
 * Enqueue the styles for the current color scheme.
 *
 * @since Catch Flames Pro 1.0
 */
function catchflames_enqueue_color_scheme() {
	global $catchflames_options_settings;
    $options = $catchflames_options_settings;
	$color_scheme = $options['color_scheme'];

	if ( 'dark' == $color_scheme )
		wp_enqueue_style( 'dark', get_template_directory_uri() . '/colors/dark.css', array(), null );

	do_action( 'catchflames_enqueue_color_scheme', $color_scheme );
}
add_action( 'wp_enqueue_scripts', 'catchflames_enqueue_color_scheme' );


/**
 * Hooks the Custom Inline CSS to head section
 *
 * @since Catch Flames Pro 1.0
 */
function catchflames_inline_css() {
	//delete_transient( 'catchflames_inline_css' );

	global $catchflames_options_settings, $catchflames_options_defaults;
	$options = $catchflames_options_settings;
	$defaults = $catchflames_options_defaults;

	$fonts = catchflames_available_fonts();

	if ( !$catchflames_inline_css = get_transient( 'catchflames_inline_css' ) ) {
		// Header Margin Options
			//Header Top Margin
			if( $defaults['header_top_size'] != $options[ 'header_top_size' ] || $defaults['header_top_size_unit'] != $options[ 'header_top_size_unit' ] ) {
				$catchflames_inline_css	.=  "#header-content { padding-top: ".$options[ 'header_top_size' ] . $options[ 'header_top_size_unit' ] ."; }". "\n";
			}
			//Header Bottom Margin
			if( $defaults['header_bottom_size'] != $options[ 'header_bottom_size' ] || $defaults['header_bottom_size_unit'] != $options[ 'header_bottom_size_unit' ] ) {
				$catchflames_inline_css	.=  "#header-content { padding-bottom: ".$options[ 'header_bottom_size' ] . $options[ 'header_bottom_size_unit' ] ."; }". "\n";
			}

		// Site Color Options
			// Title hover Color
			if( $defaults[ 'title_hover_color' ] != $options[ 'title_hover_color' ] ) {
				$catchflames_inline_css	.=  "#site-title a:hover, #site-title a:focus, #site-title a:active { color: ".  $options[ 'title_hover_color' ] ."; }". "\n";
			}
			// Tagline Color
			if( $defaults[ 'tagline_color' ] != $options[ 'tagline_color' ] ) {
				$catchflames_inline_css	.=  "#site-description { color: ".  $options[ 'tagline_color' ] ."; }". "\n";
			}
			// Text Color
			if( $defaults[ 'text_color' ] != $options[ 'text_color' ] ) {
				$catchflames_inline_css	.=  "body, input, textarea { color: ".  $options[ 'text_color' ] ."; }". "\n";
			}
			// Link Color
			if( $defaults[ 'link_color' ] != $options[ 'link_color' ] ) {
				$catchflames_inline_css	.=  "a { color: ".  $options[ 'link_color' ] ."; }". "\n";
			}

		//Header Color Options
			// Header Background Color
			if( $defaults[ 'header_top_background' ] != $options[ 'header_top_background' ] ) {
				$catchflames_inline_css	.=  "#sidebar-header-top { background-color: ".  $options[ 'header_top_background' ] ."; }". "\n";
			}
			// Header Background Color
			if( $defaults[ 'header_background' ] != $options[ 'header_background' ] ) {
				$catchflames_inline_css	.=  "#branding { background-color: ".  $options[ 'header_background' ] ."; }". "\n";
			}
			// Header Image Background Color
			if( $defaults[ 'header_image_background' ] != $options[ 'header_image_background' ] ) {
				$catchflames_inline_css	.=  "#header-image { background-color: ".  $options[ 'header_image_background' ] ."; }". "\n";
			}

		//Slider Color Options
			// Slider Background Color
			if( $defaults[ 'slider_background' ] != $options[ 'slider_background' ] ) {
				$catchflames_inline_css	.=  "#main-slider { background-color: ".  $options[ 'slider_background' ] ."; }". "\n";
				$catchflames_inline_css	.=  "#main-slider .hentry { background-color: transparent; }". "\n";
			}
			// Slider Text Color
			if( $defaults[ 'slider_text' ] != $options[ 'slider_text' ] ) {
				$catchflames_inline_css	.=  "#main-slider .entry-header .entry-title, #main-slider .entry-header .entry-title a, #main-slider .entry-content  { color: ".  $options[ 'slider_text' ] ."; }". "\n";
			}

		//Content Color Options
			// Main Wrapper Background Color
			if( $defaults[ 'content_background' ] != $options[ 'content_background' ] ) {
				$catchflames_inline_css	.=  "#main { background-color: ".  $options[ 'content_background' ] ."; }". "\n";
			}
			// Content Background Color
			if( $defaults[ 'article_background' ] != $options[ 'article_background' ] ) {
				$catchflames_inline_css	.=  ".hentry, .no-results, #author-info, #disqus_thread, #content .error404 { background-color: ".  $options[ 'article_background' ] ."; }". "\n";
			}
			// Heading Background Color
			if( $defaults[ 'heading_color' ] != $options[ 'heading_color' ] ) {
				$catchflames_inline_css	.=  "entry-title, .entry-title a { color: ".  $options[ 'heading_color' ] ."; }". "\n";
			}
			// Heading Hover Color
			if( $defaults[ 'heading_hover_color' ] != $options[ 'heading_hover_color' ] ) {
				$catchflames_inline_css	.=  ".entry-title a:hover, .entry-title a:focus, .entry-title a:active { color: ".  $options[ 'heading_hover_color' ] ."; }". "\n";
			}
			// Meta Text Color
			if( $defaults[ 'meta_color' ] != $options[ 'meta_color' ] ) {
				$catchflames_inline_css	.=  ".entry-meta { color: ".  $options[ 'meta_color' ] ."; }". "\n";
			}
			// Meta Link Color
			if( $defaults[ 'meta_link_color' ] != $options[ 'meta_link_color' ] ) {
				$catchflames_inline_css	.=  ".entry-meta a { color: ".  $options[ 'meta_link_color' ] ."; }". "\n";
			}

		//Comment Color Options
			// Comment Box Background and Text Color
			if( ( $defaults[ 'comment_background' ] != $options[ 'comment_background' ] ) || ( $defaults[ 'comment_text_color' ] != $options[ 'text_color' ] ) ) {
				$catchflames_inline_css	.=  "#comments { background-color: ".  $options[ 'comment_background' ] ."; color: ".  $options[ 'comment_text_color' ] ."; }". "\n";
			}
			// Comment Box Title Color
			if( $defaults[ 'comment_title_color' ] != $options[ 'comment_title_color' ] ) {
				$catchflames_inline_css	.=  "#comments-title, #reply-title { color: ".  $options[ 'comment_title_color' ] ."; }". "\n";
			}
			// Comment Box Link Color
			if( $defaults[ 'comment_link_color' ] != $options[ 'comment_link_color' ] ) {
				$catchflames_inline_css	.=  "#comments a { color: ".  $options[ 'comment_link_color' ] ."; }". "\n";
			}

		//ScrollUp Color Options
			// ScrollUp Color
			if( ( $defaults[ 'scrollup_bg_color' ] != $options[ 'scrollup_bg_color' ] ) || ( $defaults[ 'scrollup_text_color' ] != $options[ 'scrollup_text_color' ] ) ) {
				$catchflames_inline_css	.=  "a#scrollup { background-color: ".  $options[ 'scrollup_bg_color' ] ."; color: ".  $options[ 'scrollup_text_color' ] ."; }". "\n";
			}

		// Sidebar Color Options
			// Widget Background Color
			if( $defaults[ 'widget_background' ] != $options[ 'widget_background' ] ) {
				$catchflames_inline_css	.=  ".widget { background-color: ".  $options[ 'widget_background' ] ."; }". "\n";
			}

			// Widget Heading Color
			if( $defaults[ 'widget_heading_color' ] != $options[ 'widget_heading_color' ] ) {
				$catchflames_inline_css	.=  ".widget-area .widget-title, .widget-area .widget-title a { color: ".  $options[ 'widget_heading_color' ] ."; }". "\n";
			}
			// Widget Text Color
			if( $defaults[ 'widget_text_color' ] != $options[ 'widget_text_color' ] ) {
				$catchflames_inline_css	.=  ".widget-area .widget, .widget-area .widget ul li { color: ".  $options[ 'widget_text_color' ] ."; }". "\n";
			}
			// Widget Link Color
			if( $defaults[ 'widget_link_color' ] != $options[ 'widget_link_color' ] ) {
				$catchflames_inline_css	.=  ".widget a { color: ".  $options[ 'widget_link_color' ] ."; }". "\n";
			}

		// Footer Color Options
			// Footer Sidebar Area Background Color
			if( $defaults[ 'footer_background' ] != $options[ 'footer_background' ] ) {
				$catchflames_inline_css	.=  "#footer-sidebar { background-color: ".  $options[ 'footer_background' ] ."; }". "\n";
			}
			// Footer Sidebar Widget Background Color
			if( $defaults[ 'widget_footer_background' ] != $options[ 'widget_footer_background' ] ) {
				$catchflames_inline_css	.=  "#supplementary .widget { background-color: ".  $options[ 'widget_footer_background' ] ."; }". "\n";
			}
			// Footer Sidebar Widget Title Color:
			if( $defaults[ 'widget_footer_title_color' ] != $options[ 'widget_footer_title_color' ] ) {
				$catchflames_inline_css	.=  "#supplementary .widget-title, #supplementary .widget-title a { color: ".  $options[ 'widget_footer_title_color' ] ."; }". "\n";
			}
			// Footer Sidebar Widget Text Color
			if( $defaults[ 'widget_footer_text_color' ] != $options[ 'widget_footer_text_color' ] ) {
				$catchflames_inline_css	.=  "#supplementary .widget { color: ".  $options[ 'widget_footer_text_color' ] ."; }". "\n";
			}
			// Footer Sidebar Widget Link Color
			if( $defaults[ 'widget_footer_link_color' ] != $options[ 'widget_footer_link_color' ] ) {
				$catchflames_inline_css	.=  "#supplementary .widget a { color: ".  $options[ 'widget_footer_link_color' ] ."; }". "\n";
			}
			// Footer Background and Text Color
			if( ( $defaults[ 'sitegenerator_background' ] != $options[ 'sitegenerator_background' ] ) || ( $defaults[ 'sitegenerator_text_color' ] != $options[ 'sitegenerator_text_color' ] ) ) {
				$catchflames_inline_css	.=  "#site-generator { background-color: ".  $options[ 'sitegenerator_background' ] ."; color: ".  $options[ 'sitegenerator_text_color' ] ."; }". "\n";
			}
			// Footer Link Color
			if( $defaults[ 'sitegenerator_link_color' ] != $options[ 'sitegenerator_link_color' ] ) {
				$catchflames_inline_css	.=  "#site-generator a { background-color: ".  $options[ 'sitegenerator_link_color' ] ."; }". "\n";
			}

		// Memu Color Options
			// Primary Menu Background Color
			if( $defaults[ 'menu_background' ] != $options[ 'menu_background' ] ) {
				$catchflames_inline_css	.=  "#header-menu #access { background-color: " .  $options[ 'menu_background' ] ."; }". "\n";
			}
			// Primary Menu Color
			if( $defaults[ 'menu_color' ] != $options[ 'menu_color' ] ) {
				$catchflames_inline_css	.=  "#header-menu #access ul.menu a { color: " .  $options[ 'menu_color' ] ."; }". "\n";
			}
			// Primary Menu Hover Background and Color
			if( ( $defaults[ 'hover_background_color' ] != $options[ 'hover_background_color' ] ) || ( $defaults[ 'hover_text_color' ] != $options[ 'hover_text_color' ] ) ) {
				$catchflames_inline_css	.=  "#header-menu #access ul.menu li:hover > a, #header-menu #access ul.menu a:focus { background: none " .  $options[ 'hover_background_color' ] ."; color: " .  $options[ 'hover_text_color' ] ."; }". "\n";
			}
			// Primary Menu Active Background and Color
			if( ( $defaults[ 'active_background_color' ] != $options[ 'active_background_color' ] ) || ( $defaults[ 'active_text_color' ] != $options[ 'active_text_color' ] ) ) {
				$catchflames_inline_css	.=  "#header-menu #access ul.menu .current-menu-item > a, #header-menu #access ul.menu .current-menu-ancestor > a, #header-menu #access ul.menu .current_page_item > a, #header-menu #access ul.menu .current_page_ancestor > a { background: none " .  $options[ 'active_background_color' ] ."; color: " .  $options[ 'active_text_color' ] ."; }". "\n";
			}
			// Primary SubMenu Active Background and Color
			if( ( $defaults[ 'sub_menu_bg_color' ] != $options[ 'sub_menu_bg_color' ] ) || ( $defaults[ 'sub_menu_text_color' ] != $options[ 'sub_menu_text_color' ] ) ) {
				$catchflames_inline_css	.=  "#header-menu #access ul.menu ul a { background: none " .  $options[ 'sub_menu_bg_color' ] ."; color: " .  $options[ 'sub_menu_text_color' ] ."; }". "\n";
			}
			// Seconday Menu Background Color
			if( $defaults[ 'secondary_menu_background' ] != $options[ 'secondary_menu_background' ] ) {
				$catchflames_inline_css	.=  "#header-menu #access-secondary { background-color: " .  $options[ 'secondary_menu_background' ] ."; }". "\n";
			}
			// Secondary Menu Color
			if( $defaults[ 'secondary_menu_color' ] != $options[ 'secondary_menu_color' ] ) {
				$catchflames_inline_css	.=  "#header-menu #access-secondary ul.menu a { color: " .  $options[ 'secondary_menu_color' ] ."; }". "\n";
			}
			// Secondary Menu Hover Background and Color
			if( ( $defaults[ 'secondary_hover_background_color' ] != $options[ 'secondary_hover_background_color' ] ) || ( $defaults[ 'secondary_hover_text_color' ] != $options[ 'secondary_hover_text_color' ] ) ) {
				$catchflames_inline_css	.=  "#header-menu #access-secondary ul.menu li:hover > a, #header-menu #access-secondary ul.menu a:focus { background: none " .  $options[ 'secondary_hover_background_color' ] ."; color: " .  $options[ 'secondary_hover_text_color' ] ."; }". "\n";
			}
			// Secondary Menu Active Background and Color
			if( ( $defaults[ 'secondary_active_background' ] != $options[ 'secondary_active_background' ] ) || ( $defaults[ 'secondary_active_text_color' ] != $options[ 'secondary_active_text_color' ] ) ) {
				$catchflames_inline_css	.=  "#header-menu #access-secondary ul.menu .current-menu-item > a, #header-menu #access-secondary ul.menu .current-menu-ancestor > a, #header-menu #access-secondary ul.menu .current_page_item > a, #header-menu #access-secondary ul.menu .current_page_ancestor > a { background: none " .  $options[ 'secondary_active_background' ] ."; color: " .  $options[ 'secondary_active_text_color' ] ."; }". "\n";
			}
			// Secondary SubMenu Background and Color
			if( ( $defaults[ 'secondary_sub_menu_bg_color' ] != $options[ 'secondary_sub_menu_bg_color' ] ) || ( $defaults[ 'secondary_sub_menu_text_color' ] != $options[ 'secondary_sub_menu_text_color' ] ) ) {
				$catchflames_inline_css	.=  "#header-menu #access-secondary ul.menu ul a { background: none " .  $options[ 'secondary_sub_menu_bg_color' ] ."; color: " .  $options[ 'secondary_sub_menu_text_color' ] ."; }". "\n";
			}
			// Footer Menu Background Color
			if( $defaults[ 'footer_menu_background' ] != $options[ 'footer_menu_background' ] ) {
				$catchflames_inline_css	.=  "#footer-menu { background-color: " .  $options[ 'footer_menu_background' ] ."; }". "\n";
			}
			// Footer Menu Color
			if( $defaults[ 'footer_menu_color' ] != $options[ 'footer_menu_color' ] ) {
				$catchflames_inline_css	.=  "#footer-menu ul.menu a { color: " .  $options[ 'footer_menu_color' ] ."; }". "\n";
			}
			// Footer Menu Hover Background and Color
			if( ( $defaults[ 'footer_hover_background_color' ] != $options[ 'footer_hover_background_color' ] ) || ( $defaults[ 'footer_hover_text_color' ] != $options[ 'footer_hover_text_color' ] ) ) {
				$catchflames_inline_css	.=  "#footer-menu ul.menu li:hover > a,  #footer-menu ul.menu a:focus { background: none " .  $options[ 'footer_hover_background_color' ] ."; color: " .  $options[ 'footer_hover_text_color' ] ."; }". "\n";
			}
			// Footer Menu Active Background and Color
			if( ( $defaults[ 'footer_active_background_color' ] != $options[ 'footer_active_background_color' ] ) || ( $defaults[ 'footer_active_text_color' ] != $options[ 'footer_active_text_color' ] ) ) {
				$catchflames_inline_css	.=  "#footer-menu ul.menu .current-menu-item > a, #footer-menu ul.menu .current-menu-ancestor > a, #footer-menu ul.menu .current_page_item > a, #footer-menu ul.menu .current_page_ancestor > a { background: none " .  $options[ 'footer_active_background_color' ] ."; color: " .  $options[ 'footer_active_text_color' ] ."; }". "\n";
			}
			// Footer SubMenu Background and Color
			if( ( $defaults[ 'footer_sub_menu_bg_color' ] != $options[ 'footer_sub_menu_bg_color' ] ) || ( $defaults[ 'footer_sub_menu_text_color' ] != $options[ 'footer_sub_menu_text_color' ] ) ) {
				$catchflames_inline_css	.=  "#footer-menu ul.menu ul a { background: none " .  $options[ 'footer_sub_menu_bg_color' ] ."; color: " .  $options[ 'footer_sub_menu_text_color' ] ."; }". "\n";
			}
			// Header Top Menu Background Color
			if( $defaults[ 'header_top_menu_bg_color' ] != $options[ 'header_top_menu_bg_color' ] ) {
				$catchflames_inline_css	.=  "#access-top ul.menu { background-color: " .  $options[ 'header_top_menu_bg_color' ] ."; }". "\n";
			}
			// Header Top Menu Color
			if( $defaults[ 'header_top_menu_color' ] != $options[ 'header_top_menu_color' ] ) {
				$catchflames_inline_css	.=  "#access-top ul.menu a { color: " .  $options[ 'header_top_menu_color' ] ."; }". "\n";
			}
			// Header Top Menu Hover Background and Color
			if( ( $defaults[ 'header_top_hover_bg_color' ] != $options[ 'header_top_hover_bg_color' ] ) || ( $defaults[ 'header_top_hover_color' ] != $options[ 'header_top_hover_color' ] ) ) {
				$catchflames_inline_css	.=  "#access-top ul.menu li:hover > a, #access-top ul.menu ul :hover > a, #access-top ul.menu a:focus, #access-top ul.menu ul li a:hover { background: none " .  $options[ 'header_top_hover_bg_color' ] ."; color: " .  $options[ 'header_top_hover_color' ] ."; }". "\n";
			}
			// Header Top Menu Active Background and Color
			if( ( $defaults[ 'header_top_active_bg_color' ] != $options[ 'header_top_active_bg_color' ] ) || ( $defaults[ 'header_top_active_color' ] != $options[ 'header_top_active_color' ] ) ) {
				$catchflames_inline_css	.=  "#access-top ul.menu .current-menu-item > a, #access-top ul.menu .current-menu-ancestor > a, #access-top ul.menu .current_page_item > a, #access-top ul.menu .current_page_ancestor > a { background: none " .  $options[ 'header_top_active_bg_color' ] ."; color: " .  $options[ 'header_top_active_color' ] ."; }". "\n";
			}
			// Header Top SubMenu Background and Color
			if( ( $defaults[ 'header_top_sub_menu_bg_color' ] != $options[ 'header_top_sub_menu_bg_color' ] ) || ( $defaults[ 'header_top_sub_menu_color' ] != $options[ 'header_top_sub_menu_color' ] ) ) {
				$catchflames_inline_css	.=  "#access-top ul.menu ul a { background: none " .  $options[ 'header_top_sub_menu_bg_color' ] ."; color: " .  $options[ 'header_top_sub_menu_color' ] ."; }". "\n";
			}
			// Header Top Menu Border Color
			if( $defaults[ 'header_top_sub_menu_border_color' ] != $options[ 'header_top_sub_menu_border_color' ] ) {
				$catchflames_inline_css	.=  "#access-top ul.menu ul, #access-top ul.menu ul ul { border-color: " .  $options[ 'header_top_sub_menu_border_color' ] ."; }". "\n";
			}
			// Header Right Menu Background Color
			if( $defaults[ 'header_right_menu_bg_color' ] != $options[ 'header_right_menu_bg_color' ] ) {
				$catchflames_inline_css	.=  ".sidebar-top .widget_nav_menu ul.menu { background-color: " .  $options[ 'header_right_menu_bg_color' ] ."; }". "\n";
			}
			// Header Right Menu Color
			if( $defaults[ 'header_right_menu_color' ] != $options[ 'header_right_menu_color' ] ) {
				$catchflames_inline_css	.=  ".sidebar-top .widget_nav_menu ul.menu a { color: " .  $options[ 'header_right_menu_color' ] ."; }". "\n";
			}
			// Header Right Menu Hover Background and Color
			if( ( $defaults[ 'header_right_hover_bg_color' ] != $options[ 'header_right_hover_bg_color' ] ) || ( $defaults[ 'header_right_hover_color' ] != $options[ 'header_right_hover_color' ] ) ) {
				$catchflames_inline_css	.=  ".sidebar-top .widget_nav_menu ul.menu li:hover > a, .sidebar-top .widget_nav_menu ul.menu ul :hover > a, .sidebar-top .widget_nav_menu ul.menu a:focus { background: none " .  $options[ 'header_right_hover_bg_color' ] ."; color: " .  $options[ 'header_right_hover_color' ] ."; }". "\n";
			}
			// Header Right Menu Active Background and Color
			if( ( $defaults[ 'header_right_active_bg_color' ] != $options[ 'header_right_active_bg_color' ] ) || ( $defaults[ 'header_right_active_color' ] != $options[ 'header_right_active_color' ] ) ) {
				$catchflames_inline_css	.=  ".sidebar-top .widget_nav_menu .menu .current-menu-item > a, .sidebar-top .widget_nav_menu .menu .current-menu-ancestor > a, .sidebar-top .widget_nav_menu .menu .current_page_item > a, .sidebar-top .widget_nav_menu .menu .current_page_ancestor > a { background: none " .  $options[ 'header_right_active_bg_color' ] ."; color: " .  $options[ 'header_right_active_color' ] ."; }". "\n";
			}
			// Header Right SubMenu Background and Color
			if( ( $defaults[ 'header_right_sub_menu_bg_color' ] != $options[ 'header_right_sub_menu_bg_color' ] ) || ( $defaults[ 'header_right_sub_menu_color' ] != $options[ 'header_right_sub_menu_color' ] ) ) {
				$catchflames_inline_css	.=  ".sidebar-top .widget_nav_menu ul.menu ul a { background: none " .  $options[ 'header_right_sub_menu_bg_color' ] ."; color: " .  $options[ 'header_right_sub_menu_color' ] ."; }". "\n";
			}
			// Header Right Menu Border Color
			if( $defaults[ 'header_right_border_top_color' ] != $options[ 'header_right_border_top_color' ] ) {
				$catchflames_inline_css	.=  ".sidebar-top .widget_nav_menu ul.menu ul { border-color: " .  $options[ 'header_right_border_top_color' ] ."; }". "\n";
			}
			// Mobile Menu Open Color
			if( $defaults[ 'mobile_hamburger_open_color' ] != $options[ 'mobile_hamburger_open_color' ] ) {
				$catchflames_inline_css	.=  ".mobile-menu a { color: " .  $options[ 'mobile_hamburger_open_color' ] ."; }". "\n";
			}
			// Mobile Menu Close Color
			if( $defaults[ 'mobile_hamburger_close_color' ] != $options[ 'mobile_hamburger_close_color' ] ) {
				$catchflames_inline_css	.=  ".sidr-open .mobile-menu a { color: " .  $options[ 'mobile_hamburger_close_color' ] ."; }". "\n";
			}
			// Mobile Menu Background Color
			if( $defaults[ 'mobile_bg_color' ] != $options[ 'mobile_bg_color' ] ) {
				$catchflames_inline_css	.=  ".sidr { background-color: " .  $options[ 'mobile_bg_color' ] ."; }". "\n";
			}
			// Mobile Menu Color
			if( $defaults[ 'mobile_color' ] != $options[ 'mobile_color' ] ) {
				$catchflames_inline_css	.=  ".sidr ul li a, .sidr ul li span { color: " .  $options[ 'mobile_color' ] ."; }". "\n";
			}
			// Mobile Menu Hover Background and Color
			if( ( $defaults[ 'mobile_hover_bg_color' ] != $options[ 'mobile_hover_bg_color' ] ) || ( $defaults[ 'mobile_hover_color' ] != $options[ 'mobile_hover_color' ] ) ) {
				$catchflames_inline_css	.=  ".sidr ul li:hover>a, .sidr ul li:hover>span, .sidr ul li.active>a, .sidr ul li.active>span, .sidr ul li.sidr-class-active>a, .sidr ul li.sidr-class-active>span { background: none " .  $options[ 'mobile_hover_bg_color' ] ."; color: " .  $options[ 'mobile_hover_color' ] ."; box-shadow: none; }". "\n";
			}
			// Mobile SubMenu Background and Color
			if( ( $defaults[ 'mobile_sub_menu_bg_color' ] != $options[ 'mobile_sub_menu_bg_color' ] ) || ( $defaults[ 'mobile_sub_menu_color' ] != $options[ 'mobile_sub_menu_color' ] ) ) {
				$catchflames_inline_css	.=  ".sidr ul li ul li a, .sidr ul li ul li span { background: none " .  $options[ 'mobile_sub_menu_bg_color' ] ."; color: " .  $options[ 'mobile_sub_menu_color' ] ."; box-shadow: none; }". "\n";
			}
			if( ( $defaults[ 'mobile_hover_bg_color' ] != $options[ 'mobile_hover_bg_color' ] ) || ( $defaults[ 'mobile_hover_color' ] != $options[ 'mobile_hover_color' ] ) || ( $defaults[ 'mobile_sub_menu_bg_color' ] != $options[ 'mobile_sub_menu_bg_color' ] ) || ( $defaults[ 'mobile_sub_menu_color' ] != $options[ 'mobile_sub_menu_color' ] ) ) {
				$catchflames_inline_css	.=  ".sidr ul li ul li:hover>a, .sidr ul li ul li:hover>span, .sidr ul li ul li.active>a, .sidr ul li ul li.active>span, .sidr ul li ul li.sidr-class-active>a, .sidr ul li ul li.sidr-class-active>span { box-shadow: none; }". "\n";
			}
			// Mobile Menu Border Color
			if( $defaults[ 'mobile_border_color' ] != $options[ 'mobile_border_color' ] ) {
				$catchflames_inline_css	.=  ".sidr ul li { border-color: " .  $options[ 'mobile_border_color' ] ."; }". "\n";
			}

		// Typography (Font Family) Options
			if( $defaults[ 'body_font' ] != $options[ 'body_font' ] ) {
				$catchflames_inline_css	.=  "body, input, textarea { font-family: ". $fonts [ $options[ 'body_font' ] ] ."; }". "\n";
			}
			if( $defaults[ 'title_font' ] != $options[ 'title_font' ] ) {
				$catchflames_inline_css	.=  "#site-title a, #site-description { font-family: ". $fonts [ $options[ 'title_font' ] ] ."; }". "\n";
			}
			if( $defaults[ 'headings_font' ] != $options[ 'headings_font' ] ) {
				$catchflames_inline_css	.=  "h1, h2, h3, h4, h5, h6 { font-family: ". $fonts [ $options[ 'headings_font' ] ] ."; }". "\n";
			}
			if( $defaults[ 'content_font' ] != $options[ 'content_font' ] ) {
				$catchflames_inline_css	.=  ".entry-content, .entry-summary { font-family: ". $fonts [ $options[ 'content_font' ] ] ."; }". "\n";
			}

		// Typography (Font Size) Options
			$catchflames_font_size_css = '';	
			
			//Body Font Size
			if( $defaults['body_font_size'] != $options[ 'body_font_size' ] ) {
				$catchflames_font_size_css	.=  "body, input, textarea { font-size: ". $options[ 'body_font_size' ] . $options[ 'body_font_size_unit' ] ."; line-height: ". $options[ 'body_line_height' ] . $options[ 'body_line_height_unit' ] .";  }". "\n";
			} elseif( $defaults['body_line_height'] != $options[ 'body_line_height' ] ) {
				$catchflames_font_size_css	.=  "body, input, textarea { line-height: ". $options[ 'body_line_height' ] . $options[ 'body_line_height_unit' ] .";  }". "\n";
			}
			//Site Title Font Size
			if( $defaults['site_title_font_size'] != $options[ 'site_title_font_size' ] ) {
				$catchflames_font_size_css	.=  "#site-title { font-size: ". $options[ 'site_title_font_size' ] . $options[ 'site_title_font_size_unit' ] ."; line-height: ". $options[ 'site_title_line_height' ] . $options[ 'site_title_line_height_unit' ] .";  }". "\n";
			} elseif( $defaults['site_title_line_height'] != $options[ 'site_title_line_height' ] ) {
				$catchflames_font_size_css	.=  "#site-title  { line-height: ". $options[ 'site_title_line_height' ] . $options[ 'site_title_line_height_unit' ] .";  }". "\n";
			}
			//Site Description Font Size
			if( $defaults['site_description_font_size'] != $options[ 'site_description_font_size' ] ) {
				$catchflames_font_size_css	.=  "#site-description { font-size: ". $options[ 'site_description_font_size' ] . $options[ 'site_description_font_size_unit' ] ."; line-height: ". $options[ 'site_description_line_height' ] . $options[ 'site_description_line_height_unit' ] .";  }". "\n";
			} elseif( $defaults['site_description_line_height'] != $options[ 'site_description_line_height' ] ) {
				$catchflames_font_size_css	.=  "#site-description { line-height: ". $options[ 'site_description_line_height' ] . $options[ 'site_description_line_height_unit' ] .";  }". "\n";
			}
			//H1 Font Size
			if( $defaults['h1_font_size'] != $options[ 'h1_font_size' ] ) {
				$catchflames_font_size_css	.=  ".hentry h1, .no-sidebar .entry-title, .error404 .entry-title { font-size: ".  $options[ 'h1_font_size' ] . $options[ 'h1_font_size_unit' ] ."; line-height: ". $options[ 'headings_line_height' ] . $options[ 'headings_line_height_unit' ] .";  }". "\n";
			}
			//H2 Font Size
			if( $defaults['h2_font_size'] != $options[ 'h2_font_size' ] ) {
				$catchflames_font_size_css	.=  ".hentry h2 { font-size: ". $options[ 'h2_font_size' ] . $options[ 'h2_font_size_unit' ] ."; line-height: ". $options[ 'headings_line_height' ] . $options[ 'headings_line_height_unit' ] .";  }". "\n";
			}
			//H3 Font Size
			if( $defaults['h3_font_size'] != $options[ 'h3_font_size' ] ) {
				$catchflames_font_size_css	.=  ".hentry h3 { font-size: ". $options[ 'h3_font_size' ] . $options[ 'h3_font_size_unit' ] ."; line-height: ". $options[ 'headings_line_height' ] . $options[ 'headings_line_height_unit' ] .";  }". "\n";
			}
			//H4 Font Size
			if( $defaults['h4_font_size'] != $options[ 'h4_font_size' ] ) {
				$catchflames_font_size_css	.=  ".hentry h4 { font-size: ". $options[ 'h4_font_size' ] . $options[ 'h4_font_size_unit' ] ."; line-height: ". $options[ 'headings_line_height' ] . $options[ 'headings_line_height_unit' ] .";  }". "\n";
			}
			//Heading Line height
			if( $defaults['headings_line_height'] != $options[ 'headings_line_height' ] ) {
				$catchflames_font_size_css	.=  ".hentry h1, .hentry h2, .hentry h3, .hentry h4, .hentry h5, .hentry h6 { line-height: ". $options[ 'headings_line_height' ] . $options[ 'headings_line_height_unit' ] .";  }". "\n";
			}
			//Content Font Size
			if( $defaults[ 'content_font_size' ] != $options[ 'content_font_size' ] ) {
				$catchflames_font_size_css	.=  ".entry-content, .entry-summary { font-size: ". $options[ 'content_font_size' ] . $options[ 'content_font_size_unit' ] ."; line-height: ". $options[ 'content_line_height' ] . $options[ 'content_line_height_unit' ] .";  }". "\n";
			}

			if( '' != $catchflames_font_size_css ) {
				$catchflames_inline_css .=  "@media screen and (min-width: 961px) {". "\n" . $catchflames_font_size_css ."}". "\n";
			}

		//Disable Header
		if( !empty( $options[ 'disable_header_content' ] ) ) {
			$catchflames_inline_css	.=  "#header-content { padding: 0; clip: rect(1px 1px 1px 1px); /* IE7 */ clip: rect(1px, 1px, 1px, 1px); position: absolute; }" . "\n";
		}

		//Disable Header
		if( !empty( $options[ 'disable_header' ] ) ) {
			$catchflames_inline_css	.=  "#branding { clip: rect(1px 1px 1px 1px); /* IE7 */ clip: rect(1px, 1px, 1px, 1px); position: absolute; }" . "\n";
			$catchflames_inline_css	.=  "#header-content { padding: 0; }" . "\n";
		}

		//Custom CSS Option
		if( !empty( $options[ 'custom_css' ] ) ) {
			$catchflames_inline_css	.=  $options['custom_css'] . "\n";
		}

		if ( '' != $catchflames_inline_css ){
			echo '<!-- refreshing custom css cache -->' . "\n";
			
			$catchflames_inline_css = '
				<!-- '.get_bloginfo('name').' inline CSS Styles -->' . "\n" . '
					<style type="text/css" media="screen">' . "\n" . 
						$catchflames_inline_css . '
					</style>' . "\n";
		}

		set_transient( 'catchflames_inline_css', $catchflames_inline_css, 86940 );
	}
	echo $catchflames_inline_css;
}
add_action('wp_head', 'catchflames_inline_css');


/**
 * Sets the post excerpt length.
 *
 * To override this length in a child theme, remove the filter and add your own
 * function tied to the excerpt_length filter hook.
 */
function catchflames_excerpt_length( $length ) {
	global $catchflames_options_settings;
    $options = $catchflames_options_settings;

	if( empty( $options['excerpt_length'] ) )
		$options = catchflames_get_default_theme_options();

	$length = $options['excerpt_length'];
	return $length;
}
add_filter( 'excerpt_length', 'catchflames_excerpt_length' );


/**
 * Returns a "Continue Reading" link for excerpts
 */
function catchflames_continue_reading_link() {
	global $catchflames_options_settings;
    $options = $catchflames_options_settings;
	$more_tag_text = $options[ 'more_tag_text' ];

	return ' <a class="more-link" href="'. esc_url( get_permalink() ) . '">' . esc_attr( $more_tag_text ) . '</a>';
}


/**
 * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and catchflames_continue_reading_link().
 *
 * To override this in a child theme, remove the filter and add your own
 * function tied to the excerpt_more filter hook.
 */
function catchflames_auto_excerpt_more( $more ) {
	return catchflames_continue_reading_link();
}
add_filter( 'excerpt_more', 'catchflames_auto_excerpt_more' );


/**
 * Adds a pretty "Continue Reading" link to custom post excerpts.
 *
 * To override this link in a child theme, remove the filter and add your own
 * function tied to the get_the_excerpt filter hook.
 */
function catchflames_custom_excerpt_more( $output ) {
	if ( has_excerpt() && ! is_attachment() ) {
		$output .= catchflames_continue_reading_link();
	}
	return $output;
}
add_filter( 'get_the_excerpt', 'catchflames_custom_excerpt_more' );


if ( ! function_exists( 'catchflames_content_nav' ) ) :
/**
 * Display navigation to next/previous pages when applicable
 */
function catchflames_content_nav( $nav_id ) {
	global $wp_query;

	/**
	 * Check Jetpack Infinite Scroll
	 * if it's active then disable pagination
	 */
	if ( class_exists( 'Jetpack', false ) ) {
		$jetpack_active_modules = get_option('jetpack_active_modules');
		if ( $jetpack_active_modules && in_array( 'infinite-scroll', $jetpack_active_modules ) ) {
			return false;
		}
	}

	$nav_class = 'site-navigation paging-navigation';
	if ( is_single() )
		$nav_class = 'site-navigation post-navigation';

	if ( $wp_query->max_num_pages > 1 ) { ?>
        <nav role="navigation" id="<?php echo $nav_id; ?>">
        	<h3 class="assistive-text"><?php _e( 'Post navigation', 'catch-flames' ); ?></h3>
			<?php if ( function_exists('wp_pagenavi' ) )  {
                wp_pagenavi();
            }
            elseif ( function_exists('wp_page_numbers' ) ) {
                wp_page_numbers();
            }
            else { ?>
                <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'catch-flames' ) ); ?></div>
                <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'catch-flames' ) ); ?></div>
            <?php
            } ?>
        </nav><!-- #nav -->
	<?php
	}
}
endif; // catchflames_content_nav


/**
 * Return the URL for the first link found in the post content.
 *
 * @since Catch Flames Pro 1.0
 * @return string|bool URL or false when no link is present.
 */
function catchflames_url_grabber() {
	if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) )
		return false;

	return esc_url_raw( $matches[1] );
}


if ( ! function_exists( 'catchflames_footer_sidebar_class' ) ) :
/**
 * Count the number of footer sidebars to enable dynamic classes for the footer
 */
function catchflames_footer_sidebar_class() {
	$count = 0;

	if ( is_active_sidebar( 'sidebar-2' ) )
		$count++;

	if ( is_active_sidebar( 'sidebar-3' ) )
		$count++;

	if ( is_active_sidebar( 'sidebar-4' ) )
		$count++;

	if ( is_active_sidebar( 'sidebar-5' ) )
		$count++;

	$class = '';

	switch ( $count ) {
		case '1':
			$class = 'one';
			break;
		case '2':
			$class = 'two';
			break;
		case '3':
			$class = 'three';
			break;
		case '4':
			$class = 'four';
			break;
	}

	if ( $class )
		echo 'class="' . $class . '"';
}
endif; // catchflames_footer_sidebar_class


if ( ! function_exists( 'catchflames_comment' ) ) :
/**
 * Template for comments and pingbacks.
 *
 * To override this walker in a child theme without modifying the comments template
 * simply create your own catchflames_comment(), and that function will be used instead.
 *
 * Used as a callback by wp_list_comments() for displaying the comments.
 *
 * @since Catch Flames Pro 1.0
 */
function catchflames_comment( $comment, $args, $depth ) {
	$GLOBALS['comment'] = $comment;
	switch ( $comment->comment_type ) :
		case 'pingback' :
		case 'trackback' :
		// Display trackbacks differently than normal comments.
	?>
   	<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
		<p><?php _e( 'Pingback:', 'catch-flames' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'catch-flames' ), '<span class="edit-link">', '</span>' ); ?></p>
	<?php
			break;
		default :
		// Proceed with normal comments.
		global $post;
	?>
	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
		<article id="comment-<?php comment_ID(); ?>" class="comment">
			<header class="comment-meta comment-author vcard">
				<?php
					echo get_avatar( $comment, 44 );
					printf( '<cite><b class="fn">%1$s</b> %2$s</cite>',
						get_comment_author_link(),
						// If current post author is also comment author, make it known visually.
						( $comment->user_id === $post->post_author ) ? '<span>' . __( 'Post author', 'catch-flames' ) . '</span>' : ''
					);
					printf( '<a href="%1$s"><time 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', 'catch-flames' ), get_comment_date(), get_comment_time() )
					);
				?>
			</header><!-- .comment-meta -->

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

			<section class="comment-content comment">
				<?php comment_text(); ?>
				<?php edit_comment_link( __( 'Edit', 'catch-flames' ), '<p class="edit-link">', '</p>' ); ?>
			</section><!-- .comment-content -->

			<div class="reply">
				<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'catch-flames' ), 'after' => ' <span>&darr;</span>', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
			</div><!-- .reply -->
		</article><!-- #comment-## -->
	<?php
		break;
	endswitch; // end comment_type check
}
endif; //catchflames_comment


if ( ! function_exists( 'catchflames_comment_defaults' ) ) :
/**
 * Modify Comment Form Defaults
 *
 * @uses comment_form_defaults filter
 * @since Catch Flames Pro 1.0
 */
function catchflames_comment_defaults( $defaults ) {
	// get data value from theme options
	global $catchflames_options_settings;
    $options = $catchflames_options_settings;
	$disablenote = $options[ 'commenting_disable_notes' ];

 	if ( $disablenote == '1' ) :
		$defaults['comment_notes_after'] = '';
	endif;

	return $defaults;

}
endif; //catchflames_comment_defaults

add_filter( 'comment_form_defaults', 'catchflames_comment_defaults' );


if ( ! function_exists( 'catchflames_comment_form_fields' ) ) :
/**
 * Modify Comment Form Fields
 *
 * @uses comment_form_default_fields filter
 * @since Catch Flames Pro 1.0
 */
function catchflames_comment_form_fields( $fields ) {
	// get data value from theme options
	global $catchflames_options_settings;
    $options = $catchflames_options_settings;
	$disableurl = $options[ 'commenting_disable_url' ];

	if ( isset( $fields['url'] ) && $disableurl == '1' ) {
		unset( $fields['url'] );
	}

	return $fields;

}
endif; //catchflames_comment_form_fields

add_filter( 'comment_form_default_fields', 'catchflames_comment_form_fields' );


if ( ! function_exists( 'catchflames_posted_on' ) ) :
/**
 * Prints HTML with meta information for the current post-date/time and author.
 * Create your own catchflames_posted_on to override in a child theme
 *
 * @since Catch Flames Pro 1.0
 */
function catchflames_posted_on() {
	/* Check Author URL to Support Google Authorship
	*
	* By deault the author will link to author archieve page
	* But if the author have added their Website in Profile page then it will link to author website
	*/
	if ( get_the_author_meta( 'user_url' ) != '' ) {
		$catchflames_author_url = 	esc_url( get_the_author_meta( 'user_url' ) );
	}
	else {
		$catchflames_author_url = esc_url( get_author_posts_url( get_the_author_meta( "ID" ) ) );
	}
	printf( __( '<span class="sep">Posted on </span><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date updated" datetime="%3$s" pubdate>%4$s</time></a><span class="by-author"> <span class="sep"> by </span> <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'catch-flames' ),
		esc_url( get_permalink() ),
		esc_attr( get_the_time() ),
		esc_attr( get_the_date( 'c' ) ),
		esc_html( get_the_date() ),
		$catchflames_author_url,
		esc_attr( sprintf( __( 'View all posts by %s', 'catch-flames' ), get_the_author() ) ),
		get_the_author()
	);
}
endif; //catchflames_posted_on


if ( ! function_exists( 'catchflames_body_classes' ) ) :
/**
 * Adds two classes to the array of body classes.
 * The first is if the site has only had one author with published posts.
 * The second is if a singular post being displayed
 *
 * @since Catch Flames Pro 1.0
 */
function catchflames_body_classes( $classes ) {
	//Getting Ready to load data from Theme Options Panel
	global $post, $wp_query, $catchflames_options_settings;
   	$options = $catchflames_options_settings;
	$themeoption_layout = $options['sidebar_layout'];
	$header_menu = $options['disable_header_menu'];

	// Front page displays in Reading Settings
	$page_on_front = get_option('page_on_front') ;
	$page_for_posts = get_option('page_for_posts');

	// Get Page ID outside Loop
	$page_id = $wp_query->get_queried_object_id();


	// Check WooCommerce Sidebar
	if ( !is_active_sidebar( 'catchflames_woocommerce_sidebar' ) && ( class_exists( 'Woocommerce' ) && is_woocommerce() ) ) :
		$classes[] = 'woocommerce-nosidebar';
	endif;

	// Check Fixed Header Top and Header Logo
	if ( !empty( $options['enable_header_top'] ) ) :
		$classes[] = 'has-header-top';
		if ( empty( $options['disable_top_menu_logo'] ) ) {
			$classes[] = 'menu-logo';
		}
		if ( !has_nav_menu( 'top' ) ) {
			$classes[] = 'no-top-menu';
		}
		if ( !empty( $options['disable_social'] ) ) {
			$classes[] = 'no-top-social';
		}
		if ( !empty( $options['disable_search'] ) ) {
			$classes[] = 'no-top-search';
		}
	endif;

	// Check Disable Header
	if ( !empty( $options['disable_header'] ) ) :
		$classes[] = 'disable-header';
	endif;

	// Check Mobile Header Menu
	if ( ( has_nav_menu( 'primary' ) &&  has_nav_menu( 'secondary' ) ) || ( has_nav_menu( 'primary' ) &&  has_nav_menu( 'third' ) ) || ( has_nav_menu( 'secondary' ) &&  has_nav_menu( 'third' ) ) ) :
		$classes[] = 'has-header-left-menu has-header-right-menu';
	elseif ( has_nav_menu( 'primary' ) || has_nav_menu( 'secondary' ) || has_nav_menu( 'third' ) ) :
		$classes[] = 'has-header-left-menu';
	elseif ( empty ( $header_menu ) ) :
		$classes[] = 'has-header-left-menu';
	endif;

	// Blog Page setting in Reading Settings
	if ( $page_id == $page_for_posts ) {
		$layout = get_post_meta( $page_for_posts,'catchflames-sidebarlayout', true );
	}	
	// Front Page setting in Reading Settings
	elseif ( $page_id == $page_on_front ) {
		$layout = get_post_meta( $page_on_front,'catchflames-sidebarlayout', true );
	}	
	// Settings for page/post/attachment
	elseif ( is_singular() ) {
		if ( is_attachment() ) { 
			$parent = $post->post_parent;
			$layout = get_post_meta( $parent, 'catchflames-sidebarlayout', true );
		} else {
			$layout = get_post_meta( $post->ID, 'catchflames-sidebarlayout', true ); 
		}
	}
	else {
		$layout = 'default';	
	}

	//check empty and load default
	if ( empty( $layout ) ) {
		$layout = 'default';	
	}	

	if ( $layout == 'three-columns-sidebar' || ( $layout=='default' && $themeoption_layout == 'three-columns-sidebar' ) ) {
		$classes[] = 'three-columns three-columns-sidebar';
	}
	elseif ( $layout == 'three-columns-equal' || ( $layout=='default' && $themeoption_layout == 'three-columns-equal' ) ) {
		$classes[] = 'three-columns equal';
	}
	elseif ( $layout == 'three-columns' || ( $layout=='default' && $themeoption_layout == 'three-columns' ) ) {
		$classes[] = 'three-columns';
	}
	elseif ( $layout == 'no-sidebar' || ( $layout=='default' && $themeoption_layout == 'no-sidebar' ) ) {
		$classes[] = 'no-sidebar';
	}
	elseif ( $layout == 'no-sidebar-one-column' || ( $layout=='default' && $themeoption_layout == 'no-sidebar-one-column' ) ) {
		$classes[] = 'no-sidebar one-column';
	}
	elseif ( $layout == 'no-sidebar-full-width' || ( $layout=='default' && $themeoption_layout == 'no-sidebar-full-width' ) ) {
		$classes[] = 'no-sidebar full-width';
	}
	elseif ( $layout == 'left-sidebar' || ( $layout=='default' && $themeoption_layout == 'left-sidebar' ) ) {
		$classes[] = 'left-sidebar two-columns';
	}
	elseif ( $layout == 'right-sidebar' || ( $layout=='default' && $themeoption_layout == 'right-sidebar' ) ) {
		$classes[] = 'right-sidebar two-columns';
	}

	return $classes;
}
endif; //catchflames_body_classes

add_filter( 'body_class', 'catchflames_body_classes' );


/**
 * Adds in post and Page ID when viewing lists of posts and pages
 * This will help the admin to add the post ID in featured slider
 *
 * @param mixed $post_columns
 * @return post columns
 */
function catchflames_post_id_column( $post_columns ) {
	$beginning = array_slice( $post_columns, 0 ,1 );
	$beginning[ 'postid' ] = __( 'ID', 'catch-flames'  );
	$ending = array_slice( $post_columns, 1 );
	$post_columns = array_merge( $beginning, $ending );
	return $post_columns;
}
add_filter( 'manage_posts_columns', 'catchflames_post_id_column' );
add_filter( 'manage_pages_columns', 'catchflames_post_id_column' );

function catchflames_posts_id_column( $col, $val ) {
	if( $col == 'postid' ) echo $val;
}
add_action( 'manage_posts_custom_column', 'catchflames_posts_id_column', 10, 2 );
add_action( 'manage_pages_custom_column', 'catchflames_posts_id_column', 10, 2 );

function catchflames_posts_id_column_css() {
	echo '<style type="text/css">#postid { width: 40px; }</style>';
}
add_action( 'admin_head-edit.php', 'catchflames_posts_id_column_css' );


/**
 * Alter the query for the main loop in home page
 * @uses pre_get_posts hook
 */
function catchflames_alter_home( $query ){
	global $post, $catchflames_options_settings;
    $options = $catchflames_options_settings;
	$cats = $options[ 'front_page_category' ];

    if ( $options[ 'exclude_slider_post'] != "0" && !empty( $options[ 'featured_slider' ] ) ) {
		if( $query->is_main_query() && $query->is_home() ) {
			$query->query_vars['post__not_in'] = $options[ 'featured_slider' ];
		}
	}

	if ( !in_array( '0', $cats ) ) {
		if( $query->is_main_query() && $query->is_home() ) {
			$query->query_vars['category__in'] = $options[ 'front_page_category' ];
		}
	}

}
add_action( 'pre_get_posts','catchflames_alter_home' );


/**
 * Remove div from wp_page_menu() and replace with ul.
 * @uses wp_page_menu filter
 */
function catchflames_wp_page_menu( $page_markup ) {
    preg_match('/^<div class=\"([a-z0-9-_]+)\">/i', $page_markup, $matches);
        $divclass = $matches[1];
        $replace = array('<div class="'.$divclass.'">', '</div>');
        $new_markup = str_replace($replace, '', $page_markup);
        $new_markup = preg_replace('/^<ul>/i', '<ul class="'.$divclass.'">', $new_markup);
        return $new_markup; }

add_filter( 'wp_page_menu', 'catchflames_wp_page_menu' );


/**
 * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
 */
function catchflames_page_menu_args( $args ) {
	$args['show_home'] = true;
	return $args;
}
add_filter( 'wp_page_menu_args', 'catchflames_page_menu_args' );


/**
 * Replacing classed in default wp_page_menu
 *
 * REPLACE "current_page_item" WITH CLASS "current-menu-item"
 * REPLACE "current_page_ancestor" WITH CLASS "current-menu-ancestor"
 */
function catchflames_current_to_active($text){
	$replace = array(
		// List of classes to replace with "active"
		'current_page_item' => 'current-menu-item',
		'current_page_ancestor' => 'current-menu-ancestor',
	);
	$text = str_replace(array_keys($replace), $replace, $text);
		return $text;
	}
add_filter( 'wp_page_menu', 'catchflames_current_to_active' );


/**
 * Redirect WordPress Feeds To FeedBurner
 */
function catchflames_rss_redirect() {
	global $catchflames_options_settings;
    $options = $catchflames_options_settings;

    if ($options['feed_url']) {
		$url = 'Location: '.$options['feed_url'];
		if ( is_feed() && !preg_match('/feedburner|feedvalidator/i', $_SERVER['HTTP_USER_AGENT']))
		{
			header($url);
			header('HTTP/1.1 302 Temporary Redirect');
		}
	}
}
add_action('template_redirect', 'catchflames_rss_redirect');


if ( ! function_exists( 'catchflames_social_networks' ) ) :
/**
 * This function for social links display
 *
 * @fetch links through Theme Options
 * @use in widget
 * @social links, Facebook, Twitter and RSS
  */
function catchflames_social_networks() {
	//delete_transient( 'catchflames_social_networks' );

	// get the data value from theme options
	global $catchflames_options_settings;
	$options = $catchflames_options_settings;

    $elements = array();

	$elements = array( 	$options[ 'social_facebook' ],
						$options[ 'social_twitter' ],
						$options[ 'social_googleplus' ],
						$options[ 'social_linkedin' ],
						$options[ 'social_pinterest' ],
						$options[ 'social_youtube' ],
						$options[ 'social_vimeo' ],
						$options[ 'social_aim' ],
						$options[ 'social_myspace' ],
						$options[ 'social_flickr' ],
						$options[ 'social_tumblr' ],
						$options[ 'social_deviantart' ],
						$options[ 'social_dribbble' ],
						$options[ 'social_myspace' ],
						$options[ 'social_wordpress' ],
						$options[ 'social_rss' ],
						$options[ 'social_slideshare' ],
						$options[ 'social_instagram' ],
						$options[ 'social_skype' ],
						$options[ 'social_soundcloud' ],
						$options[ 'social_email' ],
						$options[ 'social_contact' ],
						$options[ 'social_xing' ],
						$options[ 'enable_specificfeeds' ]
					);
	$flag = 0;
	if( !empty( $elements ) ) {
		foreach( $elements as $option) {
			if( !empty( $option ) ) {
				$flag = 1;
			}
			else {
				$flag = 0;
			}
			if( $flag == 1 ) {
				break;
			}
		}
	}

	if ( ( !$catchflames_social_networks = get_transient( 'catchflames_social_networks' ) ) && ( $flag == 1 ) )  {
		echo '<!-- refreshing cache -->';

		$catchflames_social_networks .='
		<div class="social-profile"><ul>';
			//facebook
			if ( !empty( $options[ 'social_facebook' ] ) ) {
				$catchflames_social_networks .=
					'<li class="facebook"><a href="'.esc_url( $options[ 'social_facebook' ] ).'" title="'. esc_attr__( 'Facebook', 'catch-flames' ) .'" target="_blank">'.esc_attr__( 'Facebook', 'catch-flames' ).'</a></li>';
			}
			//Twitter
			if ( !empty( $options[ 'social_twitter' ] ) ) {
				$catchflames_social_networks .=
					'<li class="twitter"><a href="'.esc_url( $options[ 'social_twitter' ] ).'" title="'. esc_attr__( 'Twitter', 'catch-flames' ) .'" target="_blank">'.esc_attr__( 'Twitter', 'catch-flames' ).'</a></li>';
			}
			//Google+
			if ( !empty( $options[ 'social_googleplus' ] ) ) {
				$catchflames_social_networks .=
					'<li class="google-plus"><a href="'.esc_url( $options[ 'social_googleplus' ] ).'" title="'. esc_attr__( 'Google+', 'catch-flames' ) .'" target="_blank">'.esc_attr__( 'Google+', 'catch-flames' ).'</a></li>';
			}
			//Linkedin
			if ( !empty( $options[ 'social_linkedin' ] ) ) {
				$catchflames_social_networks .=
					'<li class="linkedin"><a href="'.esc_url( $options[ 'social_linkedin' ] ).'" title="'. esc_attr__( 'Linkedin', 'catch-flames' ) .'" target="_blank">'.esc_attr__( 'Linkedin', 'catch-flames' ).'</a></li>';
			}
			//Pinterest
			if ( !empty( $options[ 'social_pinterest' ] ) ) {
				$catchflames_social_networks .=
					'<li class="pinterest"><a href="'.esc_url( $options[ 'social_pinterest' ] ).'" title="'. esc_attr__( 'Pinterest', 'catch-flames' ) .'" target="_blank">'.esc_attr__( 'Pinterest', 'catch-flames' ).'</a></li>';
			}
			//Youtube
			if ( !empty( $options[ 'social_youtube' ] ) ) {
				$catchflames_social_networks .=
					'<li class="you-tube"><a href="'.esc_url( $options[ 'social_youtube' ] ).'" title="'. esc_attr__( 'YouTube', 'catch-flames' ) .'" target="_blank">'.esc_attr__( 'YouTube', 'catch-flames' ).'</a></li>';
			}
			//Vimeo
			if ( !empty( $options[ 'social_vimeo' ] ) ) {
				$catchflames_social_networks .=
					'<li class="viemo"><a href="'.esc_url( $options[ 'social_vimeo' ] ).'" title="'. esc_attr__( 'Vimeo', 'catch-flames' ) .'" target="_blank">'.esc_attr__( 'Vimeo', 'catch-flames' ).'</a></li>';
			}
			//Slideshare
			if ( !empty( $options[ 'social_aim' ] ) ) {
				$catchflames_social_networks .=
					'<li class="aim"><a href="'.esc_url( $options[ 'social_aim' ] ).'" title="'. esc_attr__( 'AIM', 'catch-flames' ) .'" target="_blank">'.esc_attr__( 'AIM', 'catch-flames' ).'</a></li>';
			}
			//MySpace
			if ( !empty( $options[ 'social_myspace' ] ) ) {
				$catchflames_social_networks .=
					'<li class="myspace"><a href="'.esc_url( $options[ 'social_myspace' ] ).'" title="'. esc_attr__( 'MySpace', 'catch-flames' ) .'" target="_blank">'.esc_attr__( 'MySpace', 'catch-flames' ).'</a></li>';
			}
			//Flickr
			if ( !empty( $options[ 'social_flickr' ] ) ) {
				$catchflames_social_networks .=
					'<li class="flickr"><a href="'.esc_url( $options[ 'social_flickr' ] ).'" title="'. esc_attr__( 'Flickr', 'catch-flames' ) .'" target="_blank">'.esc_attr__( 'Flickr', 'catch-flames' ).'</a></li>';
			}
			//Tumblr
			if ( !empty( $options[ 'social_tumblr' ] ) ) {
				$catchflames_social_networks .=
					'<li class="tumblr"><a href="'.esc_url( $options[ 'social_tumblr' ] ).'" title="'. esc_attr__( 'Tumblr', 'catch-flames' ) .'" target="_blank">'.esc_attr__( 'Tumblr', 'catch-flames' ).'</a></li>';
			}
			//deviantART
			if ( !empty( $options[ 'social_deviantart' ] ) ) {
				$catchflames_social_networks .=
					'<li class="deviantart"><a href="'.esc_url( $options[ 'social_deviantart' ] ).'" title="'. esc_attr__( 'deviantART', 'catch-flames' ) .'" target="_blank">'.esc_attr__( 'deviantART', 'catch-flames' ).'</a></li>';
			}
			//Dribbble
			if ( !empty( $options[ 'social_dribbble' ] ) ) {
				$catchflames_social_networks .=
					'<li class="dribbble"><a href="'.esc_url( $options[ 'social_dribbble' ] ).'" title="'. esc_attr__( 'Dribbble', 'catch-flames' ) .'" target="_blank">'.esc_attr__( 'Dribbble', 'catch-flames' ).'</a></li>';
			}
			//WordPress
			if ( !empty( $options[ 'social_wordpress' ] ) ) {
				$catchflames_social_networks .=
					'<li class="wordpress"><a href="'.esc_url( $options[ 'social_wordpress' ] ).'" title="'. esc_attr__( 'WordPress', 'catch-flames' ) .'" target="_blank">'.esc_attr__( 'WordPress', 'catch-flames' ).'</a></li>';
			}
			//RSS
			if ( !empty( $options[ 'social_rss' ] ) ) {
				$catchflames_social_networks .=
					'<li class="rss"><a href="'.esc_url( $options[ 'social_rss' ] ).'" title="'. esc_attr__( 'RSS', 'catch-flames' ) .'" target="_blank">'.esc_attr__( 'RSS', 'catch-flames' ).'</a></li>';
			}
			//Slideshare
			if ( !empty( $options[ 'social_slideshare' ] ) ) {
				$catchflames_social_networks .=
					'<li class="slideshare"><a href="'.esc_url( $options[ 'social_slideshare' ] ).'" title="'. esc_attr__( 'Slideshare', 'catch-flames' ) .'" target="_blank">'.esc_attr__( 'Slideshare', 'catch-flames' ).'</a></li>';
			}
			//Instagram
			if ( !empty( $options[ 'social_instagram' ] ) ) {
				$catchflames_social_networks .=
					'<li class="instagram"><a href="'.esc_url( $options[ 'social_instagram' ] ).'" title="'. esc_attr__( 'Instagram', 'catch-flames' ) .'" target="_blank">'.esc_attr__( 'Instagram', 'catch-flames' ).'</a></li>';
			}
			//Skype
			if ( !empty( $options[ 'social_skype' ] ) ) {
				$catchflames_social_networks .=
					'<li class="skype"><a href="'.esc_url( $options[ 'social_skype' ] ).'" title="'. esc_attr__( 'Skype', 'catch-flames' ) .'" target="_blank">'.esc_attr__( 'Skype', 'catch-flames' ).'</a></li>';
			}
			//Soundcloud
			if ( !empty( $options[ 'social_soundcloud' ] ) ) {
				$catchflames_social_networks .=
					'<li class="soundcloud"><a href="'.esc_url( $options[ 'social_soundcloud' ] ).'" title="'. esc_attr__( 'Soundcloud', 'catch-flames' ) .'" target="_blank">'. esc_attr__( 'Soundcloud', 'catch-flames' ) .'</a></li>';
			}
			//Email
			if ( !empty( $options[ 'social_email' ] )  && is_email( $options[ 'social_email' ] ) ) {
				$catchflames_social_networks .=
					'<li class="email"><a href="mailto:'.sanitize_email( $options[ 'social_email' ] ).'" title="'. esc_attr__( 'Email', 'catch-flames' ) .'" target="_blank">'. esc_attr__( 'Email', 'catch-flames' ) .'</a></li>';
			}
			//Contact
			if ( !empty( $options[ 'social_contact' ] ) ) {
				$catchflames_social_networks .=
					'<li class="contactus"><a href="'.esc_url( $options[ 'social_contact' ] ).'" title="'. esc_attr__( 'Contact', 'catch-flames' ) .'">'.esc_attr__( 'Contact', 'catch-flames' ).'</a></li>';
			}
			//Xing
			if ( !empty( $options[ 'social_xing' ] ) ) {
				$catchflames_social_networks .=
					'<li class="xing"><a href="'.esc_url( $options[ 'social_xing' ] ).'" title="'. esc_attr__( 'Xing', 'catch-flames' ) .'" target="_blank">'.esc_attr__( 'Xing', 'catch-flames' ).'</a></li>';
			}
			//SpecificFeeds
			if ( !empty( $options[ 'enable_specificfeeds' ] ) ) {
				$catchflames_social_networks .=
					'<li class="specificfeeds"><a href="'.esc_url( 'http://www.specificfeeds.com/follow' ).'" title="'. esc_attr__( 'SpecificFeeds', 'catch-flames' ) .'" target="_blank">'. esc_attr__( 'SpecificFeeds', 'catch-flames' ) .'</a></li>';
			}
			$catchflames_social_networks .='
		</ul></div>';

		set_transient( 'catchflames_social_networks', $catchflames_social_networks, 86940 );
	}
	echo $catchflames_social_networks;
}
endif; //catchflames_social_networks


if ( ! function_exists( 'catchflames_post_featured_image' ) ) :
/**
 * Template for Featured Image in Content
 *
 * To override this in a child theme
 * simply create your own catchflames_post_featured_image(), and that function will be used instead.
 *
 * @since Catch Flames Pro 1.0
 */
function catchflames_post_featured_image() {
	// Getting data from Theme Options
	global $post, $wp_query, $catchflames_options_settings;
	$options = $catchflames_options_settings;
	$contentlayout = $options['content_layout'];
	$sidebarlayout = $options['sidebar_layout'];

	$imagesize = '';

	if ( $contentlayout == 'full' ) :
		return false;
	elseif ( $contentlayout == 'excerpt' ) :
		if ( $sidebarlayout == 'three-columns' || $sidebarlayout == 'three-columns-sidebar' || $sidebarlayout == 'three-columns-equal' ) :
			$imagesize = 'featured-three';
		else :
			$imagesize = 'featured';
		endif;
	elseif ( $contentlayout == 'excerpt-full' ) :
		$imagesize = 'full';
	elseif ( $contentlayout == 'excerpt-small' ) :
		$imagesize = 'featured-small';
	elseif ( $contentlayout == 'excerpt-square' ) :
		$imagesize = 'featured-square';
	elseif ( $contentlayout == 'excerpt-tall' ) :
		$imagesize = 'featured-tall';
	endif;

    if ( has_post_thumbnail() ) : ?>
        <figure class="featured-image">
            <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'catch-flames' ), the_title_attribute( 'echo=0' ) ) ); ?>">
                <?php the_post_thumbnail( $imagesize ); ?>
            </a>
        </figure>
   	<?php endif;

}
endif; //catchflames_post_featured_image


if ( ! function_exists( 'catchflames_post_classes' ) ) :
/**
 * Adds classes to the array of post classes.
 *
 * @since Catch Flames Pro 1.0
 */
function catchflames_post_classes( $classes ) {
	//Getting Ready to load data from Theme Options Panel
	global $post, $wp_query, $catchflames_options_settings;
   	$options = $catchflames_options_settings;
	$contentlayout = $options['content_layout'];

	if ( is_archive() || is_home() ) {
		if ( $contentlayout == 'excerpt-small' ) :
			$classes[] = 'image-left image-featured';
		elseif ( $contentlayout == 'excerpt-square' ) :
			$classes[] = 'image-square';
		elseif ( $contentlayout == 'excerpt-tall' ) :
			$classes[] = 'image-tall';
		elseif ( $contentlayout == 'excerpt-full' ) :
			$classes[] = 'image-full-width image-full';
		elseif ( $contentlayout == 'excerpt' ) :
			$classes[] = 'image-full-width image-featured';
		endif;
	}

	return $classes;
}
endif; //catchflames_post_classes

add_filter( 'post_class', 'catchflames_post_classes' );

/**
 * Site Verification  and Webmaster Tools
 *
 * If user sets the code we're going to display meta verification
 * @get the data value from theme options
 * @uses wp_head action to add the code in the header
 * @uses set_transient and delete_transient API for cache
 */
function catchflames_site_verification() {
	//delete_transient( 'catchflames_site_verification' );

	if ( ( !$catchflames_site_verification = get_transient( 'catchflames_site_verification' ) ) )  {

		// get the data value from theme options
		global $catchflames_options_settings;
		$options = $catchflames_options_settings;
		echo '<!-- refreshing cache -->';

		$catchflames_site_verification = '';
		//google
		if ( !empty( $options['google_verification'] ) ) {
			$catchflames_site_verification .= '<meta name="google-site-verification" content="' .  $options['google_verification'] . '" />' . "\n";
		}
		//bing
		if ( !empty( $options['bing_verification'] ) ) {
			$catchflames_site_verification .= '<meta name="msvalidate.01" content="' .  $options['bing_verification']  . '" />' . "\n";
		}
		//yahoo
		 if ( !empty( $options['yahoo_verification'] ) ) {
			$catchflames_site_verification .= '<meta name="y_key" content="' .  $options['yahoo_verification']  . '" />' . "\n";
		}
		//site stats, analytics header code
		if ( !empty( $options['analytic_header'] ) ) {
			$catchflames_site_verification .=  $options[ 'analytic_header' ] ;
		}

		set_transient( 'catchflames_site_verification', $catchflames_site_verification, 86940 );
	}
	echo $catchflames_site_verification;
}
add_action('wp_head', 'catchflames_site_verification');


/**
 * This function loads the Footer Code such as Add this code from the Theme Option
 *
 * @get the data value from theme options
 * @load on the footer ONLY
 * @uses wp_footer action to add the code in the footer
 * @uses set_transient and delete_transient
 */
function catchflames_footercode() {
	//delete_transient( 'catchflames_footercode' );

	if ( ( !$catchflames_footercode = get_transient( 'catchflames_footercode' ) ) ) {

		// get the data value from theme options
		global $catchflames_options_settings;
   	 	$options = $catchflames_options_settings;
		echo '<!-- refreshing cache -->';

		//site stats, analytics header code
		if ( !empty( $options['analytic_footer'] ) ) {
			$catchflames_footercode =  $options[ 'analytic_footer' ] ;
		}

		set_transient( 'catchflames_footercode', $catchflames_footercode, 86940 );
	}
	echo $catchflames_footercode;
}
add_action('wp_footer', 'catchflames_footercode');


/**
 * Get the Web Clip Icon Image from theme options
 *
 * @uses web_clip and remove_web_clip
 * @get the data value of image from theme options
 * @display favicon
 *
 * @uses default Web Click Icon if web_clip field on theme options is empty
 *
 * @uses set_transient and delete_transient
 */
function catchflames_web_clip() {
	//delete_transient( 'catchflames_web_clip' );

	if( ( !$catchflames_web_clip = get_transient( 'catchflames_web_clip' ) ) ) {

		global $catchflames_options_settings;
        $options = $catchflames_options_settings;

		echo '<!-- refreshing cache -->';
		if ( $options[ 'remove_web_clip' ] == "0" ) :
			// if not empty fav_icon on theme options
			if ( !empty( $options[ 'web_clip' ] ) ) :
				$catchflames_web_clip = '<link rel="apple-touch-icon-precomposed" href="'.esc_url( $options[ 'web_clip' ] ).'" />';
			else:
				// if empty fav_icon on theme options, display default fav icon
				$catchflames_web_clip = '<link rel="apple-touch-icon-precomposed" href="'. get_template_directory_uri() .'/images/apple-touch-icon.png" />';
			endif;
		endif;

		set_transient( 'catchflames_web_clip', $catchflames_web_clip, 86940 );
	}
	echo $catchflames_web_clip ;
} // catchflames_web_clip

//Load WebClip Icon in Header Section
add_action('wp_head', 'catchflames_web_clip');

/**
 * Third Sidebar
 *
 * @Hooked in catchflames_before_primary
 * @since Catch Flames Pro 1.0
 */

function catchflames_third_sidebar() {
	get_sidebar( 'third' );
}
add_action( 'catchflames_after_contentsidebarwrap', 'catchflames_third_sidebar', 10 );


/**
 * Footer Sidebar
 *
 * @Hooked in catchflames_footer
 * @since Catch Flames Pro 1.0
 */
function catchflames_footer_sidebar() {
	get_sidebar( 'footer' );
}
add_action( 'catchflames_footer', 'catchflames_footer_sidebar', 10 );


/**
 * Footer Site Generator Open
 *
 * @Hooked in catchflames_site_generator
 * @since Catch Flames Pro 1.0
 */
function catchflames_site_generator_open() {
	echo '<div id="site-generator"><div class="wrapper">';
}
add_action( 'catchflames_site_generator', 'catchflames_site_generator_open', 10 );


/**
 * Footer Social Icons
 *
 * @Hooked in catchflames_site_generator
 * @since Catch Flames Pro 1.0
 */
function catchflames_footer_social() {
	global $catchflames_options_settings;
	$options = $catchflames_options_settings;

	echo '<!-- refreshing cache -->';
	if ( !empty( $options[ 'disable_footer_social' ] ) ) :
		return catchflames_social_networks();
	endif;
}
add_action( 'catchflames_site_generator', 'catchflames_footer_social', 20 );


/**
 * Footer Content
 *
 * @Hooked in catchflames_site_generator
 * @since Catch Flames Pro 1.0
 */
function catchflames_footer_content() {
	//delete_transient( 'catchflames_footer_content' );

	if ( ( !$catchflames_footer_content = get_transient( 'catchflames_footer_content' ) ) ) {
		echo '<!-- refreshing cache -->';

		// get the data value from theme options
		global $catchflames_options_settings;
   	 	$options = $catchflames_options_settings;       

        $search = array( '[the-year]', '[site-link]', '[wp-link]', '[theme-link]' );

        $replace = array( catchflames_the_year(), catchflames_site_link(), catchflames_wp_link(), catchflames_theme_link() );

        $options[ 'footer_code' ] = str_replace( $search, $replace, $options[ 'footer_code' ] );

        $catchflames_footer_content = $options[ 'footer_code' ];

    	set_transient( 'catchflames_footer_content', $catchflames_footer_content, 86940 );
    }
	echo do_shortcode( $catchflames_footer_content );
}
add_action( 'catchflames_site_generator', 'catchflames_footer_content', 30 );


/**
 * Footer Site Generator Close
 *
 * @Hooked in catchflames_site_generator
 * @since Catch Flames Pro 1.0
 */
function catchflames_site_generator_close() {
	echo '</div><!-- .wrapper --></div><!-- #site-generator -->';
}
add_action( 'catchflames_site_generator', 'catchflames_site_generator_close', 100 );


/**
 * This function loads Scroll Up Navigation
 *
 * @uses catchflames_after action
 */
function catchflames_scrollup() {
// get the data value from theme options
		global $catchflames_options_settings;
			$options = $catchflames_options_settings;

		if ( empty( $options['disable_scrollup'] ) ) {
		echo '<a href="#page" id="scrollup"></a>';
		}
}
add_action( 'catchflames_after', 'catchflames_scrollup', 10 );