<?php

// Exit if accessed directly
if ( !defined('ABSPATH')) exit;

/**
 * Theme Styles
 *
 * @package WordPress
 * @subpackage TDFramework
 * @since framework 1.0
 */
	define('BASE_FONT_SIZE', 12);

	// Fonts that need to be loaded through the Google Fonts API
	global $theme_load_fonts;
	$theme_load_fonts = array();

	// Fonts
	$fonts = array(
		'font_menu' => array('#theme-menu-main', '#menu-footer', '#top-widget-container'),
		'font_heading' => array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'),
		'font_paragraph' => array('body'),
	);

	// Font sizes
	$fontsizes = array(
		'font_size_heading1' => array('h1'),
		'font_size_heading2' => array('h2'),
		'font_size_heading3' => array('h3'),
		'font_size_heading4' => array('h4'),
		'font_size_heading5' => array('h5'),
		'font_size_heading6' => array('h6'),

		'font_size_mainmenu'          => array('#theme-menu-main > li a'),
		'font_size_mainmenu_sub'      => array('#theme-menu-main > li li a'),
		'font_size_footermenu'        => array('#menu-footer a'),

		'font_size_other_footer'      => array('#footer'),
		'font_size_other_paragraph'   => array('body'),
		'font_size_sidebar_header'    => array('.sidebar .widget-title'),
		'font_size_other_copyright'   => array('#footer .copyright', '#footer .powered'),
	);

	// Text colors
	$colors = array(

		// Heading Titles
		'color_heading1' => array('.theme-content h1'),
		'color_heading2' => array('.theme-content h2'),
		'color_heading3' => array('.theme-content h3'),
		'color_heading4' => array('.theme-content h4'),
		'color_heading5' => array('.theme-content h5'),
		'color_heading6' => array('.theme-content h6'),

		// Menu
		'color_menu_text' => array(
			'#theme-menu-main > li > a',
		),
		'color_menu_text_hover' => array(
			'#theme-menu-main > li:hover > a',
			'#theme-menu-main > li.current-menu-item:hover > a',
		),
		'color_submenu_text' => array(
			'#theme-menu-main li li > a',
		),
		'color_submenu_text_hover' => array(
			'#theme-menu-main li li > a:hover',
		),

		// Breadcrumb
		'color_breadcrumb_text' => array(
			'.theme-breadcrumbs',
			'.theme-breadcrumbs a',
		),
		'color_breadcrumb_text_hover' => array(
			'.theme-breadcrumbs a:hover',
		),

		//Footer
		'color_footer_text' => array(
			'#footer',
			'#footer a',
			'#footer .widget-title',
			'#footer-widget-area',
			'#footer-widget-area a',
			'#footer-widget-area h1', '#footer-widget-area h2', '#footer-widget-area h3', '#footer-widget-area h4', '#footer-widget-area h5', '#footer-widget-area h6'
		),
		'color_footer_menu_text' => array(
			'#menu-footer a',
			'#footer a',
			'#footer-widget-area a'
		),
		'color_footer_menu_text_hover' => array(
			'#menu-footer a:hover',
			'#footer a:hover',
			'#footer-widget-area a:hover'
		),
		'color_copyright' => array(
			'#theme-copyright',
			'.powered'
		),

		'color_social_icons_text' => array(
			'.sociables a'
		),

		'color_social_icons_text_hover' => array(
			'.sociables a:hover'
		),

		// Content
		'color_paragraphs'            => array('#wrapper .grid'),
		'color_links'                 => array('a'),
		'color_links_hover'           => array('a:hover', '.menu a:hover', '#footer-widget-area a:hover', '#footer a:hover'),
		'color_button_text'           => array('.button', 'a.button'),
		'color_button_text_hover'     => array('.button:hover', 'a.button:hover'),
		'color_sidebar_header_text'   => array('.sidebar .widget-title'),
		'color_search_field'		  => array('.searchform .field'),

	);

	// Background colors
	$colors_background = array(

		// Menu
		'color_menu_background' => array('#site-navigation', '.sb-holder', '.social_icons .icons', '#theme-search-box'),
		'color_submenu_background' => array('#theme-menu-main li li', '#theme-menu-main li li a'),
		'color_submenu_background_hover' => array('#theme-menu-main li:hover li:hover a:hover'),

		// Footer
		'color_footer_menu_background' => array(
			//'#menu-footer',
		),
		'color_footer_background' => array(
			'#footer-widget',
			'#footer-background'
		),

		// Content
		'color_content_background' => array('#wrapper', '#theme_slider_area'),
		'color_button' => array(
			'.button',
			'a.button'
		),
		'color_button_hover' => array(
			'.button:hover',
			'a.button:hover'
		),
		'color_sidebar_header_background' => array('.sidebar .widget-title'),

		'color_custom_content'		  => array('#theme-custom-content')

	);

	// Border colors
	$colors_border = array(
		// Menu
		'color_submenu_background' => array(
			'#theme-menu-main li li',
			'#theme-menu-main li li a'
		),
		'color_menu_text_hover' => array(
			'#theme-menu-main > li > a:hover span',
			'#theme-menu-main > li:hover > a span',
			'#theme-menu-main > li.current-menu-item > a span',
			'#theme-menu-main > li.current-page-item > a span'
		),

		// Links
		'color_links' => array(
			'a > img',
			'a .thumbs',
		),
		'color_links_hover' => array(
			'a > img:hover',
			'.thumbs:hover',
			'img:hover',
			'area:focus',
			'input:focus',
			'textarea:focus'
		),
	);

	// Outline colors
	$colors_outline = array(
		'color_links_hover' => array(
			'ul.shortcode-gallery > li:hover',
		),
	);

	// Path to all theme images
	$imagepath = THEME_URI . '/images/';

	// Get background image
	// Post type > category > theme
	$backgroundimage = null;

	if ( is_singular() && (is_page() || is_single()) )
		$backgroundimage = core_options_get('background_image', get_post_type());
	else
		$backgroundimage = core_options_get('layout-default_background', 'theme');

	if (is_archive()){
		if (is_category() && !$backgroundimage) {
			$obj = get_queried_object();
			$backgroundimage = core_options_get('category_background_' .$obj->slug);
		} elseif (is_author())
			$backgroundimage = core_options_get('layout-author_background', 'theme');
		elseif (is_tag())
			$backgroundimage = core_options_get('layout-tag_background', 'theme');
		else
			$backgroundimage = core_options_get('layout-archive_background', 'theme');
	}

	if (is_404())
		$backgroundimage = core_options_get('layout-404_background', 'theme');

	if (is_search())
		$backgroundimage = core_options_get('layout-search_background', 'theme');

	$backgroundimage = apply_filters('layout_background', $backgroundimage);

	if (!$backgroundimage || $backgroundimage == 'none')
		$backgroundimage = core_options_get('background_image');

	// Other options
	$pattern = core_options_get('pattern');

	// Slogan Background
	function slogan_block_background(){
		$post_type          = get_post_type();
		$category           = get_query_var('cat');
		$current_category   = get_category ($category);

			// check if it's a page or post with a custom content block background
			if ( is_singular() && (is_page() || is_single()) )
				$slogan_bg = core_options_get('custom_content_image', $post_type);

			if (is_archive()){

				// check if it's a category and display the custom content if there are any
				if ( is_category() ){
					$obj = get_queried_object();
					$slogan_bg = core_options_get('custom_content_' .$obj->slug.'_bg');

				} elseif (is_author())
					$slogan_bg = core_options_get('custom_content_layout-author_bg', 'theme');

				elseif (is_tag())
					$slogan_bg = core_options_get('custom_content_layout-tag_bg', 'theme');

				else
					$slogan_bg = core_options_get('custom_content_layout-archive_bg', 'theme');
			}

			if (is_search())
				$slogan_bg = core_options_get('custom_content_layout-search_bg', 'theme');

		$slogan_bg = apply_filters('slogan_background', $slogan_bg);

		if ( !$slogan_bg || $slogan_bg == 'none' )
			$slogan_bg = core_options_get('custom_content_layout-default_bg', 'theme');

		$slogan_bg = "#theme-custom-content .bg{ background-image: url(".$slogan_bg."); background-position: top center; background-repeat: repeat; } ";

		return $slogan_bg;
	}


