<?php 

/*-----------------------------------------------------------------------------------

TABLE OF CONTENTS

- Add custom styling to HEAD
- Add custom typograhpy to HEAD

-----------------------------------------------------------------------------------*/

add_action( 'woo_head','woo_custom_typography' );			// Add custom typography to HEAD
add_action( 'woo_head','woo_custom_styling' );			// Add custom styling to HEAD

/*-----------------------------------------------------------------------------------*/
/* Add Custom Styling to HEAD */
/*-----------------------------------------------------------------------------------*/
if (!function_exists( 'woo_custom_styling')) {
	function woo_custom_styling() {
	
		global $woo_options;
		               
		$output = '';
		// Get options
		$body_color = $woo_options[ 'woo_body_color' ];
		$body_img = $woo_options[ 'woo_body_img' ];
		$body_repeat = $woo_options[ 'woo_body_repeat' ];
		$body_position = $woo_options[ 'woo_body_pos' ];
                $text = $woo_options[ 'woo_text_color' ];
		$link = $woo_options[ 'woo_link_color' ];
		$hover = $woo_options[ 'woo_link_hover_color' ];
		$button = $woo_options[ 'woo_button_color' ];
                $top_menu_back = $woo_options[ 'woo_top_menu_back_color' ];
                $top_submenu_back = $woo_options[ 'woo_top_submenu_back_color' ];
                $top_menu_hover = $woo_options[ 'woo_top_menu_hover_color' ];
                $top_menu_active = $woo_options[ 'woo_top_menu_active_color' ];
		
		// Add CSS to output
		if ($body_color)
                        $output .= 'body {background:'.$body_color.';}' . "\n";
		
                if ($text) {
                        $output .= 'body {color:'.$text.';}' . "\n";
                }
                
		if ($body_img)
			$output .= 'body {background-image:url( '.$body_img.')}' . "\n";

		if ($body_img && $body_repeat && $body_position)
			$output .= 'body {background-repeat:'.$body_repeat.'}' . "\n";

		if ($body_img && $body_position)
			$output .= 'body {background-position:'.$body_position.'}' . "\n";

		if ($link) {
			$output .= 'a:link, a:visited, #about a.more:link, #about a.more:visited, #footer ul li a:link, #footer ul li a:visited { color:'.$link.'}' . "\n";
                }

		if ($hover) {
			$output .= 'a:hover, .post-more a:hover, .post-meta a:hover, .post p.tags a:hover, .post .title a:hover, .post-meta a:hover, #comments .avatar .name a:hover {color:'.$hover.';}' . "\n";
                        $output .= '#slide-navigator {background-color: '.$hover.';}' . "\n";                        
                }

		if ($button) {
			$output .= 'a.button, a.comment-reply-link, #commentform #submit, #contact-page .submit {background:'.$button.';border-color:'.$button.'}' . "\n";
			$output .= 'a.button:hover, a.button.hover, a.button.active, a.comment-reply-link:hover, #commentform #submit:hover, #contact-page .submit:hover {background:'.$button.';opacity:0.9;}' . "\n";
		}
                
                if ($link && $hover) {
                        $output .= '.widget_woo_archives li a { background:'.$link.'; color:'.$hover.';}' . "\n";
                        $output .= '.widget_woo_archives li a:hover { background:'.$hover.'; color:'.$link.';}' . "\n";
                        $output .= '#navigation .nav li a:hover { color:'.$link.';}' . "\n";
                        $output .= '.nav a:hover, 
                                    .nav li.current_page_item a, 
                                    .nav li.current_page_parent a, 
                                    .nav li.current-menu-ancestor a, 
                                    .nav li.current-cat a, 
                                    .nav li.current-menu-item a { color: '.$link.'; background: '.$hover.';}' . "\n";
                }
                
                
                if ($top_menu_back) {
                        $output .= '#pagenav { background:'.$top_menu_back.';}' . "\n";                        
                }

                if ($top_submenu_back) {
                    $output .= '#pagenav li ul li { background:'.$top_submenu_back.';}' . "\n";
                    $output .= '.entry img {background:'.$top_submenu_back.';}' . "\n";
                }

                
                if ($top_menu_hover) {
                    $output .= '#pagenav li a:hover, #pagenav li.current_page_item a, ';
                    $output .= '#pagenav li.hover, #pagenav li:hover { background: '.$top_menu_hover.';}' . "\n";                    
                    $output .= '#pagenav li ul li a:hover  { background: '.$top_menu_hover.'; }' . "\n";                
                }

                if ($top_menu_active) {
                        $output .= '#pagenav li.current_page_item a { background:'.$top_menu_active.'; }' . "\n";                
                        
                }
                
                if ($top_menu_back && $top_menu_active) {
                        /*$output .= '#header { border: 1px solid '.$top_menu_active.'; border-bottom: 3px solid '.$top_menu_back.'; border-top: none;}' . "\n";                    
                        $output .= '#content, .home #content, .home #donate { border: 1px solid '.$top_menu_active.'; border-bottom: 3px solid '.$top_menu_back.';}' . "\n";                                            
                        
                        $output .= '.post .post-date {  background-color:'.$top_menu_back.'; border-color:'.$top_menu_active.';}' . "\n";
                        $output .= '#navigation-top .nav li a:hover, .top-search a:hover { background-color:'.$top_menu_active.'; color: '.$top_menu_back.'.}' . "\n";                        */
                }
                
		// Adjust slider title size, if content is enabled.
		if ( $woo_options[ 'woo_slider_content' ] == "true" )
			$output .= '#slides.slides .slide-content .slide-title { font-size: 50px; line-height: 1.2em; margin-top:10px; }'  . "\n";	
		               
                
                // Output styles
		if (isset($output) && $output != '') {
			$output = strip_tags($output);
			$output = "<!-- Woo Custom Styling -->\n<style type=\"text/css\">\n" . $output . "</style>\n";
			echo $output;
		}
			
	}
} 

