<?php
/**
 * Output theme settings custom CSS into your header
 * @package Ultra WordPress Theme
 * @since 1.0
 * @author AJ Clarke : http://wpexplorer.com
 * @copyright Copyright (c) 2012, AJ Clarke
 * @link http://wpexplorer.com
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 */


if ( !function_exists( 'wpex_custom_css' ) ) {
	
	add_action('wp_head', 'wpex_custom_css'); // Hook function to wp_head
	
	function wpex_custom_css() {
	
		$custom_css ='';
		
		// Custom BG Color
		$custom_bg_color = of_get_option('custom_bg_color','');
		if ( $custom_bg_color !== '' ) {
			$custom_css .= 'body{background-color: '. $custom_bg_color .' !important;}';	
		}
		
		// Predefined Colors
		$predefined_bg_color = of_get_option('predefined_bg_color','none');
		if ( $predefined_bg_color !== 'none' ) {
			$custom_css .= 'body{background-color: '. $predefined_bg_color .' !important;}';	
		}
		
		// Predefined Bgs
		$predefined_bg_img = of_get_option('predefined_bg_img','none');
		if ( $predefined_bg_img !== 'none' ) {
			// Default
			$custom_css .= 'body{background-image: url( '. get_template_directory_uri().'/images/bgs/'. $predefined_bg_img .'.png);background-image: repeat;}';
			// Retina
			$custom_css .= '@media only screen and (-webkit-min-device-pixel-ratio: 2){body{background-image: url( '. get_template_directory_uri().'/images/bgs/'. $predefined_bg_img .'_@2X.png);background-image: repeat;}}';
		}
		
		// Custom Skin / Gradient
		$skin_top_color = of_get_option('skin_top_color','');
		$skin_bottom_color = of_get_option('skin_bottom_color','');
		
			// Gradients
			if ( $skin_top_color && $skin_bottom_color ) {
				$custom_css .= ".services-entry-font-icon,
								ul.portfolio-filter a.active,
								ul.portfolio-filter a.active:hover,
								ul.services-filter a.active,
								ul.services-filter a.active:hover,
								ul.faq-filter a.active,
								ul.faq-filter a.active:hover,
								ul.staff-filter a.active,
								ul.staff-filter a.active:hover,
								.symple-testimonials .flex-control-paging a:hover,
								.symple-testimonials .flex-control-paging a.flex-active,
								.page-numbers.current,
								.page-numbers.current:hover,
								#sidebar .widget_nav_menu .current-menu-item a,
								.wpex-widget-testimonials .flex-control-paging a:hover,
								.wpex-widget-testimonials .flex-control-paging a.flex-active,
								#footer .wpex-widget-testimonials .flex-control-paging a:hover,
								#footer .wpex-widget-testimonials .flex-control-paging a.flex-active,
								.bx-wrapper .bx-pager.bx-default-pager a:hover,
								.bx-wrapper .bx-pager.bx-default-pager a.active,
								.symple-toggle .symple-toggle-trigger.active,
								.symple-toggle .symple-toggle-trigger.active:hover,
								.symple-accordion .symple-accordion-trigger.ui-state-active,
								.symple-accordion .symple-accordion-trigger.ui-state-active:hover,
								.symple-tabs ul.ui-tabs-nav .ui-state-active a:hover,
								.symple-tabs ul.ui-tabs-nav .ui-state-active a,
								.symple-pricing-table .featured .symple-pricing-header,
								.portfolio-entry-overlay-inner .overlay-icon:hover {
									background: -moz-linear-gradient(top,  ". $skin_top_color ." 0%, ". $skin_bottom_color ." 100%);
									background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,". $skin_top_color ."), color-stop(100%,". $skin_bottom_color ."));
									background: -webkit-linear-gradient(top,  ". $skin_top_color ." 0%,". $skin_bottom_color ." 100%);
									background: -o-linear-gradient(top,  ". $skin_top_color ." 0%,". $skin_bottom_color ." 100%);
									background: -ms-linear-gradient(top,  ". $skin_top_color ." 0%,". $skin_bottom_color ." 100%);
									background: linear-gradient(to bottom,  ". $skin_top_color ." 0%,". $skin_bottom_color ." 100%);
									filter: progid:DXImageTransform.Microsoft.gradient( startColorstr=". $skin_top_color .", endColorstr='". $skin_bottom_color ."',GradientType=0 ); }
								.wpex-widget-slider .flex-direction-nav li a:hover,
								.flex-direction-nav li a:hover{
									background: ". $skin_top_color .";
								} ";
			}
			
		if ( $skin_top_color &&  $skin_bottom_color == '' ) {
			$custom_css .= '.services-entry-font-icon,
								ul.portfolio-filter a.active,
								ul.portfolio-filter a.active:hover,
								ul.services-filter a.active,
								ul.services-filter a.active:hover,
								ul.faq-filter a.active,
								ul.faq-filter a.active:hover,
								ul.staff-filter a.active,
								ul.staff-filter a.active:hover,
								.symple-testimonials .flex-control-paging a:hover,
								.symple-testimonials .flex-control-paging a.flex-active,
								.page-numbers.current,
								.page-numbers.current:hover,
								#sidebar .widget_nav_menu .current-menu-item a,
								.wpex-widget-testimonials .flex-control-paging a:hover,
								.wpex-widget-testimonials .flex-control-paging a.flex-active,
								#footer .wpex-widget-testimonials .flex-control-paging a:hover,
								#footer .wpex-widget-testimonials .flex-control-paging a.flex-active,
								.bx-wrapper .bx-pager.bx-default-pager a:hover,
								.bx-wrapper .bx-pager.bx-default-pager a.active,
								.symple-toggle .symple-toggle-trigger.active,
								.symple-toggle .symple-toggle-trigger.active:hover,
								.symple-accordion .symple-accordion-trigger.ui-state-active,
								.symple-accordion .symple-accordion-trigger.ui-state-active:hover,
								.symple-tabs ul.ui-tabs-nav .ui-state-active a:hover,
								.symple-tabs ul.ui-tabs-nav .ui-state-active a,
								.symple-pricing-table .featured .symple-pricing-header,
								.portfolio-entry-overlay-inner .overlay-icon:hover,
								.wpex-widget-slider .flex-direction-nav li a:hover,
								.flex-direction-nav li a:hover {
									background: '. $skin_top_color .';
							}';
		}
		
		// Top Bar Callout Button
		$callout_button_top_color = of_get_option('callout_button_top_color','');
		$callout_button_bottom_color = of_get_option('callout_button_bottom_color','');
		
		if ( $callout_button_top_color && $callout_button_bottom_color ) {
			$custom_css .= "#top-bar-nav a,
							#top-bar-nav a:active {
								color: #fff;
								text-shadow: 1px -1px 1px rgba(0,0,0,0.15);
								background: -moz-linear-gradient(top,  ". $callout_button_top_color ." 0%, ". $callout_button_bottom_color ." 100%);
								background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,". $callout_button_top_color ."), color-stop(100%,". $callout_button_bottom_color ."));
								background: -webkit-linear-gradient(top,  ". $callout_button_top_color ." 0%,". $callout_button_bottom_color ." 100%);
								background: -o-linear-gradient(top,  ". $callout_button_top_color ." 0%,". $callout_button_bottom_color ." 100%);
								background: -ms-linear-gradient(top,  ". $callout_button_top_color ." 0%,". $callout_button_bottom_color ." 100%);
								background: linear-gradient(to bottom,  ". $callout_button_top_color ." 0%,". $callout_button_bottom_color ." 100%);
								filter: progid:DXImageTransform.Microsoft.gradient( startColorstr=". $callout_button_top_color .", endColorstr='". $callout_button_bottom_color ."',GradientType=0 );
							}
							#top-bar-nav a:active {
								box-shadow: none;
							}";
		}
		
		
		// Callout Text Color
		$callout_button_txt_color = of_get_option('callout_button_txt_color','');
		if ( $callout_button_txt_color ) {
			$custom_css .= '#top-bar-nav a,
							 #top-bar-nav a:active {
								color: '. $callout_button_txt_color .';
							}';
		}
				
		
		// Header Top Margin
		$header_top_margin = of_get_option('header_top_margin','45');
		if( $header_top_margin !== '45' && $header_top_margin != '' ) {
			$custom_css .= '#header{margin-top: '. $header_top_margin .'px;}';		
		}
		
		// Header Bottom Margin
		$header_bottom_margin = of_get_option('header_bottom_margin','45');
		if( $header_bottom_margin !== '45' && $header_bottom_margin != '' ) {
			$custom_css .= '#header{margin-bottom: '. $header_bottom_margin .'px;}';			
		}
	
		// trim white space for faster page loading
		$custom_css_trimmed =  preg_replace( '/\s+/', ' ', $custom_css );
		
		// output css on front end
		$css_output = "<!-- Custom CSS -->\n<style type=\"text/css\">\n" . $custom_css_trimmed . "\n</style>";
		if( !empty($custom_css) ) { echo $css_output;}
		
	} //end wpex_custom_css()
	
}