?>

<style type="text/css">
	<?php
		// Content colors
		$color = core_hex2rgb(core_options_get('color_content_background'));
		$color['alpha'] = 1.0;
		//echo '#wrapper .theme-wrap,';
		echo 'div.shortcode-header h1,';
		echo 'div.shortcode-header h2,';
		echo 'div.shortcode-header h3,';
		echo 'div.shortcode-header h4,';
		echo 'div.shortcode-header h5,';
		echo 'div.shortcode-header h6';
		echo '{ background-color:'.core_options_get('color_content_background').'; background-color: ', core_color2rgba($color), ';';
		$color['alpha'] = 0.7;
		echo ' outline-color: ', core_color2rgba($color), ';}';

		// Typography
		apply_fonts($fonts);
		apply_font_sizes($fontsizes);

		// Other color settings
		apply_colors('color', $colors);
		apply_colors('background-color', $colors_background);
		apply_colors('border-color', $colors_border);
		apply_colors('outline-color', $colors_outline);

		// Core custom CSS
		do_action('core_custom_css');

		echo 'body {';
		$new_base_font = intval(core_options_get('font_size_other_paragraph')) / BASE_FONT_SIZE;
		echo 'background-color: ' . core_options_get('main_background_color') . ';';
		echo 'background-image: url(' . $backgroundimage . ');';
		echo 'background-position: top center;';
		$bg_repeat = (core_options_get('background_repeat') == true) ? 'background-repeat: repeat;' : 'background-repeat: no-repeat;';
		echo $bg_repeat;
		$bg_size = (core_options_get('background_size') == false) ? 'background-size: cover;' : 'background-size: 100%;';
		echo $bg_size;
		echo '} ';

		echo 'h1 { ' . ( ( intval( core_options_get( 'font_size_heading1' ) ) / BASE_FONT_SIZE ) + $new_base_font ) .'em; } ';
		echo 'h2 { ' . ( ( intval( core_options_get( 'font_size_heading2' ) ) / BASE_FONT_SIZE ) + $new_base_font ) .'em; } ';
		echo 'h3 { ' . ( ( intval( core_options_get( 'font_size_heading3' ) ) / BASE_FONT_SIZE ) + $new_base_font ) .'em; } ';
		echo 'h4 { ' . ( ( intval( core_options_get( 'font_size_heading4' ) ) / BASE_FONT_SIZE ) + $new_base_font ) .'em; } ';
		echo 'h5 { ' . ( ( intval( core_options_get( 'font_size_heading5' ) ) / BASE_FONT_SIZE ) + $new_base_font ) .'em; } ';
		echo 'h6 { ' . ( ( intval( core_options_get( 'font_size_heading6' ) ) / BASE_FONT_SIZE ) + $new_base_font ) .'em; } ';

		if($pattern != 'none') {
			echo '#site-navigation, #theme-custom-content, #footer-widget, #footer-background, .sidebar { background-image: url(' . $imagepath . 'patterns/' . $pattern . '); } ';
		} else {
			echo '#header, #site-navigation, #footer { background-image: none; } ';
		}

		// Output the custom content background
		$slogan_block_background = slogan_block_background();
		if( $slogan_block_background  ) {
			echo $slogan_block_background;
		}

		// Menu color
		$color = core_hex2rgb(core_options_get('color_submenu_background'));
		$color['alpha'] = 0.95;
		echo '#theme-menu-main li li, #theme-menu-main li li a { background-color: transparent; } ';
		echo '#theme-menu-main li ul { background-color: '.core_options_get('color_submenu_background').'; background-color: ', core_color2rgba($color), '; } ';
	?>
	<?php core_theme_hook_styles(); ?>

</style>