/*-----------------------------------------------------------------------------------*/
/* Add custom typograhpy to HEAD */
/*-----------------------------------------------------------------------------------*/
if (!function_exists( 'woo_custom_typography')) {
	function woo_custom_typography() {
	
		// Get options
		global $woo_options;
				
		// Reset	
		$output = '';
		
		if ( $woo_options[ 'woo_typography' ] == "true") {
			
			if ( $woo_options[ 'woo_font_body' ] ) {
				$output .= 'body { '.woo_generate_font_css($woo_options[ 'woo_font_body' ], '1.4').' }' . "\n";	
                        }
                        
			if ( $woo_options[ 'woo_font_title' ] ) {
                                $output .= 'h1, h2, h3, h4, h5, h6 { '.
                                           'font-family:"'.stripslashes($woo_options[ 'woo_font_title' ]["face"]).'", serif; '.
                                           'color: '.stripslashes($woo_options[ 'woo_font_title' ]["color"]).';'.
                                           ' }' . "\n";                        
                        }
                            
                        if ( $woo_options[ 'woo_font_nav' ] ) {
				$output .= '#navigation, #navigation .nav a { '.woo_generate_font_css($woo_options[ 'woo_font_nav' ], '1.4').' }' . "\n";	
                        }
                        
			if ( $woo_options[ 'woo_font_post_title' ] ) {
				$output .= '.post .title { '.woo_generate_font_css($woo_options[ 'woo_font_post_title' ]).' }' . "\n";	
                        }

                        if ( $woo_options[ 'woo_font_post_meta' ] ) {
				$output .= '.post-meta { '.woo_generate_font_css($woo_options[ 'woo_font_post_meta' ]).' }' . "\n";	
                        }
			
                        if ( $woo_options[ 'woo_font_post_entry' ] ) {
				$output .= '.entry, .entry p { '.woo_generate_font_css($woo_options[ 'woo_font_post_entry' ], '1.5').' }'  . "\n";	
                        }
                        
			if ( $woo_options[ 'woo_font_widget_titles' ] ) {
				$output .= '.widget h3 { '.woo_generate_font_css($woo_options[ 'woo_font_widget_titles' ]).' }'  . "\n";	
                        }
                }       
		
		// Output styles
		if (isset($output) && $output != '') {
		
			// Enable Google Fonts stylesheet in HEAD
			if (function_exists( 'woo_google_webfonts')) woo_google_webfonts();
			
			$output = "\n<!-- Woo Custom Typography -->\n<style type=\"text/css\">\n" . $output . "</style>\n";
                        echo $output;
			
		}
			
	}
} 

if (!function_exists('woo_generate_font_css')) {
	// Returns proper font css output
	function woo_generate_font_css($option, $em = '1') {
	
		if (!$option["style"] && !$option["size"] && !$option["unit"] && !$option["color"])
			return 'font-family:"'.stripslashes($option["face"]).'", serif;'; 
		else
			return 'font:'.$option["style"].' '.$option["size"].$option["unit"].'/'.$em.'em '.stripslashes($option["face"]).';color:'.$option["color"].';';
			
	}
}

// Output stylesheet and custom.css after custom styling
remove_action( 'wp_head', 'woothemes_wp_head' );
add_action( 'woo_head', 'woothemes_wp_head' );



/*-----------------------------------------------------------------------------------*/
/* END */
/*-----------------------------------------------------------------------------------*/
?>