<?php
class SH_Enqueue
{
	
	function __construct()
	{
		add_action( 'wp_enqueue_scripts', array( $this, 'sh_enqueue_scripts' ) );
		add_action( 'wp_head', array( $this, 'wp_head' ) );
		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
	}


	function sh_enqueue_scripts()
	{
		global $post;
		$options = _WSH()->option();
		$color = sh_set($options, 'custom_color_scheme', '#fb724e');
		$color = str_replace('#', '', $color);

		$protocol = is_ssl() ? 'https' : 'http';
		$styles = array( 
						 //'google_fonts'  => $protocol.'://fonts.googleapis.com/css?family=Open+Sans:400,300,700|Montserrat:400,700',
						 'bootstrap'	 => 'css/bootstrap.css',
						 'font-awesome'  => 'css/font-awesome.min.css',
						 'magnific-popup' 	 => 'css/magnific-popup.css',
						 'owl-carousel'		=> 'css/owl.carousel.css',
						 'custom-animate'	=> 'css/animate.css',
						 'main_style'	=> get_stylesheet_directory_uri().'/style.css',
						 'color_scheme' => 'css/color.php?color='.$color ,

					   );
	
		foreach( $styles as $name => $style )
		{

			if(strstr($style, 'http') || strstr($style, 'https') ) 
			{
				wp_enqueue_style( $name, $style);
			}

			else wp_enqueue_style( $name, SH_URL.$style);
		}

		$scripts = array( 
						  	'custom-plugins'	=> 'js/plugins.js',
						  	'fullscreen_popup'  => 'js/jquery.fullscreen-popup.min.js',
						    'custom-scripts'	=> 'js/custom.js'
						 );
						 
		foreach( $scripts as $name => $js )
		{
			wp_register_script( $name, SH_URL.$js, '', '', true);
		}
		
		wp_enqueue_script( array( 'jquery', 'custom-plugins', 'fullscreen_popup', 'custom-scripts'));

		if( is_singular() ) wp_enqueue_script('comment-reply');

	}
	
	function wp_head()
	{
		$options = _WSH()->option();

		echo '<script type="text/javascript"> if( ajaxurl === undefined ) var ajaxurl = "'.admin_url('admin-ajax.php').'";</script>';?>
		<style type="text/css">
		<?php
			
			if( sh_set( $options, 'body_custom_font' ) )
			echo sh_get_font_settings( array( 'body_font_family' => 'font-family', 'body_font_color' => 'color' ), 'body, p { ', ' }' );
			
			if( sh_set( $options, 'use_custom_font' ) ) {
				
				echo sh_get_font_settings( array( 'h1_font_family' => 'font-family', 'h1_font_color' => 'color' ), 'h1 { ', ' }' );
				echo sh_get_font_settings( array( 'h2_font_family' => 'font-family', 'h2_font_color' => 'color'  ), 'h2 { ', ' }' );
				echo sh_get_font_settings( array( 'h3_font_family' => 'font-family', 'h3_font_color' => 'color'  ), 'h3 { ', ' }' );
				echo sh_get_font_settings( array( 'h4_font_family' => 'font-family', 'h4_font_color' => 'color'  ), 'h4 { ', ' }' );
				echo sh_get_font_settings( array( 'h5_font_family' => 'font-family', 'h5_font_color' => 'color'  ), 'h5 { ', ' }' );
				echo sh_get_font_settings( array( 'h6_font_family' => 'font-family', 'h6_font_color' => 'color'  ), 'h6 { ', ' }' );
			}
		?>
			<?php if( $banner_image = sh_set( $options, 'subpages_banner' ) ): ?>
				.info-section-parallax-path {
					background: url("<?php echo esc_url($banner_image); ?>") repeat fixed center top rgba(0, 0, 0, 0);
				}
			<?php endif; ?>
		</style>
		<?php 

		$custom_css = sh_set($options , 'custom_css');
		
	}
	
	function wp_footer()

	{

		$theme_options = _WSH()->option();
		
		if( sh_set( $theme_options, 'footer_analytics' ) ): ?>
			<script type="text/javascript">
                <?php echo sh_set( $theme_options, 'footer_analytics' );?>
            </script>
        <?php endif;

	}

}